utils 0.0.94 → 0.0.95

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f305d8f5b4e73105aab4d04fb8d8f532fa7315a
4
- data.tar.gz: 5805f755e522eb42e7c6beb1f54ba05991af74a3
3
+ metadata.gz: b2dac1f83a4dd6b72644ff55a4e8a25739ddf72c
4
+ data.tar.gz: ad875a032b04323d2eb2680f01e66cd8fa30fe09
5
5
  SHA512:
6
- metadata.gz: ba6e73af147acc19a600c722d9c5e974cb1c15b7502d0d7d9a4f0878d13a9555f7ec83749be2b4753df2c50970009c5ec3e6e719d33079d413dd944c2cf5bb0c
7
- data.tar.gz: 914eb916619c1bcd932ca240c01bff12902701bacb04bd29317ff18fb383a02637060fb5fe0c0d3ef93572de891244b7064961179e211b9b11c6675b5c196d63
6
+ metadata.gz: b10aefc8448a99346cb51093d3061d655f734f37c668908544b538e87e7e9c25b4c6e31f1a812f96237608ccc4be81e43f532c825a10b7ed41ed28880d1a4789
7
+ data.tar.gz: 88d34d3d0e82ecf2408fbd10d3910aa546767faf4c6e0f0dd9bca4f0172a48c6771903981f4f8c0125ef3022471831b5ee094acd8c0273b07166779e7a34eee4
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ GemHadar do
16
16
  readme 'README.rdoc'
17
17
 
18
18
  dependency 'tins', '~>0.8', '>=0.8.3'
19
- dependency 'term-ansicolor', '~>1.0'
19
+ dependency 'term-ansicolor', '~>1.2', '>=1.2.2'
20
20
  dependency 'dslkit', '~>0.2.10'
21
21
  dependency 'pstree'
22
22
  dependency 'pry-editline'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.94
1
+ 0.0.95
data/bin/edit CHANGED
@@ -17,6 +17,8 @@ Options are
17
17
  -w open a buffer in vim and wait until it is deleted
18
18
  -s read files and files:linenumbers from stdin and open them
19
19
  -m make intermediate non existing directories to file
20
+ -c COMMAND send ex command to the current running editor
21
+ -C COMMAND send visual command to the current running editor
20
22
  -p DURATION pause for this many seconds to wait for vim's reaction
21
23
  -S SERVER specify the server for this edit command
22
24
  -h display this help
@@ -26,7 +28,7 @@ Version is #{File.basename($0)} #{Utils::VERSION}.
26
28
  exit 1
27
29
  end
28
30
 
29
- $opt = go 'p:S:wsmh'
31
+ $opt = go 'p:S:c:wsmh'
30
32
  $opt['h'] and usage
31
33
 
32
34
  config = Utils::Config::ConfigFile.new
@@ -49,31 +51,36 @@ if $opt['s']
49
51
  rescue Interrupt
50
52
  exit 1
51
53
  end
52
- else
53
- argv = ARGV.dup
54
- if argv.empty?
55
- unless STDIN.tty?
56
- file = File.new(File.join(Dir.tmpdir, "edit_tmp.#$$"), 'w')
57
- until STDIN.eof?
58
- buffer = STDIN.read(8192)
59
- file.write buffer
60
- end
61
- file.close
62
- argv << file.path
54
+ exit 0
55
+ elsif command = $opt['c']
56
+ editor.edit_remote_send "\e:#{command}\n"
57
+ elsif command = $opt['C']
58
+ editor.edit_remote_send command
59
+ end
60
+
61
+ argv = ARGV.dup
62
+ if argv.empty?
63
+ unless STDIN.tty?
64
+ file = File.new(File.join(Dir.tmpdir, "edit_tmp.#$$"), 'w')
65
+ until STDIN.eof?
66
+ buffer = STDIN.read(8192)
67
+ file.write buffer
63
68
  end
69
+ file.close
70
+ argv << file.path
64
71
  end
65
- if argv.empty?
66
- editor.start
67
- else
68
- if editor.file_linenumber?(argv.first)
69
- editor.wait = argv.size > 1
70
- for current_file in argv
71
- STDOUT.puts "Edit #{current_file}"
72
- editor.edit current_file
73
- end
74
- else
75
- editor.edit(*argv)
72
+ end
73
+ if argv.empty?
74
+ editor.start
75
+ else
76
+ if editor.file_linenumber?(argv.first)
77
+ editor.wait = argv.size > 1
78
+ for current_file in argv
79
+ STDOUT.puts "Edit #{current_file}"
80
+ editor.edit current_file
76
81
  end
