update_repo 0.8.2 → 0.8.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 +4 -4
- data/README.md +1 -1
- data/lib/update_repo.rb +7 -93
- data/lib/update_repo/cmd_config.rb +0 -4
- data/lib/update_repo/console_output.rb +101 -0
- data/lib/update_repo/helpers.rb +7 -11
- data/lib/update_repo/logger.rb +57 -0
- data/lib/update_repo/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3535241ed1c52eb02d217ed8527c1b157b2eef
|
4
|
+
data.tar.gz: 63024bbfebe62bb05f82bb328a1ba6c0e127fda1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c29335e5df44c273e7666a36e03a79d4c9b02490f0c3cd715d089a63e9d1a428e53dd88aee4296ae39f379c1f7c81aa24a17884373f2ec5e5539f22eb45ca95
|
7
|
+
data.tar.gz: eed327dfa5518532b4f01c0e757e5570b8584ecbc9377436e128804eec981a73c02f3960a88effbfd55a8c573e7d0be794f2361cf71f4ad30f4d1aecf68fa594
|
data/README.md
CHANGED
data/lib/update_repo.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'update_repo/version'
|
2
2
|
require 'update_repo/helpers'
|
3
3
|
require 'update_repo/cmd_config'
|
4
|
+
require 'update_repo/logger'
|
5
|
+
require 'update_repo/console_output'
|
4
6
|
require 'yaml'
|
5
7
|
require 'colorize'
|
6
8
|
require 'confoog'
|
@@ -15,7 +17,6 @@ module UpdateRepo
|
|
15
17
|
|
16
18
|
# An encapsulated class to walk the repo directories and update all Git
|
17
19
|
# repositories found therein.
|
18
|
-
# rubocop:disable Metrics/ClassLength
|
19
20
|
class WalkRepo
|
20
21
|
include Helpers
|
21
22
|
# Class constructor. No parameters required.
|
@@ -23,12 +24,12 @@ module UpdateRepo
|
|
23
24
|
def initialize
|
24
25
|
@metrics = { processed: 0, skipped: 0, failed: 0, updated: 0,
|
25
26
|
start_time: 0, failed_list: [] }
|
26
|
-
@summary = { processed: 'green', updated: 'cyan', skipped: 'yellow',
|
27
|
-
failed: 'red' }
|
28
27
|
# create a new instance of the CmdConfig class then read the config var
|
29
28
|
@cmd = CmdConfig.new
|
30
29
|
# set up the logfile if needed
|
31
|
-
|
30
|
+
@log = Logger.new(cmd(:log), cmd(:timestamp))
|
31
|
+
# instantiate the console output class for header, footer etc
|
32
|
+
@cons = ConsoleOutput.new(@log, @metrics, @cmd)
|
32
33
|
end
|
33
34
|
|
34
35
|
# This function will perform the required actions to traverse the Repo.
|
@@ -37,15 +38,13 @@ module UpdateRepo
|
|
37
38
|
# walk_repo.start
|
38
39
|
def start
|
39
40
|
String.disable_colorization = !cmd(:color)
|
40
|
-
# make sure we dont have bad cmd-line parameter combinations ...
|
41
|
-
@cmd.check_params # TODO - check this since is already called in @cmd.init
|
42
41
|
# print out our header unless we are dumping / importing ...
|
43
|
-
show_header unless dumping?
|
42
|
+
@cons.show_header unless dumping?
|
44
43
|
config['location'].each do |loc|
|
45
44
|
cmd(:dump_tree) ? dump_tree(File.join(loc)) : recurse_dir(loc)
|
46
45
|
end
|
47
46
|
# print out an informative footer unless dump / import ...
|
48
|
-
|
47
|
+
@cons.show_footer unless dumping?
|
49
48
|
end
|
50
49
|
|
51
50
|
private
|
@@ -72,20 +71,6 @@ module UpdateRepo
|
|
72
71
|
@cmd.true_cmd(command.to_sym)
|
73
72
|
end
|
74
73
|
|
75
|
-
# Set up the log file - determine if we need to timestamp the filename and
|
76
|
-
# then actually open it and set to sync.
|
77
|
-
# @param [none]
|
78
|
-
# @return [void]
|
79
|
-
def setup_logfile
|
80
|
-
filename = if cmd(:timestamp)
|
81
|
-
'updaterepo-' + Time.new.strftime('%y%m%d-%H%M%S') + '.log'
|
82
|
-
else
|
83
|
-
'updaterepo.log'
|
84
|
-
end
|
85
|
-
@logfile = File.open(filename, 'w')
|
86
|
-
@logfile.sync = true
|
87
|
-
end
|
88
|
-
|
89
74
|
# take each directory contained in the Repo directory, if it is detected as
|
90
75
|
# a Git repository then update it (or as directed by command line)
|
91
76
|
# @param dirname [string] Contains the directory to search for Git repos.]
|
@@ -110,77 +95,6 @@ module UpdateRepo
|
|
110
95
|
!config['exceptions'].include?(File.basename(dir))
|
111
96
|
end
|
112
97
|
|
113
|
-
# Display a simple header to the console
|
114
|
-
# @example
|
115
|
-
# show_header
|
116
|
-
# @return [void]
|
117
|
-
# @param [none]
|
118
|
-
def show_header
|
119
|
-
# print an informative header before starting
|
120
|
-
print_log "\nGit Repo update utility (v", VERSION, ')',
|
121
|
-
" \u00A9 Grant Ramsay <seapagan@gmail.com>\n"
|
122
|
-
print_log "Using Configuration from '#{config.config_path}'\n"
|
123
|
-
# print_log "Command line is : #{config['cmd']}\n"
|
124
|
-
# list out the locations that will be searched
|
125
|
-
list_locations
|
126
|
-
# list any exceptions that we have from the config file
|
127
|
-
list_exceptions
|
128
|
-
# save the start time for later display in the footer...
|
129
|
-
@metrics[:start_time] = Time.now
|
130
|
-
print_log "\n" # blank line before processing starts
|
131
|
-
end
|
132
|
-
|
133
|
-
# print out a brief footer. This will be expanded later.
|
134
|
-
# @return [void]
|
135
|
-
# @param [none]
|
136
|
-
def footer
|
137
|
-
duration = Time.now - @metrics[:start_time]
|
138
|
-
print_log "\nUpdates completed in ", show_time(duration).cyan
|
139
|
-
print_metrics
|
140
|
-
print_log " \n\n"
|
141
|
-
# close the log file now as we are done, just to be sure ...
|
142
|
-
@logfile.close if @logfile
|
143
|
-
end
|
144
|
-
|
145
|
-
# Print end-of-run metrics to console / log
|
146
|
-
# @return [void]
|
147
|
-
# @param [none]
|
148
|
-
def print_metrics
|
149
|
-
@summary.each do |metric, color|
|
150
|
-
metric_value = @metrics[metric]
|
151
|
-
output = "#{metric_value} #{metric.capitalize}"
|
152
|
-
print_log ' | ', output.send(color.to_sym) unless metric_value.zero?
|
153
|
-
end
|
154
|
-
print_log ' |'
|
155
|
-
return if @metrics[:failed_list].empty?
|
156
|
-
print_log "\n\n!! Note : The following repositories ",
|
157
|
-
'FAILED'.red.underline, ' during this run :'
|
158
|
-
@metrics[:failed_list].each do |failed|
|
159
|
-
print_log "\n [", 'x'.red, "] #{failed[:loc]}"
|
160
|
-
print_log "\n -> ", "\"#{failed[:line].chomp}\"".red
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Print a list of any defined expections that will not be updated.
|
165
|
-
# @return [void]
|
166
|
-
# @param [none]
|
167
|
-
def list_exceptions
|
168
|
-
exceptions = config['exceptions']
|
169
|
-
return unless exceptions
|
170
|
-
print_log "\nExclusions:".underline, ' ',
|
171
|
-
exceptions.join(', ').yellow, "\n"
|
172
|
-
end
|
173
|
-
|
174
|
-
# Print a list of all top-level directories that will be searched and any
|
175
|
-
# Git repos contained within updated.
|
176
|
-
# @return [void]
|
177
|
-
def list_locations
|
178
|
-
print_log "\nRepo location(s):\n".underline
|
179
|
-
config['location'].each do |loc|
|
180
|
-
print_log '-> ', loc.cyan, "\n"
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
98
|
# Takes the specified Repo and does not update it, outputing a note to the
|
185
99
|
# console / log to this effect.
|
186
100
|
# @param dirpath [string] The directory with Git repository to be skipped
|
@@ -60,12 +60,8 @@ module UpdateRepo
|
|
60
60
|
# @return [void]
|
61
61
|
def check_params
|
62
62
|
return unless true_cmd(:dump)
|
63
|
-
# if true_cmd(:import)
|
64
63
|
Trollop.die 'You cannot use --dump AND --import'.red if true_cmd(:import)
|
65
|
-
# end
|
66
|
-
# if true_cmd(:dump_remote)
|
67
64
|
Trollop.die 'You cannot use --dump AND --dump-remote'.red if true_cmd(:dump_remote)
|
68
|
-
# end
|
69
65
|
end
|
70
66
|
# rubocop:enable Metrics/LineLength
|
71
67
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'update_repo/version'
|
2
|
+
require 'update_repo/helpers'
|
3
|
+
|
4
|
+
module UpdateRepo
|
5
|
+
# Class : ConsoleOutput.
|
6
|
+
# This class has functions to print header, footer and metrics.
|
7
|
+
class ConsoleOutput
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
# Constructor for the ConsoleOutput class.
|
11
|
+
# @param logger [class] Pointer to the Logger class
|
12
|
+
# @param metrics [hash] Hash of metrics and their values
|
13
|
+
# @param config [class] Pointer to the Confoog class
|
14
|
+
# @return [void]
|
15
|
+
# @example
|
16
|
+
# console = ConsoleOutput.new(@log)
|
17
|
+
def initialize(logger, metrics, config)
|
18
|
+
@summary = { processed: 'green', updated: 'cyan', skipped: 'yellow',
|
19
|
+
failed: 'red' }
|
20
|
+
@metrics = metrics
|
21
|
+
@log = logger
|
22
|
+
@config = config.getconfig
|
23
|
+
end
|
24
|
+
|
25
|
+
# Display a simple header to the console
|
26
|
+
# @example
|
27
|
+
# show_header
|
28
|
+
# @return [void]
|
29
|
+
# @param [none]
|
30
|
+
def show_header
|
31
|
+
# print an informative header before starting
|
32
|
+
print_log "\nGit Repo update utility (v", VERSION, ')',
|
33
|
+
" \u00A9 Grant Ramsay <seapagan@gmail.com>\n"
|
34
|
+
print_log "Using Configuration from '#{@config.config_path}'\n"
|
35
|
+
# list out the locations that will be searched
|
36
|
+
list_locations
|
37
|
+
# list any exceptions that we have from the config file
|
38
|
+
list_exceptions
|
39
|
+
# save the start time for later display in the footer...
|
40
|
+
@metrics[:start_time] = Time.now
|
41
|
+
print_log "\n" # blank line before processing starts
|
42
|
+
end
|
43
|
+
|
44
|
+
# print out a brief footer. This will be expanded later.
|
45
|
+
# @return [void]
|
46
|
+
# @param [none]
|
47
|
+
def show_footer
|
48
|
+
duration = Time.now - @metrics[:start_time]
|
49
|
+
print_log "\nUpdates completed in ", show_time(duration).cyan
|
50
|
+
print_metrics
|
51
|
+
print_log " \n\n"
|
52
|
+
# close the log file now as we are done, just to be sure ...
|
53
|
+
@log.close
|
54
|
+
end
|
55
|
+
|
56
|
+
# Print end-of-run metrics to console / log
|
57
|
+
# @return [void]
|
58
|
+
# @param [none]
|
59
|
+
def print_metrics
|
60
|
+
@summary.each do |metric, color|
|
61
|
+
metric_value = @metrics[metric]
|
62
|
+
output = "#{metric_value} #{metric.capitalize}"
|
63
|
+
print_log ' | ', output.send(color.to_sym) unless metric_value.zero?
|
64
|
+
end
|
65
|
+
print_log ' |'
|
66
|
+
list_failures unless @metrics[:failed_list].empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
# List any repositories that failed their update, and the error.
|
70
|
+
# @param [none]
|
71
|
+
# @return [void]
|
72
|
+
def list_failures
|
73
|
+
print_log "\n\n!! Note : The following repositories ",
|
74
|
+
'FAILED'.red.underline, ' during this run :'
|
75
|
+
@metrics[:failed_list].each do |failed|
|
76
|
+
print_log "\n [", 'x'.red, "] #{failed[:loc]}"
|
77
|
+
print_log "\n -> ", "\"#{failed[:line].chomp}\"".red
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Print a list of any defined expections that will not be updated.
|
82
|
+
# @return [void]
|
83
|
+
# @param [none]
|
84
|
+
def list_exceptions
|
85
|
+
exceptions = @config['exceptions']
|
86
|
+
return unless exceptions
|
87
|
+
print_log "\nExclusions:".underline, ' ',
|
88
|
+
exceptions.join(', ').yellow, "\n"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Print a list of all top-level directories that will be searched and any
|
92
|
+
# Git repos contained within updated.
|
93
|
+
# @return [void]
|
94
|
+
def list_locations
|
95
|
+
print_log "\nRepo location(s):\n".underline
|
96
|
+
@config['location'].each do |loc|
|
97
|
+
print_log '-> ', loc.cyan, "\n"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/update_repo/helpers.rb
CHANGED
@@ -14,17 +14,6 @@ module Helpers
|
|
14
14
|
File.join(path_array)
|
15
15
|
end
|
16
16
|
|
17
|
-
# this function will simply pass the given string to 'print', and also
|
18
|
-
# log to file if that is specified.
|
19
|
-
# @param string [array] Array of strings for print formatting
|
20
|
-
# @return [void]
|
21
|
-
def print_log(*string)
|
22
|
-
# log to screen regardless
|
23
|
-
print(*string)
|
24
|
-
# log to file if that has been enabled
|
25
|
-
@logfile.write(string.join('').gsub(/\e\[(\d+)(;\d+)*m/, '')) if cmd('log')
|
26
|
-
end
|
27
|
-
|
28
17
|
# mark these as private simply so that 'reek' wont flag as utility function.
|
29
18
|
private
|
30
19
|
|
@@ -37,4 +26,11 @@ module Helpers
|
|
37
26
|
time_taken = Time.at(duration).utc
|
38
27
|
time_taken.strftime('%-H hours, %-M Minutes and %-S seconds')
|
39
28
|
end
|
29
|
+
|
30
|
+
# helper function to call the Logger class output method.
|
31
|
+
# @param *string [Array] Array of strings to be passed to the 'print' fn
|
32
|
+
# @return [*string] Output of the Logger
|
33
|
+
def print_log(*string)
|
34
|
+
@log.output(*string)
|
35
|
+
end
|
40
36
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'update_repo/version'
|
2
|
+
require 'update_repo/helpers'
|
3
|
+
|
4
|
+
module UpdateRepo
|
5
|
+
# Class : Logger.
|
6
|
+
# This class encapsulates printing to screen and logging to file if requried.
|
7
|
+
class Logger
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
# Constructor for the Logger class.
|
11
|
+
# @param enabled [boolean] True if we log to file
|
12
|
+
# @param timestamp [boolean] True if we timestamp the filename
|
13
|
+
# @return [void]
|
14
|
+
# @example
|
15
|
+
# log = Logger.new(true, false)
|
16
|
+
def initialize(enabled, timestamp)
|
17
|
+
@settings = { enabled: enabled, timestamp: timestamp }
|
18
|
+
# don't prepare a logfile unless it's been requested.
|
19
|
+
return unless @settings[:enabled]
|
20
|
+
# generate a filename depending on 'timestamp' setting.
|
21
|
+
filename = generate_filename
|
22
|
+
# open the logfile and set sync mode.
|
23
|
+
@logfile = File.open(filename, 'w')
|
24
|
+
@logfile.sync = true
|
25
|
+
end
|
26
|
+
|
27
|
+
# generate a filename for the log, with or without a timestamp
|
28
|
+
# @param [none]
|
29
|
+
# @return [string] Filename for the logfile.
|
30
|
+
def generate_filename
|
31
|
+
if @settings[:timestamp]
|
32
|
+
'updaterepo-' + Time.new.strftime('%y%m%d-%H%M%S') + '.log'
|
33
|
+
else
|
34
|
+
'updaterepo.log'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# this function will simply pass the given string to 'print', and also
|
39
|
+
# log to file if that is specified.
|
40
|
+
# @param string [array] Array of strings for print formatting
|
41
|
+
# @return [void]
|
42
|
+
def output(*string)
|
43
|
+
# log to screen regardless
|
44
|
+
print(*string)
|
45
|
+
# log to file if that has been enabled
|
46
|
+
return unless @settings[:enabled]
|
47
|
+
@logfile.write(string.join('').gsub(/\e\[(\d+)(;\d+)*m/, ''))
|
48
|
+
end
|
49
|
+
|
50
|
+
# close the logfile, if it exists
|
51
|
+
# @param [none]
|
52
|
+
# @return [void]
|
53
|
+
def close
|
54
|
+
@logfile.close if @logfile
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/update_repo/version.rb
CHANGED
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.3
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -286,7 +286,9 @@ files:
|
|
286
286
|
- exe/update_repo
|
287
287
|
- lib/update_repo.rb
|
288
288
|
- lib/update_repo/cmd_config.rb
|
289
|
+
- lib/update_repo/console_output.rb
|
289
290
|
- lib/update_repo/helpers.rb
|
291
|
+
- lib/update_repo/logger.rb
|
290
292
|
- lib/update_repo/version.rb
|
291
293
|
- update_repo.gemspec
|
292
294
|
homepage: http://updaterepo.seapagan.net
|