update_repo 0.9.2 → 0.9.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/.travis.yml +4 -3
- data/README.md +21 -18
- data/lib/update_repo/cmd_config.rb +15 -0
- data/lib/update_repo/console_output.rb +15 -6
- data/lib/update_repo/logger.rb +18 -16
- data/lib/update_repo/version.rb +1 -1
- data/lib/update_repo.rb +5 -19
- data/update_repo.gemspec +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83505a5c407a8a9b4b1d83270037dd9bea6bad1b
|
4
|
+
data.tar.gz: 367640e56d880c7aa011fb499748d4544c96c1fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a22861bff02f7e0ef0dfa0920256f506d33a951448a988cb4ef0e05f4ff6babfb57125225eb0c1d117fa879aa428ea6d5354d8ab539bb218af77bc4f346ba883
|
7
|
+
data.tar.gz: c341cd60fd33e4692b948309caadd7d44b0a1866b2c4ea3764891c1a3b38235aa08d7255bbfd96c1e36bbe36a9bafc13078b7601d08f40770292fc96097da9e8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -17,10 +17,7 @@ __Note:__ From version 0.9.0 onwards, the default mode of operation is non-verbo
|
|
17
17
|
|
18
18
|
#### Pre-requirements
|
19
19
|
|
20
|
-
It goes without saying that at the very least a working copy of both [`Git`][git] (version 1.8.5 or greater, the script will not run with an older version) and [`Ruby`][ruby] need to be installed on your machine. Also, the script has currently only been tested under Linux, not windows.
|
21
|
-
|
22
|
-
[git]: http://git-scm.com
|
23
|
-
[ruby]: http://www.ruby-lang.org
|
20
|
+
It goes without saying that at the very least a working copy of both [`Git`][git] (version 1.8.5 or greater, the script will not run with an older version) and [`Ruby`][ruby] (version 1.9.3 and newer) need to be installed on your machine. Also, the script has currently only been tested under Linux, not windows.
|
24
21
|
|
25
22
|
Install this from the shell prompt as you would any other Ruby Gem
|
26
23
|
|
@@ -31,14 +28,14 @@ $ gem install update_repo
|
|
31
28
|
## Usage
|
32
29
|
|
33
30
|
#### Quick start
|
34
|
-
Create a [YAML]
|
31
|
+
Create a [YAML][yaml]-formatted configuration file `.updaterepo` **in your home directory** that contains at least a 'location' tag pointing to the directory containing the git repositories you wish to have updated :
|
35
32
|
```yaml
|
36
33
|
---
|
37
34
|
location:
|
38
35
|
- /media/myuser/git-repos
|
39
36
|
- /data/RepoDir
|
40
37
|
```
|
41
|
-
This is the most basic example of a configuration file and there are other options that can be added to fine-tune the operation - see the description of configuration options below and the [Website]
|
38
|
+
This is the most basic example of a configuration file and there are other options that can be added to fine-tune the operation - see the description of configuration options below and the [Website][website] for more information.
|
42
39
|
|
43
40
|
This file should be located in the users home directory (`~/.updaterepo`).
|
44
41
|
|
@@ -48,9 +45,9 @@ $ update_repo
|
|
48
45
|
```
|
49
46
|
|
50
47
|
## Configuration
|
51
|
-
The below is a summary of the most common configuration options, see the [Website]
|
48
|
+
The below is a summary of the most common configuration options, see the [Website][website] for complete details and usage.
|
52
49
|
#### Configuration file
|
53
|
-
The configuration file defaults to `~/.updaterepo` and is a standard [YAML]
|
50
|
+
The configuration file defaults to `~/.updaterepo` and is a standard [YAML][yaml]-formatted text file. If this configuration file is not found, the script will terminate with an error.
|
54
51
|
The first line must contain the YAML frontmatter of 3 dashes (`---`). After that, the following sections can follow in any order. Only the `location:` section is compulsory, and that must contain at least one entry.
|
55
52
|
|
56
53
|
`location:` - at least one directory which contains the locally cloned repository(s) to update. There is no limit on how many directories can be listed :
|
@@ -89,7 +86,7 @@ quiet: true
|
|
89
86
|
```
|
90
87
|
|
91
88
|
#### Command line switches
|
92
|
-
Options are not required. If none are specified then the program will read from the standard configuration file (~/.updaterepo) and automatically update the specified Repositories. Command line options will take preference over those specified in the configuration file.
|
89
|
+
Options are not required. If none are specified then the program will read from the standard configuration file (~/.updaterepo) and automatically update the specified Repositories. Command line options will take preference over those specified in the configuration file. Again, see the [Website][website] for complete details and usage.
|
93
90
|
|
94
91
|
Enter `update_repo --help` at the command prompt to get a list of available options :
|
95
92
|
```
|
@@ -123,6 +120,8 @@ Add functionality, not in any specific order :
|
|
123
120
|
* ability to export a text dump of each repo location and remote as a CSV file. `[DONE]`
|
124
121
|
* re-import the above dump on a different machine or after reinstall. Modify the '--prune' command to apply to this function also, removing the required number of directory levels before importing.
|
125
122
|
- Add option to use alternative git command if required, either globally or on a case-by-case basis (see also comments on 'variants' above). Currently the script just uses a blanket `git pull` command on all repositories.
|
123
|
+
- Implement the option `--log-local` to put log file into the local directory.
|
124
|
+
- Add option to specify a completely different directory for the log file other than the 2 current (planned, local not yet implemented) options (home dir and local)
|
126
125
|
- Document configuration file format and options. `[IN PROGRESS]`
|
127
126
|
|
128
127
|
Internal Changes and refactoring :
|
@@ -133,8 +132,6 @@ Internal Changes and refactoring :
|
|
133
132
|
* Add more failure cases, there may be more git errors than "fatal:" or "error:"
|
134
133
|
- Retry for connection issues etc (config setting).
|
135
134
|
|
136
|
-
[confoog]: http://confoog.seapagan.net
|
137
|
-
|
138
135
|
## Development
|
139
136
|
|
140
137
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests (or simply `rake`). You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -154,10 +151,6 @@ Run `rake` to run the RSpec tests, which also runs `RuboCop`, `Reek` and `inch -
|
|
154
151
|
Please note - This Gem currently aims to pass 100% on [RuboCop][rubocop], [Reek][reek] and [Inch-CI][inch] (on pedantic mode), so all pull requests should do likewise. Ask for guidance if needed.
|
155
152
|
Running `rake` will automatically test all 3 of those along with the RSpec tests.
|
156
153
|
|
157
|
-
[rubocop]: https://github.com/bbatsov/rubocop
|
158
|
-
[reek]: https://github.com/troessner/reek
|
159
|
-
[inch]: https://inch-ci.org
|
160
|
-
|
161
154
|
## Versioning
|
162
155
|
|
163
156
|
This Gem aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
|
@@ -169,9 +162,19 @@ introduced with new major versions.
|
|
169
162
|
|
170
163
|
Of course, currently we have not even reached version 1, so leave off the version requirement completely. Expect any and all of the API and interface to change!
|
171
164
|
|
165
|
+
## License
|
166
|
+
|
167
|
+
The gem is available as open source under the terms of the [MIT License][mit].
|
168
|
+
|
169
|
+
[website]: http://updaterepo.seapagan.net
|
170
|
+
[git]: http://git-scm.com
|
171
|
+
[ruby]: http://www.ruby-lang.org
|
172
|
+
[yaml]: http://yaml.org
|
173
|
+
[rubocop]: https://github.com/bbatsov/rubocop
|
174
|
+
[reek]: https://github.com/troessner/reek
|
175
|
+
[inch]: https://inch-ci.org
|
172
176
|
[semver]: http://semver.org/
|
173
177
|
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
178
|
+
[confoog]: http://confoog.seapagan.net
|
179
|
+
[mit]: http://opensource.org/licenses/MIT
|
174
180
|
|
175
|
-
## License
|
176
|
-
|
177
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -12,12 +12,18 @@ module UpdateRepo
|
|
12
12
|
class CmdConfig
|
13
13
|
include Helpers
|
14
14
|
|
15
|
+
# This constant holds the path to the config file, default to home dir.
|
16
|
+
CONFIG_PATH = '~/'.freeze
|
17
|
+
# This constant holds the filename of the config file.
|
18
|
+
CONFIG_FILE = '.updaterepo'.freeze
|
19
|
+
|
15
20
|
def initialize
|
16
21
|
# read the options from Trollop and store in temp variable.
|
17
22
|
# we do it this way around otherwise if configuration file is missing it
|
18
23
|
# gives the error messages even on '--help' and '--version'
|
19
24
|
temp_opt = set_options
|
20
25
|
@conf = Confoog::Settings.new(filename: CONFIG_FILE,
|
26
|
+
location: CONFIG_PATH,
|
21
27
|
prefix: 'update_repo',
|
22
28
|
autoload: true, autosave: false)
|
23
29
|
config_error unless @conf.status[:errors] == Status::INFO_FILE_LOADED
|
@@ -34,6 +40,15 @@ module UpdateRepo
|
|
34
40
|
@conf
|
35
41
|
end
|
36
42
|
|
43
|
+
# return the specified TRUE configuration variable, using '[]' notation
|
44
|
+
# @param key [string] Which cmd variable to return
|
45
|
+
# @return [various] The value of the specified cmd variable
|
46
|
+
# @example
|
47
|
+
# quiet = @cmd[quiet]
|
48
|
+
def [](key)
|
49
|
+
true_cmd(key.to_sym)
|
50
|
+
end
|
51
|
+
|
37
52
|
# This will return the 'true' version of a command, taking into account
|
38
53
|
# both command line (given preference) and the configuration file.
|
39
54
|
# @param command [symbol] The symbol of the defined command
|
@@ -10,16 +10,16 @@ module UpdateRepo
|
|
10
10
|
# Constructor for the ConsoleOutput class.
|
11
11
|
# @param logger [class] Pointer to the Logger class
|
12
12
|
# @param metrics [class] Pointer to the Metrics class
|
13
|
-
# @param
|
13
|
+
# @param cmd [class] Pointer to the CmdConfig class
|
14
14
|
# @return [void]
|
15
15
|
# @example
|
16
16
|
# console = ConsoleOutput.new(@log)
|
17
|
-
def initialize(logger, metrics,
|
17
|
+
def initialize(logger, metrics, cmd)
|
18
18
|
@summary = { processed: 'green', updated: 'cyan', skipped: 'yellow',
|
19
19
|
failed: 'red', unchanged: 'white' }
|
20
20
|
@metrics = metrics
|
21
21
|
@log = logger
|
22
|
-
@
|
22
|
+
@cmd = cmd
|
23
23
|
end
|
24
24
|
|
25
25
|
# Display a simple header to the console
|
@@ -31,7 +31,9 @@ module UpdateRepo
|
|
31
31
|
# print an informative header before starting
|
32
32
|
print_log "\nGit Repo update utility (v", VERSION, ')',
|
33
33
|
" \u00A9 Grant Ramsay <seapagan@gmail.com>\n"
|
34
|
-
print_log "Using Configuration from '#{@
|
34
|
+
print_log "Using Configuration from '#{@cmd.getconfig.config_path}'\n"
|
35
|
+
# show the logfile location, but only if it is enabled
|
36
|
+
show_logfile
|
35
37
|
# list out the locations that will be searched
|
36
38
|
list_locations
|
37
39
|
# list any exceptions that we have from the config file
|
@@ -93,7 +95,7 @@ module UpdateRepo
|
|
93
95
|
# @return [void]
|
94
96
|
# @param [none]
|
95
97
|
def list_exceptions
|
96
|
-
exceptions = @
|
98
|
+
exceptions = @cmd['exceptions']
|
97
99
|
return unless exceptions
|
98
100
|
print_log "\nExclusions:".underline, ' ',
|
99
101
|
exceptions.join(', ').yellow, "\n"
|
@@ -104,9 +106,16 @@ module UpdateRepo
|
|
104
106
|
# @return [void]
|
105
107
|
def list_locations
|
106
108
|
print_log "\nRepo location(s):\n".underline
|
107
|
-
@
|
109
|
+
@cmd['location'].each do |loc|
|
108
110
|
print_log '-> ', loc.cyan, "\n"
|
109
111
|
end
|
110
112
|
end
|
113
|
+
|
114
|
+
# print out the logfile name and location, if we are logging to file
|
115
|
+
# @return [void]
|
116
|
+
def show_logfile
|
117
|
+
return unless @cmd[:log]
|
118
|
+
print_log "\nLogging to file:".underline, " #{@log.logfile}\n".cyan
|
119
|
+
end
|
111
120
|
end
|
112
121
|
end
|
data/lib/update_repo/logger.rb
CHANGED
@@ -8,22 +8,18 @@ module UpdateRepo
|
|
8
8
|
include Helpers
|
9
9
|
|
10
10
|
# Constructor for the Logger class.
|
11
|
-
# @param
|
12
|
-
# @param timestamp [boolean] True if we timestamp the filename
|
13
|
-
# @param verbose [boolean] True if verbose flag is set
|
14
|
-
# @param quiet [boolean] True if quiet flag is set
|
11
|
+
# @param cmd [instance] - pointer to the CmdConfig class
|
15
12
|
# @return [void]
|
16
13
|
# @example
|
17
|
-
# log = Logger.new(
|
18
|
-
def initialize(
|
19
|
-
@
|
20
|
-
quiet: quiet }
|
14
|
+
# log = Logger.new(@cmd)
|
15
|
+
def initialize(cmd)
|
16
|
+
@cmd = cmd
|
21
17
|
@legend = { failed: { char: 'x', color: 'red' },
|
22
18
|
updated: { char: '^', color: 'green' },
|
23
19
|
unchanged: { char: '.', color: 'white' },
|
24
20
|
skipped: { char: 's', color: 'yellow' } }
|
25
21
|
# don't prepare a logfile unless it's been requested.
|
26
|
-
return unless @
|
22
|
+
return unless @cmd[:log]
|
27
23
|
# generate a filename depending on 'timestamp' setting.
|
28
24
|
filename = generate_filename
|
29
25
|
# open the logfile and set sync mode.
|
@@ -35,7 +31,7 @@ module UpdateRepo
|
|
35
31
|
# @param [none]
|
36
32
|
# @return [string] Filename for the logfile.
|
37
33
|
def generate_filename
|
38
|
-
if @
|
34
|
+
if @cmd[:timestamp]
|
39
35
|
name = 'updaterepo-' + Time.new.strftime('%y%m%d-%H%M%S') + '.log'
|
40
36
|
else
|
41
37
|
name = 'updaterepo.log'
|
@@ -49,12 +45,12 @@ module UpdateRepo
|
|
49
45
|
# @return [void]
|
50
46
|
def output(*string)
|
51
47
|
# nothing to screen if we want to be --quiet
|
52
|
-
unless @
|
48
|
+
unless @cmd[:quiet]
|
53
49
|
# log header and footer to screen regardless
|
54
|
-
print(*string) if @
|
50
|
+
print(*string) if @cmd[:verbose] || !repo_text?
|
55
51
|
end
|
56
52
|
# log to file if that has been enabled
|
57
|
-
return unless @
|
53
|
+
return unless @cmd[:log]
|
58
54
|
@logfile.write(string.join('').gsub(/\e\[(\d+)(;\d+)*m/, ''))
|
59
55
|
end
|
60
56
|
|
@@ -64,12 +60,18 @@ module UpdateRepo
|
|
64
60
|
# @return [void]
|
65
61
|
def repostat(status)
|
66
62
|
# only print if not quiet and not verbose!
|
67
|
-
return if @
|
63
|
+
return if @cmd[:quiet] || @cmd[:verbose]
|
68
64
|
@legend.each do |key, value|
|
69
65
|
print value[:char].send(value[:color].to_sym) if status[key]
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
69
|
+
# Return a string containing the logfile name and full path.
|
70
|
+
# @return [string]
|
71
|
+
def logfile
|
72
|
+
@logfile.path
|
73
|
+
end
|
74
|
+
|
73
75
|
# returns non nil if we have been called originally by one of the Repo
|
74
76
|
# update output functions.
|
75
77
|
# @param [none]
|
@@ -80,8 +82,8 @@ module UpdateRepo
|
|
80
82
|
calling_fn = caller_locations[2].label.gsub(/block in /, '')
|
81
83
|
# array with the functions we want to skip
|
82
84
|
repo_output = %w(do_update handle_output skip_repo update)
|
83
|
-
# return
|
84
|
-
|
85
|
+
# return TRUE if DOES match, FALSE otherwise.
|
86
|
+
repo_output.include?(calling_fn) ? true : false
|
85
87
|
end
|
86
88
|
|
87
89
|
# close the logfile, if it exists
|
data/lib/update_repo/version.rb
CHANGED
data/lib/update_repo.rb
CHANGED
@@ -14,9 +14,6 @@ require 'versionomy'
|
|
14
14
|
# Overall module with classes performing the functionality
|
15
15
|
# Contains Class UpdateRepo::WalkRepo
|
16
16
|
module UpdateRepo
|
17
|
-
# This constant holds the name to the config file, located in ~/
|
18
|
-
CONFIG_FILE = '.updaterepo'.freeze
|
19
|
-
|
20
17
|
# An encapsulated class to walk the repo directories and update all Git
|
21
18
|
# repositories found therein.
|
22
19
|
class WalkRepo
|
@@ -27,7 +24,7 @@ module UpdateRepo
|
|
27
24
|
# create a new instance of the CmdConfig class then read the config var
|
28
25
|
@cmd = CmdConfig.new
|
29
26
|
# set up the output and logging class
|
30
|
-
@log = Logger.new(cmd
|
27
|
+
@log = Logger.new(@cmd)
|
31
28
|
# create instance of the Metrics class
|
32
29
|
@metrics = Metrics.new(@log)
|
33
30
|
# instantiate the console output class for header, footer etc
|
@@ -39,13 +36,13 @@ module UpdateRepo
|
|
39
36
|
# walk_repo = UpdateRepo::WalkRepo.new
|
40
37
|
# walk_repo.start
|
41
38
|
def start
|
42
|
-
String.disable_colorization =
|
39
|
+
String.disable_colorization = !@cmd[:color]
|
43
40
|
# check for existence of 'Git' and exit otherwise...
|
44
41
|
checkgit
|
45
42
|
# print out our header unless we are dumping / importing ...
|
46
43
|
@cons.show_header unless dumping?
|
47
44
|
config['location'].each do |loc|
|
48
|
-
cmd
|
45
|
+
@cmd[:dump_tree] ? dump_tree(File.join(loc)) : recurse_dir(loc)
|
49
46
|
end
|
50
47
|
# print out an informative footer unless dump / import ...
|
51
48
|
@cons.show_footer unless dumping?
|
@@ -67,7 +64,7 @@ module UpdateRepo
|
|
67
64
|
end
|
68
65
|
|
69
66
|
def dumping?
|
70
|
-
cmd
|
67
|
+
@cmd[:dump] || @cmd[:dump_remote] || @cmd[:dump_tree]
|
71
68
|
end
|
72
69
|
|
73
70
|
# returns the Confoog class which can then be used to access any config var
|
@@ -77,17 +74,6 @@ module UpdateRepo
|
|
77
74
|
@cmd.getconfig
|
78
75
|
end
|
79
76
|
|
80
|
-
# Return the true value of the specified configuration parameter. This is a
|
81
|
-
# helper function that simply calls the 'true_cmd' function in the @cmd
|
82
|
-
# class
|
83
|
-
# @param command [symbol] The defined command symbol that is to be returned
|
84
|
-
# @return [various] The value of the requested command option
|
85
|
-
# @example
|
86
|
-
# logging = cmd(:log)
|
87
|
-
def cmd(command)
|
88
|
-
@cmd.true_cmd(command.to_sym)
|
89
|
-
end
|
90
|
-
|
91
77
|
# take each directory contained in the Repo directory, if it is detected as
|
92
78
|
# a Git repository then update it (or as directed by command line)
|
93
79
|
# @param dirname [string] Contains the directory to search for Git repos.]
|
@@ -163,7 +149,7 @@ module UpdateRepo
|
|
163
149
|
# @return [void]
|
164
150
|
def dump_repo(dir)
|
165
151
|
Dir.chdir(dir.chomp!('/')) do
|
166
|
-
print_log "#{trunc_dir(dir,
|
152
|
+
print_log "#{trunc_dir(dir, @cmd[:prune])}," if @cmd[:dump]
|
167
153
|
print_log `git -C #{dir} config remote.origin.url`
|
168
154
|
end
|
169
155
|
end
|
data/update_repo.gemspec
CHANGED
@@ -43,12 +43,11 @@ Gem::Specification.new do |spec|
|
|
43
43
|
if RUBY_VERSION < '2.0'
|
44
44
|
spec.add_development_dependency 'json', '= 1.8.3'
|
45
45
|
spec.add_development_dependency 'tins', '= 1.6.0'
|
46
|
+
spec.add_dependency 'term-ansicolor', '= 1.3.2'
|
46
47
|
end
|
47
48
|
|
48
49
|
spec.add_dependency 'colorize'
|
49
50
|
spec.add_dependency 'confoog'
|
50
51
|
spec.add_dependency 'trollop'
|
51
52
|
spec.add_dependency 'versionomy'
|
52
|
-
# on Ruby 1.9.3 we lock the 'term-ansicolor' gem to version 1.3.2
|
53
|
-
spec.add_dependency 'term-ansicolor', '= 1.3.2' if RUBY_VERSION < '2.0'
|
54
53
|
end
|
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.9.
|
4
|
+
version: 0.9.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:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|