manifest-dl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/README.md +83 -0
- data/Rakefile +59 -0
- data/lib/manifest-dl.rb +111 -0
- data/lib/manifest-dl/rails.rb +26 -0
- data/lib/manifest-dl/rake.rb +35 -0
- data/lib/manifest-dl/version.rb +4 -0
- data/manifest-dl.gemspec +31 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ba4017f3570e96546119341a0092abe82f0429a
|
4
|
+
data.tar.gz: f802f115ac50c6c9485301fc0a2946ec85bda7d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16370c0a559a79ca2b89ec5f28b8e4a59789605bacdb39b136355f320764835f5032ee1b2fb26f877f8d17b3cbeaa79e0312518be72a1d3f51995a087095a664
|
7
|
+
data.tar.gz: 926034ddfc85008573540f4a8db3b6f0330be00e9dc8602e73c88f4a689757964431163d25ac1f8952247889f637aa7868746e225d47e43dd5d4cb82dee6e93c
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[]: {{{1
|
2
|
+
|
3
|
+
File : README.md
|
4
|
+
Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
+
Date : 2014-10-16
|
6
|
+
|
7
|
+
Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
Version : v0.1.0
|
9
|
+
|
10
|
+
[]: }}}1
|
11
|
+
|
12
|
+
<!--
|
13
|
+
[![Gem Version](https://badge.fury.io/rb/manifest-dl.png)](https://rubygems.org/gems/manifest-dl)
|
14
|
+
-->
|
15
|
+
|
16
|
+
## Description
|
17
|
+
[]: {{{1
|
18
|
+
|
19
|
+
manifest-dl - download extra files for your app
|
20
|
+
|
21
|
+
Sometimes you have a (web) app that needs some extra files (e.g.
|
22
|
+
terms and conditions) that you don't want to have to upload
|
23
|
+
manually, but prefer (e.g. because they're not very small) not to
|
24
|
+
have in your version control system.
|
25
|
+
|
26
|
+
manifest-dl allows you to specify the paths, urls and checksums in a
|
27
|
+
manifest and automatically downloads those extra files for you (and
|
28
|
+
updates them when they -- i.e. their checksums -- change).
|
29
|
+
|
30
|
+
NB: uses `curl` to download files; you'll need to have it installed.
|
31
|
+
|
32
|
+
[]: }}}1
|
33
|
+
|
34
|
+
## Examples
|
35
|
+
[]: {{{1
|
36
|
+
|
37
|
+
`Gemfile`:
|
38
|
+
```
|
39
|
+
gem 'manifest-dl', require: 'manifest-dl/rails'
|
40
|
+
```
|
41
|
+
|
42
|
+
`config/manifest-dl.yaml`:
|
43
|
+
```yaml
|
44
|
+
- path: public/uploads/t-and-c.pdf
|
45
|
+
- url: https://example.com/path/to/tandc.pdf
|
46
|
+
- sha512sum: 9c573b5ed223f076b4f0c9483608c2d341eb8...
|
47
|
+
```
|
48
|
+
|
49
|
+
`.gitignore`
|
50
|
+
```
|
51
|
+
/.manifest-dl-cache
|
52
|
+
```
|
53
|
+
|
54
|
+
```bash
|
55
|
+
rake manifest:dl
|
56
|
+
```
|
57
|
+
|
58
|
+
[]: }}}1
|
59
|
+
|
60
|
+
## Specs & Docs
|
61
|
+
|
62
|
+
```bash
|
63
|
+
rake spec # TODO
|
64
|
+
rake docs
|
65
|
+
```
|
66
|
+
|
67
|
+
## TODO
|
68
|
+
|
69
|
+
* gpg support?
|
70
|
+
* what to do with errors?
|
71
|
+
* specs/docs?
|
72
|
+
* ...
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
LGPLv3+ [1].
|
77
|
+
|
78
|
+
## References
|
79
|
+
|
80
|
+
[1] GNU Lesser General Public License, version 3
|
81
|
+
--- http://www.gnu.org/licenses/lgpl-3.0.html
|
82
|
+
|
83
|
+
[]: ! ( vim: set tw=70 sw=2 sts=2 et fdm=marker : )
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
desc 'Run specs'
|
2
|
+
task :spec do
|
3
|
+
sh 'rspec -c'
|
4
|
+
end
|
5
|
+
|
6
|
+
desc 'Run specs verbosely'
|
7
|
+
task 'spec:verbose' do
|
8
|
+
sh 'rspec -cfd'
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Run specs verbosely, view w/ less'
|
12
|
+
task 'spec:less' do
|
13
|
+
sh 'rspec -cfd --tty | less -R'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Check for warnings'
|
17
|
+
task :warn do
|
18
|
+
reqs = %w{ config }.map { |x| "-r manifest-dl/#{x}" } * ' '
|
19
|
+
sh "ruby -w -I lib #{reqs} -e ''"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Check for warnings in specs'
|
23
|
+
task 'warn:spec' do
|
24
|
+
reqs = Dir['spec/**/*.rb'].sort.map { |x| "-r ./#{x}" } * ' '
|
25
|
+
sh "ruby -w -I lib -r rspec #{reqs} -e ''"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Check for warnings in specs (but not void context)'
|
29
|
+
task 'warn:spec:novoid' do
|
30
|
+
sh 'rake warn:spec 2>&1 | grep -v "void context"'
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Generate docs'
|
34
|
+
task :docs do
|
35
|
+
sh 'yardoc | cat'
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'List undocumented objects'
|
39
|
+
task 'docs:undoc' do
|
40
|
+
sh 'yard stats --list-undoc'
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Cleanup'
|
44
|
+
task :clean do
|
45
|
+
sh 'rm -rf .yardoc/ doc/ *.gem'
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Build SNAPSHOT gem'
|
49
|
+
task :snapshot do
|
50
|
+
v = Time.new.strftime '%Y%m%d%H%M%S'
|
51
|
+
f = 'lib/manifest-dl/version.rb'
|
52
|
+
sh "sed -ri~ 's!(SNAPSHOT)!\\1.#{v}!' #{f}"
|
53
|
+
sh 'gem build manifest-dl.gemspec'
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'Undo SNAPSHOT gem'
|
57
|
+
task 'snapshot:undo' do
|
58
|
+
sh 'git checkout -- lib/manifest-dl/version.rb'
|
59
|
+
end
|
data/lib/manifest-dl.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# -- ; {{{1
|
2
|
+
#
|
3
|
+
# File : manifest-dl.rb
|
4
|
+
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
+
# Date : 2014-10-16
|
6
|
+
#
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
|
+
#
|
10
|
+
# -- ; }}}1
|
11
|
+
|
12
|
+
require 'digest/sha1'
|
13
|
+
require 'fileutils'
|
14
|
+
require 'pathname'
|
15
|
+
require 'tmpdir'
|
16
|
+
require 'yaml'
|
17
|
+
|
18
|
+
# namespace
|
19
|
+
module ManifestDL
|
20
|
+
|
21
|
+
class InvalidItemError < StandardError; end
|
22
|
+
class SystemError < StandardError; end
|
23
|
+
class VerificationError < StandardError; end
|
24
|
+
|
25
|
+
DEFAULT_CONFIG = File.expand_path './config/manifest-dl.yaml'
|
26
|
+
DEFAULT_CACHE = File.expand_path './.manifest-dl-cache'
|
27
|
+
|
28
|
+
# --
|
29
|
+
|
30
|
+
# download files in manifest
|
31
|
+
def self.run!(quiet = false, config_file = DEFAULT_CONFIG)
|
32
|
+
YAML.load(File.read(DEFAULT_CONFIG)).map do |item|
|
33
|
+
_check! item; _dl?(item) ? _dl!(item, quiet) : nil;
|
34
|
+
end .compact
|
35
|
+
end
|
36
|
+
|
37
|
+
# --
|
38
|
+
|
39
|
+
# check item
|
40
|
+
def self._check!(item)
|
41
|
+
raise InvalidItemError,
|
42
|
+
"unexpected/missing keys for item #{item.inspect}" \
|
43
|
+
unless item.keys.sort == %w{ path sha512sum url }
|
44
|
+
raise InvalidItemError,
|
45
|
+
"non-string keys for item #{item.inspect}" \
|
46
|
+
unless item.keys.all? { |x| String === x }
|
47
|
+
end
|
48
|
+
|
49
|
+
# download, verify, mv file
|
50
|
+
def self._dl!(item, quiet = false)
|
51
|
+
$stderr.puts "==> #{item['path']}" unless quiet
|
52
|
+
Dir.mktmpdir do |dir|
|
53
|
+
tempfile = Pathname.new(dir).join('dl').to_s
|
54
|
+
_curl! item['url'], tempfile, quiet
|
55
|
+
_verify! tempfile, item['sha512sum']
|
56
|
+
FileUtils.mkdir_p File.dirname(item['path'])
|
57
|
+
FileUtils.mv tempfile, item['path'], force: true
|
58
|
+
_cache! item['path'], item['sha512sum']
|
59
|
+
end
|
60
|
+
item['path']
|
61
|
+
end
|
62
|
+
|
63
|
+
# should file be downloaded?
|
64
|
+
# (i.e. does not exist or sum has changed)
|
65
|
+
def self._dl?(item)
|
66
|
+
return true unless File.exist? item['path']
|
67
|
+
_cached_sha512sum(item['path']) != item['sha512sum']
|
68
|
+
end
|
69
|
+
|
70
|
+
# --
|
71
|
+
|
72
|
+
# download file w/ curl
|
73
|
+
def self._curl!(url, file, quiet = false)
|
74
|
+
args = %w{ curl -L } + (quiet ? %w{ -s } : []) + ['-o', file, '--', url]
|
75
|
+
# no shell b/c multiple args!
|
76
|
+
system(*args) or raise SystemError 'curl returned non-zero'
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
# verify file
|
81
|
+
def self._verify!(file, sum)
|
82
|
+
# no shell b/c multiple args!
|
83
|
+
sum2 = IO.popen(%w{ shasum -a 512 } + [file]) { |f| f.gets.split.first }
|
84
|
+
raise SystemError 'shasum returned non-zero' unless $?.success?
|
85
|
+
raise VerificationError, file unless sum == sum2
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# get item's cached sha512sum;
|
90
|
+
# returns nil if cache file does not exist
|
91
|
+
def self._cached_sha512sum(path)
|
92
|
+
file = _cachefile path
|
93
|
+
File.exist?(file) ? File.read(file) : nil
|
94
|
+
end
|
95
|
+
|
96
|
+
# cache item's sha512sum (based on sha1sum of path)
|
97
|
+
def self._cache!(path, sum)
|
98
|
+
FileUtils.mkdir_p DEFAULT_CACHE
|
99
|
+
File.write _cachefile(path), sum
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
|
103
|
+
# cache file path
|
104
|
+
def self._cachefile(path)
|
105
|
+
sha1 = Digest::SHA1.hexdigest path
|
106
|
+
Pathname.new(DEFAULT_CACHE).join(sha1).to_s
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# vim: set tw=70 sw=2 sts=2 et fdm=marker :
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -- ; {{{1
|
2
|
+
#
|
3
|
+
# File : manifest-dl/rails.rb
|
4
|
+
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
+
# Date : 2014-10-16
|
6
|
+
#
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
|
+
#
|
10
|
+
# -- ; }}}1
|
11
|
+
|
12
|
+
require 'rails'
|
13
|
+
|
14
|
+
require 'manifest-dl'
|
15
|
+
|
16
|
+
# namespace
|
17
|
+
module LocalConfig
|
18
|
+
|
19
|
+
# railtie that adds the rake tasks
|
20
|
+
class Railtie < Rails::Railtie
|
21
|
+
rake_tasks { ManifestDL::Rake.define_tasks }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# vim: set tw=70 sw=2 sts=2 et fdm=marker :
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -- ; {{{1
|
2
|
+
#
|
3
|
+
# File : manifest-dl/rake.rb
|
4
|
+
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
+
# Date : 2014-10-16
|
6
|
+
#
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
|
+
#
|
10
|
+
# -- ; }}}1
|
11
|
+
|
12
|
+
require 'rake/dsl_definition'
|
13
|
+
|
14
|
+
require 'manifest-dl'
|
15
|
+
|
16
|
+
# namespace
|
17
|
+
module LocalConfig
|
18
|
+
|
19
|
+
# rake tasks
|
20
|
+
module Rake
|
21
|
+
extend ::Rake::DSL
|
22
|
+
|
23
|
+
# define rake task manifest:dl
|
24
|
+
def self.define_tasks
|
25
|
+
desc 'download extra files w/ manifest-dl'
|
26
|
+
task 'manifest:dl' do
|
27
|
+
ManifestDL.run!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# vim: set tw=70 sw=2 sts=2 et fdm=marker :
|
data/manifest-dl.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../lib/manifest-dl/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'manifest-dl'
|
5
|
+
s.homepage = 'https://github.com/obfusk/manifest-dl'
|
6
|
+
s.summary = 'download extra files for your app'
|
7
|
+
|
8
|
+
s.description = <<-END.gsub(/^ {4}/, '')
|
9
|
+
download extra files for your app
|
10
|
+
|
11
|
+
...
|
12
|
+
END
|
13
|
+
|
14
|
+
s.version = ManifestDL::VERSION
|
15
|
+
s.date = ManifestDL::DATE
|
16
|
+
|
17
|
+
s.authors = [ 'Felix C. Stegerman' ]
|
18
|
+
s.email = %w{ flx@obfusk.net }
|
19
|
+
|
20
|
+
s.licenses = %w{ LGPLv3+ }
|
21
|
+
|
22
|
+
s.files = %w{ .yardopts README.md Rakefile } \
|
23
|
+
+ %w{ manifest-dl.gemspec } \
|
24
|
+
+ Dir['{lib,spec}/**/*.rb']
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'rake'
|
27
|
+
|
28
|
+
# s.add_development_dependency 'rspec'
|
29
|
+
|
30
|
+
s.required_ruby_version = '>= 1.9.1'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manifest-dl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felix C. Stegerman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |
|
28
|
+
download extra files for your app
|
29
|
+
|
30
|
+
...
|
31
|
+
email:
|
32
|
+
- flx@obfusk.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".yardopts"
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/manifest-dl.rb
|
41
|
+
- lib/manifest-dl/rails.rb
|
42
|
+
- lib/manifest-dl/rake.rb
|
43
|
+
- lib/manifest-dl/version.rb
|
44
|
+
- manifest-dl.gemspec
|
45
|
+
homepage: https://github.com/obfusk/manifest-dl
|
46
|
+
licenses:
|
47
|
+
- LGPLv3+
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.9.1
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.2.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: download extra files for your app
|
69
|
+
test_files: []
|
70
|
+
has_rdoc:
|