epitools 0.5.29 → 0.5.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bd295ef4f56858d08b947caa73cdbc3e9bed57b
4
- data.tar.gz: 335ab48442074262d802aada39a9fc51a53cd351
3
+ metadata.gz: 120222690b258526c2d00054435a3050d44f9a38
4
+ data.tar.gz: 67eae80482d685d793b149a6cbd9e29bb6a9b2d1
5
5
  SHA512:
6
- metadata.gz: 58ebc78bf95e4bf09b8ab5e482e5c97edf4f5da6402994aca2147f8f27996a531dbb03ba848d438dfa87afe029189aaa1e503b838f9206415265a00166e127f8
7
- data.tar.gz: afec7cf64783fd9073a6074af82049a5b2add2f0e2355f5e17a9ed809b4f01a58febbf40fd716008bb55a44cf660875af86de71d3e721cd4e2913f29c10b98d9
6
+ metadata.gz: 7be7f20a24a90202794be45347551964fa9ca3e6e28784e1baa83c23e99c69c394afa03b38c4f35b29937b30f173bdcdd008f486bf959d426a4186d13379167d
7
+ data.tar.gz: 1f4de875e2dcb0b70e47c87056462bea390dc8b20b37a4f96af0e8e03ec092df6c8d10c377ea6991ff37e5354592ebf307f1b6f2ac1815b936ed095c57f4a226
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.29
1
+ 0.5.30
@@ -68,7 +68,9 @@ class Path
68
68
  attr_reader :ext
69
69
 
70
70
 
71
- ## initializers
71
+ ###############################################################################
72
+ # Initializers
73
+ ###############################################################################
72
74
 
73
75
  def initialize(newpath, hints={})
74
76
  self.send("path=", newpath, hints)
@@ -110,7 +112,9 @@ class Path
110
112
  end
111
113
  end
112
114
 
113
- ## setters
115
+ ###############################################################################
116
+ # Setters
117
+ ###############################################################################
114
118
 
115
119
  attr_writer :base
116
120
  attr_writer :dirs
@@ -279,7 +283,9 @@ class Path
279
283
  extensions
280
284
  end
281
285
 
282
- ## fstat info
286
+ ###############################################################################
287
+ # fstat
288
+ ###############################################################################
283
289
 
284
290
  def exists?
285
291
  File.exists? path
@@ -365,7 +371,9 @@ class Path
365
371
  dirs == child.dirs[0...dirs.size]
366
372
  end
367
373
 
368
- ## comparisons
374
+ ###############################################################################
375
+ # Comparisons
376
+ ###############################################################################
369
377
 
370
378
  include Comparable
371
379
 
@@ -385,7 +393,9 @@ class Path
385
393
  end
386
394
 
387
395
 
388
- ## appending
396
+ ###############################################################################
397
+ # Joining paths
398
+ ###############################################################################
389
399
 
390
400
  #
391
401
  # Path["/etc"].join("anything{}").path == "/etc/anything{}"
@@ -406,7 +416,86 @@ class Path
406
416
  Path[ File.join(self, other) ]
407
417
  end
408
418
 
