update_repo 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/update_repo/console_output.rb +1 -1
- data/lib/update_repo/helpers.rb +4 -0
- data/lib/update_repo/metrics.rb +53 -0
- data/lib/update_repo/version.rb +1 -1
- data/lib/update_repo.rb +11 -17
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f4b96ca5d15f8eb980a80f3017430ae9a0baed7
|
4
|
+
data.tar.gz: 34dfed03a84b45affc5736f09e425be50747830b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8e063b9a01c9c4ae0dbb68f086ed25fb85c9bb3edc1da8a2fd9e78370b27affd12db1fe86f41f68ee3366e409addfb7fe648e7b78fc375bde081bbd7fb9245
|
7
|
+
data.tar.gz: ed02a5370ada39e6f02d19018db770416f0f4bf85ef386c4c275cd910cb43393eec4d9008a3866cbc8b723fc28fb6117ad2db041c18a2bca7b887c8bc5fd9b16
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ module UpdateRepo
|
|
9
9
|
|
10
10
|
# Constructor for the ConsoleOutput class.
|
11
11
|
# @param logger [class] Pointer to the Logger class
|
12
|
-
# @param metrics [
|
12
|
+
# @param metrics [class] Pointer to the Metrics class
|
13
13
|
# @param config [class] Pointer to the Confoog class
|
14
14
|
# @return [void]
|
15
15
|
# @example
|
data/lib/update_repo/helpers.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'update_repo/version'
|
2
|
+
require 'update_repo/helpers'
|
3
|
+
|
4
|
+
module UpdateRepo
|
5
|
+
# Class : Metrics.
|
6
|
+
# This class takes care of storing the metrics for processed, failures, etc.
|
7
|
+
class Metrics
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
# Constructor for the Metrics class.
|
11
|
+
# @param logger [instance] Pointer to the Logger class
|
12
|
+
# @return [instance] Instance of the Metrics class
|
13
|
+
def initialize(logger)
|
14
|
+
@log = logger
|
15
|
+
@metrics = { processed: 0, skipped: 0, failed: 0, updated: 0,
|
16
|
+
start_time: 0, failed_list: [] }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Read the metric 'key'
|
20
|
+
# @param key [symbol] the key to read
|
21
|
+
# @return [various] Return the value for hash key 'key'
|
22
|
+
def [](key)
|
23
|
+
@metrics[key]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the metric 'key' to 'value'
|
27
|
+
# @param key [symbol] the key to set
|
28
|
+
# @param value [symbol] set 'key' to this value.
|
29
|
+
# @return [value] Return the value set.
|
30
|
+
def []=(key, value)
|
31
|
+
@metrics[key] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# output an error line and update the metrics
|
35
|
+
# @param line [string] The string containing the error message
|
36
|
+
# @return [void]
|
37
|
+
def handle_err(line)
|
38
|
+
return unless line =~ /^fatal:|^error:/
|
39
|
+
print_log ' ', line.red
|
40
|
+
@metrics[:failed] += 1
|
41
|
+
err_loc = Dir.pwd + " (#{repo_url})"
|
42
|
+
@metrics[:failed_list].push(loc: err_loc, line: line)
|
43
|
+
end
|
44
|
+
|
45
|
+
# print a git output line and update the metrics if an update has occurred
|
46
|
+
# @param line [string] The string containing the git output line
|
47
|
+
# @return [void]
|
48
|
+
def handle_output(line)
|
49
|
+
print_log ' ', line.cyan
|
50
|
+
@metrics[:updated] += 1 if line =~ %r{^From\s(?:https?|git)://}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/update_repo/version.rb
CHANGED
data/lib/update_repo.rb
CHANGED
@@ -3,6 +3,7 @@ require 'update_repo/helpers'
|
|
3
3
|
require 'update_repo/cmd_config'
|
4
4
|
require 'update_repo/logger'
|
5
5
|
require 'update_repo/console_output'
|
6
|
+
require 'update_repo/metrics'
|
6
7
|
require 'yaml'
|
7
8
|
require 'colorize'
|
8
9
|
require 'confoog'
|
@@ -22,12 +23,12 @@ module UpdateRepo
|
|
22
23
|
# Class constructor. No parameters required.
|
23
24
|
# @return [void]
|
24
25
|
def initialize
|
25
|
-
@metrics = { processed: 0, skipped: 0, failed: 0, updated: 0,
|
26
|
-
start_time: 0, failed_list: [] }
|
27
26
|
# create a new instance of the CmdConfig class then read the config var
|
28
27
|
@cmd = CmdConfig.new
|
29
|
-
# set up the
|
28
|
+
# set up the output and logging class
|
30
29
|
@log = Logger.new(cmd(:log), cmd(:timestamp))
|
30
|
+
# create instance of the Metrics class
|
31
|
+
@metrics = Metrics.new(@log)
|
31
32
|
# instantiate the console output class for header, footer etc
|
32
33
|
@cons = ConsoleOutput.new(@log, @metrics, @cmd)
|
33
34
|
end
|
@@ -127,11 +128,11 @@ module UpdateRepo
|
|
127
128
|
# @param none
|
128
129
|
# @return [void]
|
129
130
|
def do_update
|
130
|
-
repo_url = `git config remote.origin.url`.chomp
|
131
|
+
# repo_url = `git config remote.origin.url`.chomp
|
131
132
|
print_log '* Checking ', Dir.pwd.green, " (#{repo_url})\n"
|
132
133
|
Open3.popen3('git pull') do |stdin, stdout, stderr, thread|
|
133
134
|
stdin.close
|
134
|
-
do_threads(stdout, stderr
|
135
|
+
do_threads(stdout, stderr)
|
135
136
|
thread.join
|
136
137
|
end
|
137
138
|
end
|
@@ -142,19 +143,12 @@ module UpdateRepo
|
|
142
143
|
# @param stderr [stream] STDERR Stream from the popen3 call
|
143
144
|
# @param repo_url [string] URL of the associated repository
|
144
145
|
# @return [void]
|
145
|
-
def do_threads(stdout, stderr
|
146
|
+
def do_threads(stdout, stderr)
|
146
147
|
{ out: stdout, err: stderr }.each do |key, stream|
|
147
148
|
Thread.new do
|
148
149
|
while (line = stream.gets)
|
149
|
-
if key == :err
|
150
|
-
|
151
|
-
@metrics[:failed] += 1
|
152
|
-
err_loc = Dir.pwd + " (#{repo_url})"
|
153
|
-
@metrics[:failed_list].push(loc: err_loc, line: line)
|
154
|
-
else
|
155
|
-
print_log ' ', line.cyan
|
156
|
-
@metrics[:updated] += 1 if line =~ %r{^From\s(?:https?|git)://}
|
157
|
-
end
|
150
|
+
@metrics.handle_err(line) if key == :err
|
151
|
+
@metrics.handle_output(line) if key == :out
|
158
152
|
end
|
159
153
|
end
|
160
154
|
end
|
@@ -166,9 +160,9 @@ module UpdateRepo
|
|
166
160
|
# @return [void]
|
167
161
|
def dump_repo(dir)
|
168
162
|
Dir.chdir(dir.chomp!('/')) do
|
169
|
-
repo_url = `git config remote.origin.url`.chomp
|
163
|
+
# repo_url = `git config remote.origin.url`.chomp
|
170
164
|
print_log "#{trunc_dir(dir, config['cmd'][:prune])}," if cmd(:dump)
|
171
|
-
print_log "#{
|
165
|
+
print_log "#{get_repo_url}\n"
|
172
166
|
end
|
173
167
|
end
|
174
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: update_repo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Ramsay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -289,6 +289,7 @@ files:
|
|
289
289
|
- lib/update_repo/console_output.rb
|
290
290
|
- lib/update_repo/helpers.rb
|
291
291
|
- lib/update_repo/logger.rb
|
292
|
+
- lib/update_repo/metrics.rb
|
292
293
|
- lib/update_repo/version.rb
|
293
294
|
- update_repo.gemspec
|
294
295
|
homepage: http://updaterepo.seapagan.net
|