git_miner 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: bd21fc17951e069e786be9eed380d7d459e62aae10e54b252cb8fe0150652ca8
4
- data.tar.gz: c7ebdce6a7230d14bafb1a325eecea4671337cd04f9412708fc4dbc3fcb233f4
3
+ metadata.gz: 12c481503abcbd3c633ab3ed3712a97b1b2d88388c7db2daf1473aab5dd9d886
4
+ data.tar.gz: 8a013d2c312f323b61e322d756884c4b7d4da2235ccdc5f55d0a87293a479952
5
5
  SHA512:
6
- metadata.gz: 703fa603e4218a04c97b90f8e2366ddada4be11080168922f482ab6658695178e010708c249b7d1e02d3a8c5f96c5e0128d07246bfb25165c3b6c0633a7fac17
7
- data.tar.gz: e805cfb6aa93d88be8eb69b252433bb5b1df7dc563d24ee009a4837f5253bb9d882466be08ae7a2fe368523f9a6cc31e7d714698b7c12c611ee854070f301d8b
6
+ metadata.gz: 268ad9f06a85504d18bea84347e08b315e2c34f1d88ab4d8b2cd268accc3544a1ff36ec8afe17f4344dddc60d8b2aa6201230d4144511f873a2297da9a3be654
7
+ data.tar.gz: 1439261df54c6c8235c8a6b47fd4dff175c962803083bf2ff02e711e6d405cb161a459113754a9cf0582cdbe8aaae1cf3052c838b838bca8f60bec3b1899435f
@@ -12,7 +12,7 @@ options = {
12
12
  dispatch: :parallel,
13
13
  }
14
14
 
15
- OptionParser.new do |opts|
15
+ parser = OptionParser.new do |opts|
16
16
  opts.banner = "Usage: example.rb [options]"
17
17
 
18
18
  opts.on("--engine [ruby|c]", [:ruby, :c], "Set the engine (default: ruby)") do |x|
@@ -23,17 +23,32 @@ OptionParser.new do |opts|
23
23
  options[:dispatch] = x
24
24
  end
25
25
 
26
+ opts.on("-v", "--[no-]verbose", "Run verbosely (default: false)") do |v|
27
+ options[:verbose] = v
28
+ end
29
+
30
+ opts.on_tail("--version", "Returns the current version") do |v|
31
+ puts "GitMiner #{GitMiner::VERSION}"
32
+ exit
33
+ end
34
+
26
35
  opts.on_tail("-h", "--help", "Show this message") do
27
36
  puts opts
28
37
  exit
29
38
  end
30
- end.parse!
39
+ end
40
+
41
+ parser.parse!
31
42
 
32
43
  unless ARGV.size == 1
33
- puts opts
44
+ puts parser
34
45
  exit 1
35
46
  end
36
47
 
48
+ GitMiner.logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
49
+
50
+ GitMiner.logger.debug("OptionParser: #{options.inspect}")
51
+
37
52
  prefix = ARGV.first
38
53
 
39
54
  engine = case(options[:engine])
@@ -5,4 +5,12 @@ end
5
5
 
6
6
  module GitMiner
7
7
  class Error < StandardError; end
8
+
9
+ def self.logger
10
+ @logger ||= Logger.new(STDOUT)
11
+ end
12
+
13
+ def self.logger=(logger)
14
+ @logger = logger
15
+ end
8
16
  end
@@ -1,7 +1,7 @@
1
1
  module GitMiner
2
2
  class Core
3
3
  def initialize(engine:, dispatch:, prefix:)
4
- puts "Initializing with engine '#{engine}'. dispatch '#{dispatch}' and prefix '#{prefix}'"
4
+ GitMiner.logger.debug("Initializing with engine '#{engine}'. dispatch '#{dispatch}' and prefix '#{prefix}'")
5
5
 
6
6
  @prefix = prefix
7
7
 
@@ -38,11 +38,11 @@ module GitMiner
38
38
  raise "Invalid prefix, expected '^[0-9a-f]{1,32}$'"
39
39
  end
40
40
 
41
- puts "Validations: Successful"
41
+ GitMiner.logger.debug("Validations: Successful")
42
42
  end
43
43
 
44
44
  def mine
45
- puts "Mining for sha"
45
+ GitMiner.logger.info("Mining for SHA: #{@prefix}")
46
46
 
47
47
  @mining_result = @dispatch.execute
48
48
  end
@@ -50,10 +50,11 @@ module GitMiner
50
50
  def report
51
51
  raise "Prerequisite: Require mining to be completed first" unless @mining_result
52
52
 
53
- puts "Mining results:"
54
- puts "- New sha: #{@mining_result.sha}"
55
- puts "- Author offset: #{@mining_result.author_offset}"
56
- puts "- Committer offset: #{@mining_result.committer_offset}"
53
+ GitMiner.logger.debug("Mining completed.")
54
+ GitMiner.logger.debug("Author offset: #{@mining_result.author_offset}")
55
+ GitMiner.logger.debug("Committer offset: #{@mining_result.committer_offset}")
56
+
57
+ GitMiner.logger.info("New SHA: #{@mining_result.sha}")
57
58
  end
58
59
 
59
60
  def alter
@@ -34,9 +34,9 @@ module GitMiner
34
34
  private
35
35
 
36
36
  def shell(cmd, environment: {}, stdin_data: nil)
37
- puts "System call: #{cmd}"
38
- puts "environment: #{environment.inspect}" unless environment.empty?
39
- puts "stdin_data: #{stdin_data}" if stdin_data
37
+ GitMiner.logger.debug("System call: #{cmd}")
38
+ GitMiner.logger.debug("environment: #{environment.inspect}") unless environment.empty?
39
+ GitMiner.logger.debug("stdin_data: #{stdin_data}") if stdin_data
40
40
 
41
41
  output, status = Open3.capture2(environment, cmd, stdin_data: stdin_data) #, chdir: @working_directory
42
42
 
@@ -44,7 +44,7 @@ module GitMiner
44
44
  raise "Error on system call: #{output}, #{status}"
45
45
  end
46
46
 
47
- puts "result: #{output}"
47
+ GitMiner.logger.debug("result: #{output.strip}")
48
48
 
49
49
  output
50
50
  end
@@ -31,19 +31,19 @@ module GitMiner
31
31
  info = []
32
32
 
33
33
  percentage = count * 100 / @combinations.to_f
34
- info << "#{percentage.round(2)}%"
34
+ info << "#{'%.2f' % percentage}%"
35
35
 
36
36
  historic_count = @historic.last[:count] - @historic.first[:count]
37
37
  historic_delay = @historic.last[:timestamp] - @historic.first[:timestamp]
38
38
  if historic_delay > 0
39
39
  per_sec = historic_count / historic_delay
40
- info << "hash: #{per_sec.round(2)}/s"
40
+ info << "hash: #{'%.2f' % per_sec}/s"
41
41
 
42
42
  per_sec = (@historic.last[:batch] - @historic.first[:batch]) / historic_delay
43
- info << "batches: #{per_sec.round(2)}/s"
43
+ info << "batches: #{'%.2f' % per_sec}/s"
44
44
  end
45
45
 
46
- puts info.join(', ')
46
+ GitMiner.logger.info(info.join(', '))
47
47
  end
48
48
  end
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module GitMiner
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_miner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thierry Joyal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel