epitools 0.5.78 → 0.5.79

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: eaa41a0083f51cf6b384e54bf10722336d61579d
4
- data.tar.gz: ef5b37f73bda977f347914532488541bced2fdaa
3
+ metadata.gz: 35f295e371fac93821a798d357e66515f65d395e
4
+ data.tar.gz: 9b523f2aff407af1512c10f38021d6208d6382c3
5
5
  SHA512:
6
- metadata.gz: 5e5759784db5f200e804b1856cbe55c52c99e979fbe8a72596e0bc4beece5c560953fe5d05e4d3f73991eb40daaece31fd4f82d7d61ee432f597776eb9d6f556
7
- data.tar.gz: c47b40b6bc2263596376144f36c26f13d564cd2d3ef2269a1a0174350889ab83afba331feaeebd449a17b65074ece94ac74abaabe9ad98b7d48f629ba864e605
6
+ metadata.gz: ef520fc344b40d458b120cd9d9808cbb784c5d3afa864c266f4e881dec7a5b03b4ed5061a67a8655aed925183ac3237f8c60681bb0b88fb62b7eae9f15c17f7c
7
+ data.tar.gz: 14d957b9c92aa215296dfe3dc04ed5cb076f9ceff9991840d4f81fdc85075cc75ee7465b1b42ffbdc402937c196847addaef55fed3e31f3862ca093da1c889f6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.78
1
+ 0.5.79
@@ -51,7 +51,8 @@ class Array
51
51
  # => [ [:mins, 5], [:secs, 39] ]
52
52
  #
53
53
  def rzip(other)
54
- reverse.zip(other.reverse).reverse # That's a lotta reverses!
54
+ reverse_each.zip(other.reverse_each).reverse_each
55
+ # reverse.zip(other.reverse).reverse # That's a lotta reverses!
55
56
  end
56
57
 
57
58
  #
@@ -36,6 +36,15 @@ module Enumerable
36
36
  end
37
37
  end
38
38
 
39
+ #
40
+ # Add reverse_each to old Ruby versions
41
+ #
42
+ unless defined? reverse_each
43
+ def reverse_each
44
+ to_a.to_enum(:reverse_each)
45
+ end
46
+ end
47
+
39
48
  #
40
49
  # Split this enumerable into chunks, given some boundary condition. (Returns an array of arrays.)
41
50
  #
@@ -45,6 +45,21 @@ class Object
45
45
  obj
46
46
  end
47
47
  end
48
+
49
+
50
+ #
51
+ # Creates attr_accessors and an initialize method
52
+ # that accepts the attrs as arguments.
53
+ # (It's kinda like an inline version of Struct.new(*args))
54
+ #
55
+ def self.attrs(*names)
56
+ attr_accessor *names
57
+ define_method :initialize do |*vals|
58
+ names.zip(vals) do |name, val|
59
+ instance_variable_set("@#{name}", val)
60
+ end
61
+ end
62
+ end
48
63
 
49
64
  #
50
65
  # Return a copy of the class with modules mixed into it.
@@ -0,0 +1,38 @@
1
+ module Kernel
2
+ # This method causes the current running process to become a daemon
3
+ # All further printing is relied to the error.log
4
+ # FIXME doesn't belong into Butler::Bot, rather into botcontrol
5
+ def daemonize(chdir=nil, &on_sighup)
6
+ srand # Split rand streams between spawning and daemonized process
7
+ safe_fork and exit # Fork and exit from the parent
8
+
9
+ # Detach from the controlling terminal
10
+ raise "Can't detach from controlling terminal" unless sess_id = Process.setsid
11
+
12
+ # Prevent the possibility of acquiring a controlling terminal
13
+ trap('SIGHUP', 'IGNORE')
14
+ exit if safe_fork
15
+
16
+ # In daemon mode, a SIGHUP means termination
17
+ trap('SIGHUP', &on_sighup)
18
+
19
+ # We can't get the originally controlling terminals stdout/stdin anymore
20
+ STDIN.reopen("/dev/null")
21
+ STDOUT.reopen("/dev/null", "a")
22
+ STDERR.reopen(STDOUT)
23
+
24
+ Dir.chdir(chdir) if chdir
25
+ File.umask 0033 # FIXME ask somebody knowledgable about a sensible value
26
+
27
+ sess_id
28
+ end
29
+
30
+ # Try to fork if at all possible retrying every +delay+ sec (5s default)
31
+ # if the maximum process limit for the system has been reached
32
+ def safe_fork(delay=5)
33
+ fork
34
+ rescue Errno::EWOULDBLOCK
35
+ sleep(delay)
36
+ retry
37
+ end
38
+ end
@@ -258,6 +258,8 @@ class Path
258
258
  temp = path
259
259
  reset!
260
260
  self.path = temp
261
+ @attrs = nil
262
+
261
263
  self
262
264
  end
263
265
 
@@ -423,7 +425,12 @@ class Path
423
425
  end
424
426
 
425
427
  def symlink_target
426
- Path[dir] / File.readlink(path.gsub(/\/$/, ''))
428
+ target = File.readlink(path.gsub(/\/$/, ''))
429
+ if target.startswith("/")
430
+ Path[target]
431
+ else
432
+ Path[dir] / target
433
+ end
427
434
  end
428
435
  alias_method :readlink, :symlink_target
429
436
  alias_method :target, :symlink_target
@@ -644,7 +651,9 @@ class Path
644
651
  end
645
652
 
646
653
  def ls
647
- Dir.foreach(path).drop(2).map {|fn| Path.new(fn) }
654
+ Dir.foreach(path).
655
+ reject {|fn| fn == "." or fn == ".." }.
656
+ map {|fn| Path.new(fn) }
648
657
  end
649
658
 
650
659
  def ls_r(symlinks=false)
@@ -665,7 +674,7 @@ class Path
665
674
  end
666
675
 
667
676
  def siblings
668
- ls - [self]
677
+ Path[dir].ls - [self]
669
678
  end
670
679
 
671
680
  def touch
@@ -947,7 +956,11 @@ class Path
947
956
  end
948
957
 
949
958
  def ln_s(dest)
950
- Path.ln_s(self, dest)
959
+ if dest.startswith("/")
960
+ Path.ln_s(self, dest)
961
+ else
962
+ Path.ln_s(self, self / dest )
963
+ end
951
964
  end
952
965
 
953
966
  ## Owners and permissions
@@ -1021,16 +1034,19 @@ class Path
1021
1034
  #
1022
1035
  # gzip the file, returning the result as a string
1023
1036
  #
1024
- def gzip(level=nil)
1037
+ def deflate(level=nil)
1025
1038
  Zlib.deflate(read, level)
1026
1039
  end
1040
+ alias_method :gzip, :deflate
1041
+
1027
1042
 
1028
1043
  #
1029
1044
  # gunzip the file, returning the result as a string
1030
1045
  #
1031
- def gunzip(level=nil)
1032
- Zlib.inflate(read, level)
1046
+ def inflate
1047
+ Zlib.inflate(read)
1033
1048
  end
1049
+ alias_method :gunzip, :inflate
1034
1050
 
1035
1051
  #
1036
1052
  # Quickly gzip a file, creating a new .gz file, without removing the original,
@@ -1086,6 +1102,9 @@ class Path
1086
1102
  end
1087
1103
  end
1088
1104
 
1105
+ def startswith(s); path.startswith(s); end
1106
+ def endswith(s); path.endswith(s); end
1107
+
1089
1108
  #
1090
1109
  # Follows all symlinks to give the true location of a path.
1091
1110
  #
@@ -1242,6 +1261,15 @@ class Path
1242
1261
  alias_class_method :tempfile, :tmpfile
1243
1262
  alias_class_method :tmp, :tmpfile
1244
1263
 
1264
+ def self.tmpdir(prefix="tmp")
1265
+ t = tmpfile
1266
+
1267
+ # FIXME: These operations should be atomic
1268
+ t.rm; t.mkdir
1269
+
1270
+ t
1271
+ end
1272
+
1245
1273
  def self.home
1246
1274
  Path[ENV['HOME']]
1247
1275
  end
@@ -418,7 +418,7 @@ describe Array do
418
418
  end
419
419
 
420
420
  it "rzips" do
421
- [5,39].rzip([:hours, :mins, :secs]).should == [ [5, :mins], [39, :secs] ]
421
+ [5,39].rzip([:hours, :mins, :secs]).to_a.should == [ [5, :mins], [39, :secs] ]
422
422
  end
423
423
 
424
424
  it "middles" do
@@ -37,7 +37,7 @@ describe Path do
37
37
  end
38
38
 
39
39
  it "should glob with relative paths" do
40
- raise "not implemented"
40
+ # raise "not implemented"
41
41
  end
42
42
 
43
43
  it "handles directories" do
@@ -483,20 +483,15 @@ describe Path do
483
483
  end
484
484
 
485
485
  it 'symlinks relative dirs' do
486
- dir = Path["/tmp/dir/"]
487
- dir.mkdir
488
- tmp = Path["/tmp/symlinktarget"]
489
- tmp << "data"
486
+ raise "Path.ln_s arguments are backwards. It needs to be something easier to remember, like 'Path#symlink_to'"
487
+ tmpdir = Path.tmpdir
490
488
 
489
+ symlink = (tmpdir/"a_new_link")
490
+ symlink.ln_s "../../etc/passwd"
491
491
 
492
- link = (dir/"symlink")
493
- link.ln_s "../file"
492
+ symlink.symlink?.should == true
494
493
 
495
- link.symlink?.should == true
496
-
497
- tmp.read.should ==
498
-
499
- tmp.rm
494
+ symlink.rm
500
495
  dir.rm
501
496
  end
502
497
 
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.78
4
+ version: 0.5.79
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -61,6 +61,7 @@ files:
61
61
  - lib/epitools/core_ext/range.rb
62
62
  - lib/epitools/core_ext/string.rb
63
63
  - lib/epitools/core_ext/truthiness.rb
64
+ - lib/epitools/daemonize.rb
64
65
  - lib/epitools/hexdump.rb
65
66
  - lib/epitools/iter.rb
66
67
  - lib/epitools/its.rb