82
+ else
83
+ editor.edit(*argv)
77
84
  end
78
85
  end
79
86
  exit 0
data/bin/probe CHANGED
@@ -17,6 +17,7 @@ Options are
17
17
  -n TESTNAME run the test TESTNAME in file FILENAME
18
18
  -t FRAMEWORK use test framework FRAMEWORK (rspec, test-unit or cucumber)
19
19
  -c start probe as a client
20
+ -C start probe as a client console
20
21
  -l start probe as a server
21
22
  -p PORT listen on/connect to local port PORT
22
23
  -h display this help
@@ -41,26 +42,26 @@ $config.configure_from_paths
41
42
  testrunner_args = []
42
43
  if i = ARGV.index('--')
43
44
  testrunner_args.concat ARGV[(i + 1)..-1]
44
- args = ARGV[0...i]
45
+ $args = ARGV[0...i]
45
46
  else
46
- args = ARGV.dup
47
+ $args = ARGV.dup
47
48
  end
48
- $opt = go 'lcp:t:n:h', args
49
+ $opt = go 'lcCp:t:n:h', $args
49
50
  $opt['h'] and usage
50
51
 
51
- uri = "druby://localhost:#{$opt['p'] || 6623}"
52
+ $uri = "druby://localhost:#{$opt['p'] || 6623}"
52
53
 
53
- if $opt['l']
54
+ def start_server
54
55
  Thread.abort_on_exception = $DEBUG
55
56
 
56
57
  begin
57
58
  DRb.start_service
58
- DRbObject.new_with_uri(uri).shutdown
59
+ DRbObject.new_with_uri($uri).shutdown
59
60
  rescue DRb::DRbConnError
60
61
  end
61
62
 
62
- puts "Starting probe server listening to #{uri.inspect}."
63
- DRb.start_service(uri, ProbeServer.new)
63
+ puts "Starting probe server listening to #{$uri.inspect}."
64
+ DRb.start_service($uri, Utils::ProbeServer.new)
64
65
  begin
65
66
  DRb.thread.join
66
67
  rescue Interrupt
@@ -69,28 +70,41 @@ if $opt['l']
69
70
  end
70
71
  end
71
72
 
72
- if $opt['c']
73
- puts "Connecting probe server on #{uri.inspect}."
73
+ def connect_server
74
+ puts "Connecting probe server on #{$uri.inspect}."
74
75
  DRb.start_service
