alib 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,7 @@
3
3
  #
4
4
  module ALib
5
5
  #--{{{
6
- VERSION = '0.4.0'
7
-
8
- def self.version() VERSION end
6
+ VERSION = '0.5.0'
9
7
 
10
8
  require 'pathname'
11
9
  require 'socket'
@@ -21,14 +19,19 @@ module ALib
21
19
  require 'fcntl'
22
20
  require 'uri'
23
21
  require 'net/http'
22
+ require 'thread'
24
23
 
25
-
26
- # TODO - bundle open4!!
24
+ class ::Object
25
+ Alib = ALib
26
+ def alib() ALib end
27
+ end
27
28
 
28
29
  LIBDIR = 'alib-%s/' % VERSION
29
30
 
30
- AUTOLOAD = {
31
+ require LIBDIR + 'classmethods'
32
+ require LIBDIR + 'stdext'
31
33
 
34
+ AUTOLOAD = {
32
35
  'Util' => 'util',
33
36
 
34
37
  'Logging' => 'logging',
@@ -54,51 +57,25 @@ module ALib
54
57
  'AbstractMain' => 'main',
55
58
  'SimpleMain' => 'main',
56
59
  'ConfigurableMain' => 'main',
57
-
58
60
  }
59
61
 
60
62
  AUTOLOAD.each{|const, basename| autoload const.to_s, LIBDIR + basename.to_s}
61
63
 
62
- METACLASS =
64
+ SINGLETON_CLASS =
63
65
  class << self
64
66
  self
65
67
  end
66
68
 
67
- AUTOLOAD.each{ |const, m| METACLASS.module_eval{ define_method(m){ ALib.send 'const_get', const}}}
68
-
69
- begin
70
- require 'open4'
71
- rescue LoadError
72
- require LIBDIR + 'open4'
73
- end
69
+ AUTOLOAD.each{ |const, m| SINGLETON_CLASS.module_eval{define_method(m){ALib.send 'const_get', const}} unless Alib.respond_to? m}
74
70
 
75
- class << self
76
- #--{{{
77
- def load basename
78
- #--{{{
79
- require LIBDIR + basename.to_s
80
- #--}}}
81
- end
82
- def simple_main &b
83
- #--{{{
84
- b ? Class::new(ALib::SimpleMain, &b) : ALib::SimpleMain
85
- #--}}}
86
- end
87
- alias_method 'main', 'simple_main'
88
- alias_method 'smain', 'simple_main'
89
- def configurable_main &b
90
- #--{{{
91
- b ? Class::new(ALib::ConfigurableMain, &b) : ALib::ConfigurableMain
92
- #--}}}
71
+ %w( open4 attributes prototype binding_of_caller ).each do |lib|
72
+ begin
73
+ require lib
74
+ rescue LoadError
75
+ require LIBDIR + lib
76
+ $LOADED_FEATURES << File.basename(lib)
93
77
  end
94
- alias_method 'cmain', 'configurable_main'
95
- #--}}}
96
78
  end
97
79
  #--}}}
98
80
  end
99
81
 
100
- Alib = ALib
101
-
102
- class Object
103
- def alib() Alib end
104
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: alib
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2006-08-23 00:00:00.000000 -06:00
6
+ version: 0.5.0
7
+ date: 2007-02-18 00:00:00 -07:00
8
8
  summary: alib
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: ara.t.howard@noaa.gov
12
12
  homepage: http://codeforpeople.com/lib/ruby/alib/
13
13
  rubyforge_project:
@@ -18,43 +18,56 @@ bindir: bin
18
18
  has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
28
+ post_install_message:
29
29
  authors:
30
- - Ara T. Howard
30
+ - Ara T. Howard
31
31
  files:
32
- - lib
33
- - install.rb
34
- - install
35
- - gemspec.rb
36
- - build
37
- - alib-0.4.0.gem
38
- - b.rb
39
- - a.rb
40
- - lib/alib-0.4.0.rb
41
- - lib/alib.rb
42
- - lib/alib-0.4.0
43
- - lib/alib-0.4.0/util.rb
44
- - lib/alib-0.4.0/logging.rb
45
- - lib/alib-0.4.0/configfile.rb
46
- - lib/alib-0.4.0/listfile.rb
47
- - lib/alib-0.4.0/autohash.rb
48
- - lib/alib-0.4.0/orderedautohash.rb
49
- - lib/alib-0.4.0/orderedhash.rb
50
- - lib/alib-0.4.0/find2.rb
51
- - lib/alib-0.4.0/bsearch.rb
52
- - lib/alib-0.4.0/main.rb
53
- - lib/alib-0.4.0/open4.rb
32
+ - a.rb
33
+ - gemspec.rb
34
+ - alib-0.5.0.gem
35
+ - install.rb
36
+ - lib
37
+ - lib/alib.rb
38
+ - lib/alib-0.5.0
39
+ - lib/alib-0.5.0/logging.rb
40
+ - lib/alib-0.5.0/bsearch.rb
41
+ - lib/alib-0.5.0/open4-0.9.1.rb
42
+ - lib/alib-0.5.0/stdext.rb
43
+ - lib/alib-0.5.0/attributes.rb
44
+ - lib/alib-0.5.0/util.rb
45
+ - lib/alib-0.5.0/prototype.rb
46
+ - lib/alib-0.5.0/listfile.rb
47
+ - lib/alib-0.5.0/binding_of_caller.rb
48
+ - lib/alib-0.5.0/prototype-0.3.0.rb
49
+ - lib/alib-0.5.0/configfile.rb
50
+ - lib/alib-0.5.0/main.rb.bak
51
+ - lib/alib-0.5.0/attributes-3.2.0.rb
52
+ - lib/alib-0.5.0/open4.rb
53
+ - lib/alib-0.5.0/autohash.rb
54
+ - lib/alib-0.5.0/orderedautohash.rb
55
+ - lib/alib-0.5.0/classmethods.rb
56
+ - lib/alib-0.5.0/main.rb
57
+ - lib/alib-0.5.0/orderedhash.rb
58
+ - lib/alib-0.5.0/find2.rb
59
+ - lib/alib-0.5.0.rb
54
60
  test_files: []
61
+
55
62
  rdoc_options: []
63
+
56
64
  extra_rdoc_files: []
65
+
57
66
  executables: []
67
+
58
68
  extensions: []
69
+
59
70
  requirements: []
60
- dependencies: []
71
+
72
+ dependencies: []
73
+
data/b.rb DELETED
@@ -1 +0,0 @@
1
- class C; end
data/build DELETED
File without changes
data/install DELETED
@@ -1,143 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rbconfig'
3
- require 'find'
4
- require 'ftools'
5
- require 'tempfile'
6
- include Config
7
-
8
- LIBDIR = "lib"
9
- LIBDIR_MODE = 0644
10
-
11
- BINDIR = "bin"
12
- BINDIR_MODE = 0755
13
-
14
-
15
- $srcdir = CONFIG["srcdir"]
16
- $version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
17
- $libdir = File.join(CONFIG["libdir"], "ruby", $version)
18
- $archdir = File.join($libdir, CONFIG["arch"])
19
- $site_libdir = $:.find {|x| x =~ /site_ruby$/}
20
- $bindir = CONFIG["bindir"]
21
- $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME']
22
- $ruby = File.join($bindir, $ruby_install_name || 'ruby')
23
-
24
- if !$site_libdir
25
- $site_libdir = File.join($libdir, "site_ruby")
26
- elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
27
- $site_libdir = File.join($site_libdir, $version)
28
- end
29
-
30
- def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
31
- #{{{
32
- path = []
33
- dir = []
34
- Find.find(srcdir) do |f|
35
- next unless FileTest.file?(f)
36
- next if (f = f[srcdir.length+1..-1]) == nil
37
- next if (/CVS$/ =~ File.dirname(f))
38
- path.push f
39
- dir |= [File.dirname(f)]
40
- end
41
- for f in dir
42
- next if f == "."
43
- next if f == "CVS"
44
- File::makedirs(File.join(destdir, f))
45
- end
46
- for f in path
47
- next if (/\~$/ =~ f)
48
- next if (/^\./ =~ File.basename(f))
49
- unless bin
50
- File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
51
- else
52
- from = File.join(srcdir, f)
53
- to = File.join(destdir, f)
54
- shebangify(from) do |sf|
55
- $deferr.print from, " -> ", File::catname(from, to), "\n"
56
- $deferr.printf "chmod %04o %s\n", mode, to
57
- File::install(sf, to, mode, false)
58
- end
59
- end
60
- end
61
- #}}}
62
- end
63
- def shebangify f
64
- #{{{
65
- open(f) do |fd|
66
- buf = fd.read 42
67
- if buf =~ %r/^\s*#\s*!.*ruby/o
68
- ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
69
- begin
70
- fd.rewind
71
- ftmp.puts "#!#{ $ruby }"
72
- while((buf = fd.read(8192)))
73
- ftmp.write buf
74
- end
75
- ftmp.close
76
- yield ftmp.path
77
- ensure
78
- ftmp.close!
79
- end
80
- else
81
- yield f
82
- end
83
- end
84
- #}}}
85
- end
86
- def ARGV.switch
87
- #{{{
88
- return nil if self.empty?
89
- arg = self.shift
90
- return nil if arg == '--'
91
- if arg =~ /^-(.)(.*)/
92
- return arg if $1 == '-'
93
- raise 'unknown switch "-"' if $2.index('-')
94
- self.unshift "-#{$2}" if $2.size > 0
95
- "-#{$1}"
96
- else
97
- self.unshift arg
98
- nil
99
- end
100
- #}}}
101
- end
102
- def ARGV.req_arg
103
- #{{{
104
- self.shift || raise('missing argument')
105
- #}}}
106
- end
107
-
108
-
109
- #
110
- # main program
111
- #
112
-
113
- libdir = $site_libdir
114
- bindir = $bindir
115
-
116
- begin
117
- while switch = ARGV.switch
118
- case switch
119
- when '-d', '--destdir'
120
- libdir = ARGV.req_arg
121
- when '-l', '--libdir'
122
- libdir = ARGV.req_arg
123
- when '-b', '--bindir'
124
- bindir = ARGV.req_arg
125
- when '-r', '--ruby'
126
- $ruby = ARGV.req_arg
127
- else
128
- raise "unknown switch #{switch.dump}"
129
- end
130
- end
131
- rescue
132
- STDERR.puts $!.to_s
133
- STDERR.puts File.basename($0) +
134
- " -d <destdir>" +
135
- " -l <libdir>" +
136
- " -b <bindir>"
137
- " -r <ruby>"
138
- exit 1
139
- end
140
-
141
- install_rb(LIBDIR, libdir, LIBDIR_MODE)
142
- install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
143
-
@@ -1,175 +0,0 @@
1
- require 'fcntl'
2
-
3
- module Open4
4
- #--{{{
5
- def self.version
6
- '0.4.0'
7
- end
8
-
9
- def popen4(*cmd)
10
- #--{{{
11
- pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
12
-
13
- verbose = $VERBOSE
14
- begin
15
- $VERBOSE = nil
16
- ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
17
-
18
- cid = fork {
19
- pw.last.close
20
- STDIN.reopen pw.first
21
- pw.first.close
22
-
23
- pr.first.close
24
- STDOUT.reopen pr.last
25
- pr.last.close
26
-
27
- pe.first.close
28
- STDERR.reopen pe.last
29
- pe.last.close
30
-
31
- STDOUT.sync = STDERR.sync = true
32
-
33
- begin
34
- exec(*cmd)
35
- raise "exec failed!"
36
- rescue Exception => e
37
- Marshal.dump(e, ps.last)
38
- ps.last.flush
39
- end
40
- ps.last.close unless (ps.last.closed?)
41
- exit!
42
- }
43
- ensure
44
- $VERBOSE = verbose
45
- end
46
-
47
- [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
48
-
49
- begin
50
- e = Marshal.load ps.first
51
- raise(Exception === e ? e : "unknown failure!")
52
- rescue EOFError # If we get an EOF error, then the exec was successful
53
- 42
54
- end
55
-
56
- pw.last.sync = true
57
-
58
- pi = [pw.last, pr.first, pe.first]
59
-
60
- if defined? yield
61
- begin
62
- yield(cid, *pi)
63
- Process.waitpid2(cid).last
64
- ensure
65
- pi.each{|fd| fd.close unless fd.closed?}
66
- end
67
- else
68
- [cid, pw.last, pr.first, pe.first]
69
- end
70
- #--}}}
71
- end
72
- alias open4 popen4
73
- module_function :popen4
74
- module_function :open4
75
-
76
- class Error < ::StandardError; end
77
- class SpawnError < Error
78
- #--{{{
79
- attr 'cmd'
80
- attr 'status'
81
- def exitstatus
82
- @status.exitstatus
83
- end
84
- def initialize cmd, status
85
- @cmd, @status = cmd, status
86
- super "cmd <#{ cmd }> failed with <#{ exitstatus }>"
87
- end
88
- #--}}}
89
- end
90
- def spawn cmd, opts = {}
91
- #--{{{
92
- getopt = lambda do |*args|
93
- keys, default, ignored = args
94
- catch('opt') do
95
- [keys].flatten.each do |key|
96
- [key, key.to_s, key.to_s.intern].each do |key|
97
- throw 'opt', opts[key] if opts.has_key?(key)
98
- end
99
- end
100
- default
101
- end
102
- end
103
-
104
- ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
105
- ignore_exec_failure = getopt[ 'ignore_exec_failure', !getopt['raise', true] ]
106
- exitstatus = getopt[ %w( exitstatus exit_status status ), 0 ]
107
- stdin = getopt[ ['stdin', 'in', '0', 0] ]
108
- stdout = getopt[ ['stdout', 'out', '1', 1] ]
109
- stderr = getopt[ ['stderr', 'err', '2', 2] ]
110
- pid = getopt[ 'pid' ]
111
-
112
- started = false
113
-
114
- status =
115
- begin
116
- popen4(cmd) do |c, i, o, e|
117
- started = true
118
-
119
- if pid.respond_to? '<<'
120
- pid << c
121
- end
122
-
123
- it = Thread.new(i,stdin) do |i,stdin|
124
- if stdin
125
- if stdin.respond_to? :each
126
- stdin.each{|buf| i << buf}
127
- elsif stdin.respond_to? :read
128
- i << stdin.read
129
- else
130
- i << stdin.to_s
131
- end
132
- end
133
- i.close
134
- end
135
-
136
- ot = Thread.new(o,stdout){|o,stdout| o.each{|buf| stdout << buf if stdout}}
137
- et = Thread.new(e,stderr){|e,stderr| e.each{|buf| stderr << buf if stderr}}
138
-
139
- it.join
140
- ot.join if ot
141
- et.join if et
142
- end
143
- rescue
144
- raise unless(not started and ignore_exec_failure)
145
- end
146
-
147
- raise SpawnError.new(cmd, status) unless
148
- (ignore_exit_failure or (status.nil? and ignore_exec_failure) or (status.exitstatus == exitstatus))
149
-
150
- status
151
- #--}}}
152
- end
153
- module_function :spawn
154
-
155
- def background cmd, opts = {}
156
- #--{{{
157
- require 'thread'
158
- q = Queue.new
159
- opts['pid'] = opts[:pid] = q
160
- thread = Thread.new(cmd, opts){|cmd, opts| spawn cmd, opts}
161
- pid = q.pop
162
- sc = class << thread; self; end
163
- sc.module_eval {
164
- define_method(:pid){ pid }
165
- define_method(:spawn_status){ @spawn_status ||= value }
166
- define_method(:exitstatus){ spawn_status.exitstatus }
167
- }
168
- thread
169
- #--}}}
170
- end
171
- alias bg background
172
- module_function :background
173
- module_function :bg
174
- #--}}}
175
- end