409
- ## opening/reading files
419
+ ###############################################################################
420
+ # Xattrs
421
+ ###############################################################################
422
+
423
+ #
424
+ # Read xattrs from file (requires "getfattr" to be in the path)
425
+ #
426
+ def self.getfattr(path)
427
+ # # file: Scissor_Sisters_-_Invisible_Light.flv
428
+ # user.m.options="-c"
429
+
430
+ cmd = ["getfattr", "-d", "-e", "hex", path]
431
+
432
+ attrs = {}
433
+
434
+ IO.popen(cmd, "rb", :err=>[:child, :out]) do |io|
435
+ io.each_line do |line|
436
+ if line =~ /^([^=]+)=0x(.+)/
437
+ key = $1
438
+ value = [$2].pack("H*") # unpack hex string
439
+
440
+ attrs[key] = value
441
+ end
442
+ end
443
+ end
444
+
445
+ attrs
446
+ end
447
+
448
+ #
449
+ # Set xattrs on a file (requires "setfattr" to be in the path)
450
+ #
451
+ def self.setfattr(path, key, value)
452
+ cmd = %w[setfattr]
453
+
454
+ if value == nil
455
+ # delete
456
+ cmd += ["-x", key]
457
+ else
458
+ # set
459
+ cmd += ["-n", key, "-v", value]
460
+ end
461
+
462
+ cmd << path
463
+
464
+ IO.popen(cmd, "rb", :err=>[:child, :out]) do |io|
465
+ result = io.each_line.to_a
466
+ error = {cmd: cmd, result: result.to_s}.inspect
467
+ raise error if result.any?
468
+ end
469
+ end
470
+
471
+ #
472
+ # Return a hash of all of this file's xattrs.
473
+ # (Metadata key=>valuse pairs, supported by most modern filesystems.)
474
+ #
475
+ def attrs
476
+ @attrs ||= Path.getfattr(path)
477
+ end
478
+ alias_method :xattrs, :attrs
479
+
480
+ #
481
+ # Retrieve one of this file's xattrs
482
+ #
483
+ def [](key)
484
+ attrs[key]
485
+ end
486
+
487
+ #
488
+ # Set this file's xattr
489
+ #
490
+ def []=(key, value)
491
+ Path.setfattr(path, key, value)
492
+ @attrs = nil
493
+ end
494
+
495
+
496
+ ###############################################################################
497
+ # Opening/Reading files
498
+ ###############################################################################
410
499
 
411
500
  def open(mode="rb", &block)
412
501
  if block_given?
@@ -456,7 +545,10 @@ class Path
456
545
  self
457
546
  end
458
547
 
459
- ## modifying files
548
+
549
+ ###############################################################################
550
+ # Modifying files
551
+ ###############################################################################
460
552
 
461
553
  #
462
554
  # Append data to this file (accepts a string, an IO, or it can yield the file handle to a block.)
@@ -494,6 +586,10 @@ class Path
494
586
  end
495
587
  end
496
588
 
589
+ ###############################################################################
590
+ # Parsing files
591
+ ###############################################################################
592
+
497
593
  #
498
594
  # Parse the file based on the file extension.
499
595
  # (Handles json, html, yaml, xml, bson, and marshal.)
@@ -324,7 +324,12 @@ describe Path do
324
324
  Path.which("ruby").should_not be_nil
325
325
  Path.which("asdfasdfhkajlsdhfkljashdf").should be_nil
326
326
  Path.which("ruby").class.should == Path
327
- Path.which("ps", "sh", "tar").map(&:path).should == ["/bin/ps", "/bin/sh", "/usr/bin/tar"]
327
+
328
+ testprogs = ["ps", "sh", "tar"]
329
+
330
+ real_result = `which #{testprogs.join(" ")}`.each_line.map(&:strip)
331
+
332
+ Path.which(*testprogs).map(&:path).should == real_result
328
333
  end
329
334
 
330
335
  it "Path[]s another path" do
@@ -455,4 +460,21 @@ describe Path do
455
460
  entries.should be_an Array
456
461
  end
457
462
 
463
+ it "xattrs" do
464
+ file = Path["~/test"]
465
+ file.touch
466
+ file["nothing"].should == nil
467
+
468
+ file["user.test"] = "whee"
469
+
470
+ file["user.test"].should == "whee"
471
+ Path.getfattr(file)["user.test"].should == "whee"
472
+
473
+ file["user.test"] = nil
474
+ file["user.test"].should == nil
475
+ Path.getfattr(file)["user.test"].should == nil
476
+
477
+ lambda { file["blahblahblah"] = "whee" }.should raise_error
478
+ end
479
+
458
480
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.29
4
+ version: 0.5.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-12 00:00:00.000000000 Z
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec