britebox 0.0.2 → 0.0.3

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: 9e800dec5d7cc7526497042fdd135dfeefb49b08
4
- data.tar.gz: caef336a484073e5b13fdbe31ab1c72d92155281
3
+ metadata.gz: ae190d938423b74e7df0f20150c509aef201a73f
4
+ data.tar.gz: ef9bc4daf6cb23fe62984a4b55a5ce63315c9235
5
5
  SHA512:
6
- metadata.gz: d8cf57385c286d5a807c0a3e04fc5c4ed0ec73754ebe1c0072d73951461b1d3285a63b93fe0f4dc94b5cd887e5209e5fe8fc2bdc80cd95257998e146005a87b6
7
- data.tar.gz: a887c75d7e6423e5e17fccb2b226f16a13b97c91839676cab6f11d6856aaa84312a34796247dffffa3f73e1f53c1840d2efba86340320ef457a69fadd5b5c4ac
6
+ metadata.gz: f9f7b8ac141941117e93326f84bb93cda6615b9bc7d2247f97767bc9f03e4e395b958a4884a7dcba5c4eb11801e46da1f3f8362627a1085caa447d128c10f764
7
+ data.tar.gz: 6f5222d89f56495be4404e8f7907272573e372d93996914e43a5d1e9cbc45c54310bcf44c2986083b2f410bfebf4d576e079936814c93f58dc2bbd3d2b9a1521
@@ -7,6 +7,9 @@ require 'britebox/cli'
7
7
  Thread.abort_on_exception = true
8
8
  THREAD_NUM_MAX = 10
9
9
 
10
+ # Register action on Ctrl-C
11
+ trap("SIGINT") { exit! }
12
+
10
13
  commands = ['watch']
11
14
 
12
15
  if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
@@ -18,12 +18,16 @@ module Britebox
18
18
  raise("Please provide directory-to-watch")
19
19
  end
20
20
 
21
+ raise("Directory #{@dir} does not exist") unless File.exists? @dir
22
+
21
23
  if params[:output]
22
24
  @out_dir = File.expand_path params[:output]
23
25
  else
24
26
  @out_dir = File.expand_path 'verified', @dir
25
27
  end
26
28
 
29
+ FileUtils.mkdir_p(@out_dir) unless File.exists? @out_dir
30
+
27
31
  fj_options = {threads: params[:threads]}
28
32
 
29
33
  puts "Watching directory #{@dir}"
@@ -32,10 +36,7 @@ module Britebox
32
36
 
33
37
  fj_pool = FileJobPool.new(params[:threads])
34
38
 
35
- options = {filter: /\.(#{MONITOR_EXTENSIONS.join('|')})$/}
36
- if @out_dir.include? @dir
37
- options[:ignore] = Regexp.new "^" + @out_dir.sub(@dir + File::SEPARATOR, '')
38
- end
39
+ options = {filter: /\.(#{MONITOR_EXTENSIONS.join('|')})$/, ignore: /\//}
39
40
 
40
41
  brite_client = BriteAPI::Client.new(@api_key)
41
42
 
@@ -4,7 +4,8 @@ require 'csv'
4
4
  module Britebox
5
5
  class FileJob
6
6
 
7
- attr_reader :file_name, :threads_count, :error, :status, :size_total, :size_processed
7
+ attr_reader :file_name, :threads_count, :error, :status, :size_total, :size_processed,
8
+ :started_at, :processed_at
8
9
 
9
10
  EMAIL_PATTERN = /(\S+)@(\S+)/
10
11
  COL_SEPARATORS = [";", "|", "\t"]
@@ -21,10 +22,12 @@ module Britebox
21
22
  @size_processed = 0
22
23
 
23
24
  unless File.exist?(file_name)
24
- report_error!("File #{file_name} not found") and return
25
+ report_error!("File not found")
26
+ return
25
27
  end
26
28
  if (@size_total = File.size(file_name)) == 0
27
- report_error!("File #{file_name} is empty") and return
29
+ report_error!("File is empty")
30
+ return
28
31
  end
29
32
 
30
33
  @semaphore = Mutex.new
@@ -34,6 +37,13 @@ module Britebox
34
37
  @threads_count * 4
35
38
  end
36
39
 
40
+ def duration
41
+ if @started_at
42
+ end_time = @processed_at || Time.now
43
+ end_time - @started_at
44
+ end
45
+ end
46
+
37
47
  def percent_complete
38
48
  if @size_total.to_i > 0
39
49
  (100.0 * @size_processed / @size_total).round(1)
@@ -68,6 +78,7 @@ module Britebox
68
78
  # Block processing if some another FileJob processing lines
69
79
  @queue.pop if @queue
70
80
 
81
+ @started_at = Time.now
71
82
  @status = 'verifying'
72
83
 
73
84
  @in_buffer = Queue.new
@@ -120,6 +131,7 @@ module Britebox
120
131
  @out_buffer.flush_backlog
121
132
  @out_buffer.close
122
133
 
134
+ @processed_at = Time.now
123
135
  @status = 'complete'
124
136
 
125
137
  # Release the lock
@@ -173,7 +185,7 @@ module Britebox
173
185
  end
174
186
 
175
187
  # Single column file
176
- if @col_separator.nil? && test_lines.first.size == 1 && is_separator?(' ', test_lines)
188
+ if @col_separator.nil? && test_lines.first.size == 1 && !is_separator?(' ', test_lines)
177
189
  @col_separator = ','
178
190
  end
179
191
 
@@ -6,7 +6,7 @@ module Britebox
6
6
  attr_reader :file_jobs
7
7
 
8
8
  SPINNERS = ["|", "/", "—", "\\"]
9
- THREAD_NUM_DEFAULT = 8
9
+ THREAD_NUM_DEFAULT = 10
10
10
 
11
11
  def initialize(num_threads = nil)
12
12
  num_threads ||= THREAD_NUM_DEFAULT
@@ -84,6 +84,13 @@ module Britebox
84
84
  status_str = "#{fj.percent_complete} %".rjust(7)
85
85
  end
86
86
 
87
+ if fj.status != 'error'
88
+ status_str += ' | '
89
+ if fj.duration
90
+ status_str += Time.at(fj.duration.ceil).gmtime.strftime('%R:%S').gsub(/\A00:/,'').rjust(8)
91
+ end
92
+ end
93
+
87
94
  buffer << "\n#{fname.ljust(20)} | #{fj.status.to_s.ljust(9)} | #{human_size(fj.size_total).rjust(8)} | #{status_str}"
88
95
  end
89
96
 
@@ -1,3 +1,3 @@
1
1
  module Britebox
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: britebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shapiotko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-12 00:00:00.000000000 Z
12
+ date: 2013-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: brite-api
@@ -58,7 +58,8 @@ files:
58
58
  - LICENSE
59
59
  - bin/britebox
60
60
  homepage: https://github.com/thousandsofthem/britebox
61
- licenses: []
61
+ licenses:
62
+ - MIT
62
63
  metadata: {}
63
64
  post_install_message:
64
65
  rdoc_options: []
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  version: 1.3.6
77
78
  requirements: []
78
79
  rubyforge_project:
79
- rubygems_version: 2.0.0
80
+ rubygems_version: 2.0.5
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: BriteVerify API CLI tool