pmirror 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -3
- data/Gemfile.lock +1 -1
- data/README.md +45 -6
- data/features/pmirror.feature +10 -2
- data/lib/pmirror.rb +37 -24
- data/lib/pmirror/version.rb +1 -1
- data/pmirror.gemspec +1 -1
- data/pmirror_test_config.yaml +7 -0
- metadata +4 -3
data/.travis.yml
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
language: ruby
|
2
|
-
rvm:
|
3
|
-
|
4
|
-
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.1.0
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: T0PsyTzE9ZIhs48xHxMUNIjzGS9pu5iYVYR8K6sUjcv2H5zmg/R3PZ3g6DK8tvnLHCgI5nrZ0Nb+BJgH+65yRMJrrFAjJISDTh/3gWq+nlTq4IFxgYOvFrCQXl2IyhjpkFktUxHBWMnz7v6iTZJt/Ej+My4iQ8X6kl4WiAnKJJ4=
|
9
|
+
gem: pmirror
|
10
|
+
on:
|
11
|
+
tags: true
|
12
|
+
repo: adnichols/pmirror
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -54,13 +54,12 @@ Usage: pmirror [options] url
|
|
54
54
|
|
55
55
|
Options:
|
56
56
|
-h, --help Show command line help
|
57
|
-
-p, --pattern PAT1,PAT2,PAT3 Regex to match files in remote dir,
|
58
|
-
|
59
|
-
-u --url One or more URL's to check for
|
60
|
-
files that match the defined patterns
|
57
|
+
-p, --pattern PAT1,PAT2,PAT3 Regex to match files in remote dir, may specify multiple patterns
|
58
|
+
-u --url One or more URL's to check for files that match the defined patterns
|
61
59
|
-l, --localdir DIR Local directory to mirror files to
|
62
60
|
-e, --exec CMD Execute command after completion
|
63
|
-
|
61
|
+
--log-level Set the logging level to one of [ debug, info, warn, error]
|
62
|
+
-c, --config FILE Config file to read command line options from (yaml)
|
64
63
|
-v, --version Show version
|
65
64
|
```
|
66
65
|
|
@@ -74,14 +73,31 @@ the same filename is matched across multiple URL's only the first will
|
|
74
73
|
be downloaded, subsequent files will see that there is already a local
|
75
74
|
file with the same name and will not download.
|
76
75
|
|
76
|
+
Example:
|
77
|
+
```
|
78
|
+
pmirror --url http://someurl.com # Single URL
|
79
|
+
pmirror --url http://someurl.com,http://someotherurl.com # Multiple URLs
|
80
|
+
```
|
81
|
+
|
77
82
|
`--pattern` allows you to specify a comma separated list of patterns to
|
78
83
|
match on the remote directly. We will iterate over each pattern and
|
79
84
|
build up the file list to fetch from the remote url.
|
80
85
|
|
86
|
+
Example:
|
87
|
+
```
|
88
|
+
pmirror --pattern foo # Single pattern
|
89
|
+
pmirror --pattern foo,bar # Multiple patterns
|
90
|
+
```
|
91
|
+
|
81
92
|
`--localdir` is the location you want files downloaded to. It is also
|
82
93
|
the directory in which any commands specified with `--exec` will be
|
83
94
|
performed.
|
84
95
|
|
96
|
+
Example:
|
97
|
+
```
|
98
|
+
pmirror --localdir /tmp/foo
|
99
|
+
```
|
100
|
+
|
85
101
|
`--exec` is used to perform actions on the download directory. The
|
86
102
|
envisioned use case right now is simply to run a createrepo when the
|
87
103
|
downloads are complete. This will change PWD to whatever directory is
|
@@ -89,7 +105,30 @@ specified in `--localdir` and then will run the command you specify.
|
|
89
105
|
There is not currently a way to pass the value of `--localdir` into a
|
90
106
|
command other than to specify `.` in your command.
|
91
107
|
|
92
|
-
|
108
|
+
Example:
|
109
|
+
```
|
110
|
+
pmirror --exec 'createrepo -c .cache -d .'
|
111
|
+
```
|
112
|
+
|
113
|
+
`--log-level` will set the logging level when you run the application.
|
114
|
+
This enables additional messaging. The most useful log levels right now
|
115
|
+
are `info` and `debug`.
|
116
|
+
|
117
|
+
`--config` allows you to put all of your command line options into a
|
118
|
+
YAML formatted configuration file. Unlike the command line, lists of
|
119
|
+
options here (like pattern: or url:) are YAML lists. Each key must be
|
120
|
+
the long name of the option to use. There is no default config file.
|
121
|
+
|
122
|
+
Example config:
|
123
|
+
```
|
124
|
+
localdir: ../foo
|
125
|
+
pattern:
|
126
|
+
- ^floo.*
|
127
|
+
- ^mah.*
|
128
|
+
url:
|
129
|
+
- http://localhost:55555
|
130
|
+
- http://localhost:55555
|
131
|
+
```
|
93
132
|
|
94
133
|
`--version` provides the version info
|
95
134
|
|
data/features/pmirror.feature
CHANGED
@@ -11,13 +11,12 @@ Feature: My bootstrapped app kinda works
|
|
11
11
|
And the banner should document that this app takes options
|
12
12
|
And the following options should be documented:
|
13
13
|
|--pattern|
|
14
|
-
|--debug|
|
15
14
|
|--localdir|
|
16
15
|
|--exec|
|
17
16
|
|--version|
|
18
17
|
|--url|
|
18
|
+
|--log-level|
|
19
19
|
|-p|
|
20
|
-
|-d|
|
21
20
|
|-l|
|
22
21
|
|-e|
|
23
22
|
|-u|
|
@@ -69,3 +68,12 @@ Feature: My bootstrapped app kinda works
|
|
69
68
|
And the following files should not exist:
|
70
69
|
| ../foo/meh.txt|
|
71
70
|
|
71
|
+
Scenario: Use a config file
|
72
|
+
When I successfully run `pmirror -c ../../pmirror_test_config.yaml`
|
73
|
+
Then the exit status should be 0
|
74
|
+
And the following files should exist:
|
75
|
+
| ../foo/floober.txt|
|
76
|
+
| ../foo/floobah.txt|
|
77
|
+
| ../foo/mah.txt|
|
78
|
+
And the following files should not exist:
|
79
|
+
| ../foo/meh.txt|
|
data/lib/pmirror.rb
CHANGED
@@ -11,12 +11,19 @@ module Pmirror
|
|
11
11
|
version(::Pmirror::VERSION)
|
12
12
|
|
13
13
|
main do
|
14
|
-
|
14
|
+
debug "Inside main"
|
15
|
+
|
16
|
+
parse_config(options[:config]) if options[:config]
|
17
|
+
normalize_defaults
|
15
18
|
|
16
19
|
if options[:url] && options[:pattern] && options[:localdir]
|
17
20
|
download_list = get_download_list(options[:url], options[:pattern])
|
18
|
-
|
19
|
-
|
21
|
+
debug "download_list: #{download_list.inspect}"
|
22
|
+
if download_list
|
23
|
+
download_files(options[:localdir], download_list)
|
24
|
+
else
|
25
|
+
info "No files to download"
|
26
|
+
end
|
20
27
|
|
21
28
|
execute(options[:exec]) if options[:exec]
|
22
29
|
else
|
@@ -31,67 +38,73 @@ module Pmirror
|
|
31
38
|
)
|
32
39
|
on("-l", "--localdir DIR", "Local directory to mirror files to")
|
33
40
|
on("-e", "--exec CMD", "Execute command after completion")
|
34
|
-
on("-d", "--debug", "Enable debugging")
|
35
41
|
on("-u", "--url URL,URL", Array, "Url or remote site")
|
42
|
+
on("-c", "--config FILE", "Config file (yaml) to use instead of command line options")
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
use_log_level_option
|
45
|
+
|
46
|
+
def self.parse_config(config_file)
|
47
|
+
debug "In parse_config"
|
48
|
+
parsed = YAML::load_file(config_file)
|
49
|
+
if parsed.kind_of? Hash
|
50
|
+
parsed.each do |option,value|
|
51
|
+
debug "Storing option '#{option}' with value '#{value.inspect}'"
|
52
|
+
options[option] = value
|
53
|
+
end
|
40
54
|
end
|
41
55
|
end
|
42
56
|
|
43
57
|
def self.get_download_list(url_list, pattern)
|
44
|
-
|
58
|
+
debug "inside get_download_list"
|
45
59
|
downloads = {}
|
46
60
|
url_list.each do |single_url|
|
47
61
|
downloads[single_url] = []
|
48
|
-
|
62
|
+
info "Getting download list for url: #{single_url}"
|
49
63
|
page = Nokogiri::HTML(open(single_url))
|
50
64
|
|
51
65
|
page.css("a").each do |link|
|
52
66
|
file_name = link.attributes['href'].value
|
53
67
|
pattern.each do |matcher|
|
54
68
|
if /#{matcher}/.match(file_name)
|
55
|
-
|
69
|
+
debug "Found match: #{file_name}"
|
56
70
|
downloads[single_url] << file_name
|
57
71
|
end
|
58
72
|
end
|
59
73
|
end
|
60
|
-
|
74
|
+
debug "Returning downloads: #{downloads.inspect}"
|
61
75
|
end
|
62
76
|
downloads
|
63
77
|
end
|
64
78
|
|
65
79
|
def self.download_files(local_dir, url_hash={})
|
66
|
-
|
80
|
+
debug "Inside download_files"
|
67
81
|
url_hash.each_key do |single_url|
|
68
|
-
|
82
|
+
debug "Working on #{single_url}"
|
69
83
|
url_hash[single_url].each do |file|
|
70
84
|
local_fn = "#{local_dir}/#{file}"
|
71
85
|
|
72
86
|
unless Dir.exist? options[:localdir]
|
73
|
-
|
74
|
-
|
75
|
-
puts "Destination directory '#{options[:localdir]}' does not exist!"
|
87
|
+
debug "PWD: #{Dir.pwd}"
|
88
|
+
info "Destination directory '#{options[:localdir]}' does not exist!"
|
76
89
|
exit 1
|
77
90
|
end
|
78
91
|
|
79
92
|
remote_fn = "#{single_url}/#{file}"
|
80
93
|
unless File.exist?(local_fn)
|
81
|
-
|
82
|
-
|
94
|
+
info "Downloading File: #{file}"
|
95
|
+
info "#{remote_fn} ==> #{local_fn}"
|
83
96
|
http_to_file(local_fn, remote_fn)
|
84
97
|
# File.write(local_fn, open(remote_fn).read)
|
85
|
-
|
98
|
+
info "Download Complete for #{file}"
|
86
99
|
else
|
87
|
-
|
100
|
+
info "Skipping #{file}, already exists"
|
88
101
|
end
|
89
102
|
end
|
90
103
|
end
|
91
104
|
end
|
92
105
|
|
93
106
|
def self.http_to_file(filename,url)
|
94
|
-
|
107
|
+
debug "Inside http_to_file"
|
95
108
|
pbar = nil
|
96
109
|
File.open(filename, 'wb') do |save_file|
|
97
110
|
open(url, 'rb',
|
@@ -105,12 +118,12 @@ module Pmirror
|
|
105
118
|
pbar.set s if pbar
|
106
119
|
}) {|f| save_file.write(f.read) }
|
107
120
|
end
|
108
|
-
|
121
|
+
info ""
|
109
122
|
end
|
110
123
|
|
111
124
|
def self.execute(cmd)
|
112
|
-
|
113
|
-
|
125
|
+
debug "Inside execute"
|
126
|
+
info "Executing: #{cmd}"
|
114
127
|
sh("cd #{options[:localdir]} && #{cmd}")
|
115
128
|
end
|
116
129
|
|
data/lib/pmirror/version.rb
CHANGED
data/pmirror.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["anichols@trumped.org"]
|
11
11
|
spec.description = %q{Mirror files from remote http server by pattern}
|
12
12
|
spec.summary = %q{Mirror files from remote http server by pattern}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "http://github.com/adnichols/pmirror"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pmirror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -178,12 +178,13 @@ files:
|
|
178
178
|
- lib/pmirror.rb
|
179
179
|
- lib/pmirror/version.rb
|
180
180
|
- pmirror.gemspec
|
181
|
+
- pmirror_test_config.yaml
|
181
182
|
- spec/something_spec.rb
|
182
183
|
- web/floobah.txt
|
183
184
|
- web/floober.txt
|
184
185
|
- web/mah.txt
|
185
186
|
- web/meh.txt
|
186
|
-
homepage:
|
187
|
+
homepage: http://github.com/adnichols/pmirror
|
187
188
|
licenses:
|
188
189
|
- MIT
|
189
190
|
post_install_message:
|