diff options
-rw-r--r-- | Rakefile | 62 | ||||
-rw-r--r-- | lib/systemu.rb | 45 | ||||
-rw-r--r-- | pkg/systemu-2.6.4.gem | bin | 0 -> 14336 bytes | |||
-rw-r--r-- | systemu.gemspec | 8 | ||||
-rw-r--r-- | test/systemu_test.rb | 14 |
5 files changed, 88 insertions, 41 deletions
@@ -4,7 +4,7 @@ This.email = "ara.t.howard@gmail.com" This.homepage = "https://github.com/ahoward/#{ This.lib }" task :license do - open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"} + open('LICENSE', 'w'){|fd| fd.puts "Ruby"} end task :default do @@ -32,7 +32,7 @@ def run_tests!(which = nil) test_rbs.each_with_index do |test_rb, index| testno = index + 1 - command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }" + command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }" puts say(div, :color => :cyan, :bold => true) @@ -63,7 +63,7 @@ end task :gemspec do ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem'] ignore_directories = ['pkg'] - ignore_files = ['test/log', 'a.rb'] + ignore_files = ['test/log'] shiteless = lambda do |list| @@ -93,6 +93,7 @@ task :gemspec do test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb") summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass" description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass" + license = object.respond_to?(:license) ? object.license : "Ruby" if This.extensions.nil? This.extensions = [] @@ -103,38 +104,51 @@ task :gemspec do end extensions = [extensions].flatten.compact + if This.dependencies.nil? + dependencies = [] + else + case This.dependencies + when Hash + dependencies = This.dependencies.values + when Array + dependencies = This.dependencies + end + end + template = if test(?e, 'gemspec.erb') Template{ IO.read('gemspec.erb') } else Template { <<-__ - ## #{ lib }.gemspec + ## <%= lib %>.gemspec # Gem::Specification::new do |spec| - spec.name = #{ lib.inspect } - spec.version = #{ version.inspect } + spec.name = <%= lib.inspect %> + spec.version = <%= version.inspect %> spec.platform = Gem::Platform::RUBY - spec.summary = #{ lib.inspect } - spec.description = #{ description.inspect } + spec.summary = <%= lib.inspect %> + spec.description = <%= description.inspect %> + spec.license = <%= license.inspect %> - spec.files =\n#{ files.sort.pretty_inspect } - spec.executables = #{ executables.inspect } + spec.files =\n<%= files.sort.pretty_inspect %> + spec.executables = <%= executables.inspect %> spec.require_path = "lib" - spec.test_files = #{ test_files.inspect } + spec.test_files = <%= test_files.inspect %> - ### spec.add_dependency 'lib', '>= version' - #### spec.add_dependency 'map' + <% dependencies.each do |lib_version| %> + spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>) + <% end %> - spec.extensions.push(*#{ extensions.inspect }) + spec.extensions.push(*<%= extensions.inspect %>) - spec.rubyforge_project = #{ This.rubyforge_project.inspect } - spec.author = #{ This.author.inspect } - spec.email = #{ This.email.inspect } - spec.homepage = #{ This.homepage.inspect } + spec.rubyforge_project = <%= This.rubyforge_project.inspect %> + spec.author = <%= This.author.inspect %> + spec.email = <%= This.email.inspect %> + spec.homepage = <%= This.homepage.inspect %> end __ } @@ -178,8 +192,8 @@ task :readme do end template = - if test(?e, 'readme.erb') - Template{ IO.read('readme.erb') } + if test(?e, 'README.erb') + Template{ IO.read('README.erb') } else Template { <<-__ @@ -270,6 +284,12 @@ BEGIN { end This.version = version +# see if dependencies are export by the module +# + if This.object.respond_to?(:dependencies) + This.dependencies = This.object.dependencies + end + # we need to know the name of the lib an it's version # abort('no lib') unless This.lib @@ -277,7 +297,7 @@ BEGIN { # discover full path to this ruby executable # - c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end + c = Config::CONFIG bindir = c["bindir"] || c['BINDIR'] ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby' ruby_ext = c['EXEEXT'] || '' diff --git a/lib/systemu.rb b/lib/systemu.rb index 719b70a..c32b9bc 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -14,9 +14,12 @@ class SystemUniversal # # constants # - SystemUniversal::VERSION = '2.5.2' unless SystemUniversal.send(:const_defined?, :VERSION) + SystemUniversal::VERSION = '2.6.4' unless SystemUniversal.send(:const_defined?, :VERSION) def SystemUniversal.version() SystemUniversal::VERSION end def version() SystemUniversal::VERSION end + def SystemUniversal.description + "universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc." + end # # class methods # @@ -73,7 +76,7 @@ class SystemUniversal thread = nil quietly{ - IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'r+' do |pipe| + IO.popen "#{ quote(@ruby) } #{ quote(c['program']) }", 'rb+' do |pipe| line = pipe.gets case line when %r/^pid: \d+$/ @@ -108,11 +111,11 @@ class SystemUniversal end if @stdout or @stderr - open(c['stdout']){|f| relay f => @stdout} if @stdout - open(c['stderr']){|f| relay f => @stderr} if @stderr + open(c['stdout'], 'rb'){|f| relay f => @stdout} if @stdout + open(c['stderr'], 'rb'){|f| relay f => @stderr} if @stderr status else - [status, IO.read(c['stdout']), IO.read(c['stderr'])] + [status, open(c['stdout'], 'rb'){|f| f.read}, open(c['stderr'], 'rb'){|f| f.read}] end end end @@ -121,9 +124,9 @@ class SystemUniversal SystemUniversal.quote(*args, &block) end - def new_thread cid, block + def new_thread child_pid, block q = Queue.new - Thread.new(cid) do |cid| + Thread.new(child_pid) do |cid| current = Thread.current current.abort_on_exception = true q.push current @@ -140,7 +143,7 @@ class SystemUniversal config = File.expand_path(File.join(tmp, 'config')) if @stdin - open(stdin, 'w'){|f| relay @stdin => f} + open(stdin, 'wb'){|f| relay @stdin => f} else FileUtils.touch stdin end @@ -155,9 +158,9 @@ class SystemUniversal c['stdout'] = stdout c['stderr'] = stderr c['program'] = program - open(config, 'w'){|f| Marshal.dump(c, f)} + open(config, 'wb'){|f| Marshal.dump(c, f)} - open(program, 'w'){|f| f.write child_program(config)} + open(program, 'wb'){|f| f.write child_program(config)} c end @@ -205,9 +208,9 @@ class SystemUniversal end def relay srcdst - src, dst, ignored = srcdst.to_a.first + src, dst, _ = srcdst.to_a.first if src.respond_to? 'read' - while((buf = src.read(8192))); dst << buf; end + while((buffer = src.read(8192))); dst << buffer; end else if src.respond_to?(:each_line) src.each_line{|buf| dst << buf} @@ -217,11 +220,21 @@ class SystemUniversal end end + def slug_for(*args) + options = args.last.is_a?(Hash) ? args.pop : {} + join = (options[:join] || options['join'] || '_').to_s + string = args.flatten.compact.join(join) + words = string.to_s.scan(%r|[/\w]+|) + words.map!{|word| word.gsub %r|[^/0-9a-zA-Z_-]|, ''} + words.delete_if{|word| word.nil? or word.strip.empty?} + words.join(join).downcase.gsub('/', (join * 2)) + end + def tmpdir d = Dir.tmpdir, max = 42, &b i = -1 and loop{ i += 1 - tmp = File.join d, "systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }" + tmp = File.join(d, slug_for("systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }")) begin Dir.mkdir tmp @@ -246,11 +259,11 @@ class SystemUniversal def getopts opts = {} lambda do |*args| - keys, default, ignored = args + keys, default, _ = args catch(:opt) do [keys].flatten.each do |key| - [key, key.to_s, key.to_s.intern].each do |key| - throw :opt, opts[key] if opts.has_key?(key) + [key, key.to_s, key.to_s.intern].each do |k| + throw :opt, opts[k] if opts.has_key?(k) end end default diff --git a/pkg/systemu-2.6.4.gem b/pkg/systemu-2.6.4.gem Binary files differnew file mode 100644 index 0000000..36e828f --- /dev/null +++ b/pkg/systemu-2.6.4.gem diff --git a/systemu.gemspec b/systemu.gemspec index 6d0b469..bfe834c 100644 --- a/systemu.gemspec +++ b/systemu.gemspec @@ -3,10 +3,11 @@ Gem::Specification::new do |spec| spec.name = "systemu" - spec.version = "2.5.2" + spec.version = "2.6.4" spec.platform = Gem::Platform::RUBY spec.summary = "systemu" - spec.description = "description: systemu kicks the ass" + spec.description = "universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc." + spec.license = "Ruby" spec.files = ["LICENSE", @@ -33,8 +34,7 @@ Gem::Specification::new do |spec| spec.test_files = nil -### spec.add_dependency 'lib', '>= version' -#### spec.add_dependency 'map' + spec.extensions.push(*[]) diff --git a/test/systemu_test.rb b/test/systemu_test.rb index 19fac1d..6d4bf2b 100644 --- a/test/systemu_test.rb +++ b/test/systemu_test.rb @@ -17,6 +17,20 @@ Testing SystemU do assert{ stdout == stdin } end + testing 'silly hostnames' do + host = SystemU.instance_variable_get('@host') + silly_hostname = "silly's hostname with spaces" + begin + SystemU.instance_variable_set('@host', silly_hostname) + assert{ SystemU.instance_variable_get('@host') == silly_hostname } + stdin = '42' + status, stdout, stderr = assert{ systemu :bin/:cat, :stdin => stdin } + assert{ status == 0 } + ensure + assert{ SystemU.instance_variable_set('@host', host) } + end + end + end |