75
- probe_server = DRbObject.new_with_uri(uri)
76
- unless args.empty?
77
- opts = $opt.subhash('n', 't').map { |k, v| v.full? { %W[-#{k} #{v}] } }.compact.flatten
78
- probe_server.enqueue opts + args
76
+ probe_server = DRbObject.new_with_uri($uri)
77
+ if $opt['c']
78
+ opts = $opt.subhash('n', 't').map { |k, v|
79
+ v.full? { "-#{k} #{v.inspect}" }
80
+ }.compact
81
+ probe_server.enqueue opts + $args
82
+ exit
83
+ elsif $opt['C']
84
+ ARGV.clear
85
+ Tins::IRB.examine probe_server
86
+ exit
79
87
  end
80
- exit
81
88
  end
82
89
 
83
- args.empty? and fail "require filename or filename:linenumber as arguments"
84
- puts "Running tests in #{args.inspect}"
90
+ case
91
+ when $opt['l']
92
+ start_server
93
+ else
94
+ connect_server
95
+ end
96
+
97
+ $args.empty? and fail "require filename or filename:linenumber as arguments"
98
+ puts "Running tests in #{$args.inspect}"
85
99
 
86
100
  case ($opt['t'] || $config.probe.test_framework).to_sym
87
101
  when :rspec
88
102
  rspec = find_cmd('rspec', 'spec')
89
103
  if linenumber = $opt['n']
90
104
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, rspec, '-l',
91
- linenumber, *(args + testrunner_args)
105
+ linenumber, *($args + testrunner_args)
92
106
  else
93
- args = args.map do |a|
107
+ $args = $args.map do |a|
94
108
  if Utils::Editor::FILE_LINENUMBER_REGEXP =~ a
95
109
  $~.captures * ':'
96
110
  else
@@ -98,15 +112,15 @@ when :rspec
98
112
  end
99
113
  end
100
114
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, rspec,
101
- *(args + testrunner_args)
115
+ *($args + testrunner_args)
102
116
  end
103
117
  when :'test-unit'
104
118
  testrb = find_cmd('testrb')
105
119
  if testname = $opt['n']
106
120
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, testrb,
107
- '-n', testname, *(args + testrunner_args)
121
+ '-n', testname, *($args + testrunner_args)
108
122
  else
109
- for filename in args
123
+ for filename in $args
110
124
  sl = filename.source_location
111
125
  if sl.linenumber
112
126
  lf = Tins::LinesFile.for_filename(*sl)
@@ -126,9 +140,9 @@ when :cucumber
126
140
  cucumber = find_cmd('cucumber')
127
141
  if linenumber = $opt['n']
128
142
  cmd 'ruby', cucumber, '-r', $config.probe.include_dirs_argument, '-l',
129
- linenumber, *(args + testrunner_args)
143
+ linenumber, *($args + testrunner_args)
130
144
  else
131
- args = args.map do |a|
145
+ $args = $args.map do |a|
132
146
  if Utils::Editor::FILE_LINENUMBER_REGEXP =~ a
133
147
  $~.captures * ':'
134
148
  else
@@ -136,6 +150,6 @@ when :cucumber
136
150
  end
137
151
  end
138
152
  cmd 'ruby', cucumber, '-r', $config.probe.include_dirs_argument,
139
- *(args + testrunner_args)
153
+ *($args + testrunner_args)
140
154
  end
141
155
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'tins/xt'
4
2
  require 'term/ansicolor'
5
3
  class String
@@ -8,51 +6,107 @@ end
8
6
 
9
7
  module Utils
10
8
  class ProbeServer
9
+ class Job
10
+ def initialize(probe_server, args)
11
+ @id = probe_server.next_job_id
12
+ @args = args
13
+ end
14
+
15
+ attr_reader :id
16
+
17
+ attr_reader :args
18
+
19
+ def inspect
20
+ "#<#{self.class}: id=#{id} args=#{args.inspect}>"
21
+ end
22
+ end
23
+
11
24
  def initialize
12
- @jobs = Queue.new
25
+ @jobs_queue = Queue.new
26
+ @current_job_id = 0
13
27
  Thread.new { work_loop }
14
28
  end
15
29
 
16
- def enqueue(job)
17
- output_message "Job #{job.inspect} enqueued.".black.on_yellow
18
- @jobs.push job
30
+ def next_job_id
31
+ @current_job_id += 1
32
+ end
33
+
34
+ def enqueue(job_args)
35
+ job = Job.new(self, job_args)
36
+ output_message "#{job.inspect} enqueued."
37
+ @jobs_queue.push job
19
38
  end
20
39
  alias run enqueue
21
40
 
41
+ def stop
42
+ @pid and Process.kill :STOP, @pid
43
+ end
44
+
45
+ def continue
46
+ @pid and Process.kill :CONT, @pid
47
+ end
48
+
22
49
  def shutdown
23
- output_message "Server was shutdown down – HARD!".white.on_red.blink
50
+ output_message "Server was shutdown down – HARD!", :type => :warn
24
51
  exit! 23
25
52
  end
26
53
 
54
+ def list_jobs
55
+ @jobs_queue.instance_variable_get(:@que)
56
+ end
57
+
58
+ def clear_jobs
59
+ queue_synchronize do
60
+ unless @jobs_queue.empty?
61
+ @jobs_queue.clear
62
+ output_message "Cleared all queued jobs.", :type => :warn
63
+ true
64
+ else
65
+ false
66
+ end
67
+ end
68
+ end
69
+
27
70
  private
28
71
 
29
- def output_message(msg)
72
+ def queue_synchronize(&block)
73
+ @jobs_queue.instance_variable_get(:@mutex).synchronize(&block)
74
+ end
75
+
76
+ def output_message(msg, opts = { :type => :info })
77
+ msg =
78
+ case opts[:type]
79
+ when :success
80
+ msg.on_green.black
81
+ when :info, nil
82
+ msg.on_color(118).black
83
+ when :warn
84
+ msg.on_color(166).black
85
+ when :failure
86
+ msg.on_red.blink.white
87
+ end
30
88
  STDOUT.puts msg
31
89
  STDOUT.flush
32
90
  end
33
91
 
34
92
  def run_job(job)
35
- message = "Job #{job.inspect} about to run now:".black
36
- message = message.ask_and_send(:on_color, 166) || message.on_yellow
37
- output_message message
38
- fork do
39
- exec(*cmd(job))
40
- end
41
- Process.wait
42
- message = "Job #{job.inspect} was just run"
93
+ output_message "#{job.inspect} about to run now.", :type => :info
94
+ @pid = fork { exec(*cmd(job.args)) }
95
+ output_message "#{job.inspect} now running with pid #@pid.", :type => :info
96
+ Process.wait @pid
97
+ message = "#{job.inspect} was just run"
43
98
  if $?.success?
44
99
  message << " successfully."
45
- message = message.black.on_green
100
+ output_message message, :type => :success
46
101
  else
47
102
  message << " and failed with exit status #{$?.exitstatus}!"
48
- message = message.white.on_red.blink
103
+ output_message message, :type => :failure
49
104
  end
50
- output_message message
51
105
  end
52
106
 
53
107
  def work_loop
54
108
  loop do
55
- job = @jobs.shift
109
+ job = @jobs_queue.shift
56
110
  run_job job
57
111
  end
58
112
  end
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.0.94'
3
+ VERSION = '0.0.95'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: utils 0.0.95 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "utils"
5
- s.version = "0.0.94"
6
+ s.version = "0.0.95"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
9
  s.authors = ["Florian Frank"]
9
- s.date = "2013-08-16"
10
+ s.date = "2013-09-30"
10
11
  s.description = "This ruby gem provides some useful command line utilities"
11
12
  s.email = "flori@ping.de"
12
13
  s.executables = ["brakeman2err", "chroot-exec", "chroot-libs", "classify", "create_tags", "discover", "edit", "edit_wait", "enum", "errf", "git-empty", "irb_connect", "myex", "number_files", "on_change", "path", "probe", "remote_copy", "same_files", "search", "sedit", "ssh-tunnel", "strip_spaces", "unquarantine_apps", "untest", "utils-install-config", "utils-utilsrc", "vacuum_firefox_sqlite", "xmp"]
@@ -15,7 +16,7 @@ Gem::Specification.new do |s|
15
16
  s.homepage = "http://github.com/flori/utils"
16
17
  s.rdoc_options = ["--title", "Utils - Some useful command line utilities", "--main", "README.rdoc"]
17
18
  s.require_paths = ["lib"]
18
- s.rubygems_version = "2.0.4"
19
+ s.rubygems_version = "2.1.4"
19
20
  s.summary = "Some useful command line utilities"
20
21
 
21
22
  if s.respond_to? :specification_version then
@@ -24,14 +25,14 @@ Gem::Specification.new do |s|
24
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
26
  s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.8"])
26
27
  s.add_runtime_dependency(%q<tins>, [">= 0.8.3", "~> 0.8"])
27
- s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.0"])
28
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 1.2.2", "~> 1.2"])
28
29
  s.add_runtime_dependency(%q<dslkit>, ["~> 0.2.10"])
29
30
  s.add_runtime_dependency(%q<pstree>, [">= 0"])
30
31
  s.add_runtime_dependency(%q<pry-editline>, [">= 0"])
31
32
  else
32
33
  s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
33
34
  s.add_dependency(%q<tins>, [">= 0.8.3", "~> 0.8"])
34
- s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
35
+ s.add_dependency(%q<term-ansicolor>, [">= 1.2.2", "~> 1.2"])
35
36
  s.add_dependency(%q<dslkit>, ["~> 0.2.10"])
36
37
  s.add_dependency(%q<pstree>, [">= 0"])
37
38
  s.add_dependency(%q<pry-editline>, [">= 0"])
@@ -39,7 +40,7 @@ Gem::Specification.new do |s|
39
40
  else
40
41
  s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
41
42
  s.add_dependency(%q<tins>, [">= 0.8.3", "~> 0.8"])
42
- s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
43
+ s.add_dependency(%q<term-ansicolor>, [">= 1.2.2", "~> 1.2"])
43
44
  s.add_dependency(%q<dslkit>, ["~> 0.2.10"])
44
45
  s.add_dependency(%q<pstree>, [">= 0"])
45
46
  s.add_dependency(%q<pry-editline>, [">= 0"])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.94
4
+ version: 0.0.95
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -50,14 +50,20 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '1.0'
53
+ version: '1.2'
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 1.2.2
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - ~>
59
62
  - !ruby/object:Gem::Version
60
- version: '1.0'
63
+ version: '1.2'
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.2.2
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: dslkit
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -228,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
234
  version: '0'
229
235
  requirements: []
230
236
  rubyforge_project:
231
- rubygems_version: 2.0.4
237
+ rubygems_version: 2.1.4
232
238
  signing_key:
233
239
  specification_version: 4
234
240
  summary: Some useful command line utilities