manifest-dl 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ba4017f3570e96546119341a0092abe82f0429a
4
- data.tar.gz: f802f115ac50c6c9485301fc0a2946ec85bda7d3
3
+ metadata.gz: cc716ceae8c6a8d54cd5c4156fd0702ee4536f2e
4
+ data.tar.gz: 232fe98b96f4beb249b2077c6c9fd309a7012116
5
5
  SHA512:
6
- metadata.gz: 16370c0a559a79ca2b89ec5f28b8e4a59789605bacdb39b136355f320764835f5032ee1b2fb26f877f8d17b3cbeaa79e0312518be72a1d3f51995a087095a664
7
- data.tar.gz: 926034ddfc85008573540f4a8db3b6f0330be00e9dc8602e73c88f4a689757964431163d25ac1f8952247889f637aa7868746e225d47e43dd5d4cb82dee6e93c
6
+ metadata.gz: cf2e8d4e8a3860be0e750804cd96eea75a624a6fbe94920499257c1eaab80e7ac86369cfb4fe3e410262ea4095f0ed5a59f2831478c5cdb85679fa1ec2d55d68
7
+ data.tar.gz: 64ed81694a1acdcad6fe0ebc496e32b213563d97309e823b57997a55f5211c2acd3ca90ddc6b3efdce65bca74cbe222725cc51a0224ac3d48e227f6f43072a1b
data/README.md CHANGED
@@ -2,30 +2,29 @@
2
2
 
3
3
  File : README.md
4
4
  Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- Date : 2014-10-16
5
+ Date : 2014-10-20
6
6
 
7
7
  Copyright : Copyright (C) 2014 Felix C. Stegerman
8
- Version : v0.1.0
8
+ Version : v0.1.1
9
9
 
10
10
  []: }}}1
11
11
 
12
- <!--
13
12
  [![Gem Version](https://badge.fury.io/rb/manifest-dl.png)](https://rubygems.org/gems/manifest-dl)
14
- -->
15
13
 
16
14
  ## Description
17
15
  []: {{{1
18
16
 
19
- manifest-dl - download extra files for your app
17
+ manifest-dl - download extra files for your ruby app
20
18
 
21
19
  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.
20
+ assets like videos or terms and conditions) that you don't want to
21
+ have to upload manually, but prefer (e.g. because they're not very
22
+ small) not to have in your version control system.
25
23
 
26
24
  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).
25
+ manifest and automatically downloads those extra files for you (from
26
+ a website or cloud storage) and updates them when they -- i.e.
27
+ their checksums -- change.
29
28
 
30
29
  NB: uses `curl` to download files; you'll need to have it installed.
31
30
 
@@ -34,25 +33,38 @@
34
33
  ## Examples
35
34
  []: {{{1
36
35
 
37
- `Gemfile`:
38
- ```
36
+ ### Rails
37
+
38
+ ```ruby
39
+ # Gemfile
39
40
  gem 'manifest-dl', require: 'manifest-dl/rails'
40
41
  ```
41
42
 
42
- `config/manifest-dl.yaml`:
43
43
  ```yaml
44
+ # config/manifest-dl.yaml
44
45
  - path: public/uploads/t-and-c.pdf
45
- - url: https://example.com/path/to/tandc.pdf
46
- - sha512sum: 9c573b5ed223f076b4f0c9483608c2d341eb8...
46
+ url: https://example.com/path/to/tandc.pdf
47
+ sha512sum: 9c573b5ed223f076b4f0c9483608c2d341eb8...
48
+
49
+ - path: public/uploads/video.mp4
50
+ url: https://cloud.example.com/share/my-video.mp4
51
+ sha512sum: f7fbba6e0636f890e56fbbf3283e524c6fa32...
47
52
  ```
48
53
 
49
- `.gitignore`
50
54
  ```
55
+ # .gitignore
51
56
  /.manifest-dl-cache
52
57
  ```
53
58
 
54
59
  ```bash
55
- rake manifest:dl
60
+ rake manifest:dl # run!
61
+ ```
62
+
63
+ ### Standalone
64
+
65
+ ```ruby
66
+ require 'manifest-rb'
67
+ ManifestRB.run!
56
68
  ```
57
69
 
58
70
  []: }}}1
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # File : manifest-dl.rb
4
4
  # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- # Date : 2014-10-16
5
+ # Date : 2014-10-20
6
6
  #
7
7
  # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
8
  # Licence : LGPLv3+
@@ -22,15 +22,19 @@ module ManifestDL
22
22
  class SystemError < StandardError; end
23
23
  class VerificationError < StandardError; end
24
24
 
25
- DEFAULT_CONFIG = File.expand_path './config/manifest-dl.yaml'
26
- DEFAULT_CACHE = File.expand_path './.manifest-dl-cache'
25
+ DEFAULT_CONFIG = './config/manifest-dl.yaml'
26
+ DEFAULT_CACHE = './.manifest-dl-cache'
27
27
 
28
28
  # --
29
29
 
30
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;
31
+ def self.run!(opts = {})
32
+ quiet = opts.fetch(:quiet) { false }
33
+ config_file = opts.fetch(:config_file) { DEFAULT_CONFIG }
34
+ cache_dir = opts.fetch(:cache_dir) { DEFAULT_CACHE }
35
+ YAML.load(File.read(config_file)).map do |item|
36
+ _check! item
37
+ _dl?(item, cache_dir) ? _dl!(item, quiet, cache_dir) : nil;
34
38
  end .compact
35
39
  end
36
40
 
@@ -47,7 +51,7 @@ module ManifestDL
47
51
  end
48
52
 
49
53
  # download, verify, mv file
50
- def self._dl!(item, quiet = false)
54
+ def self._dl!(item, quiet, cache_dir)
51
55
  $stderr.puts "==> #{item['path']}" unless quiet
52
56
  Dir.mktmpdir do |dir|
53
57
  tempfile = Pathname.new(dir).join('dl').to_s
@@ -55,22 +59,22 @@ module ManifestDL
55
59
  _verify! tempfile, item['sha512sum']
56
60
  FileUtils.mkdir_p File.dirname(item['path'])
57
61
  FileUtils.mv tempfile, item['path'], force: true
58
- _cache! item['path'], item['sha512sum']
62
+ _cache! item['path'], item['sha512sum'], cache_dir
59
63
  end
60
64
  item['path']
61
65
  end
62
66
 
63
67
  # should file be downloaded?
64
68
  # (i.e. does not exist or sum has changed)
65
- def self._dl?(item)
69
+ def self._dl?(item, cache_dir)
66
70
  return true unless File.exist? item['path']
67
- _cached_sha512sum(item['path']) != item['sha512sum']
71
+ _cached_sha512sum(item['path'], cache_dir) != item['sha512sum']
68
72
  end
69
73
 
70
74
  # --
71
75
 
72
76
  # download file w/ curl
73
- def self._curl!(url, file, quiet = false)
77
+ def self._curl!(url, file, quiet)
74
78
  args = %w{ curl -L } + (quiet ? %w{ -s } : []) + ['-o', file, '--', url]
75
79
  # no shell b/c multiple args!
76
80
  system(*args) or raise SystemError 'curl returned non-zero'
@@ -88,22 +92,22 @@ module ManifestDL
88
92
 
89
93
  # get item's cached sha512sum;
90
94
  # returns nil if cache file does not exist
91
- def self._cached_sha512sum(path)
92
- file = _cachefile path
95
+ def self._cached_sha512sum(path, cache_dir)
96
+ file = _cachefile cache_dir, path
93
97
  File.exist?(file) ? File.read(file) : nil
94
98
  end
95
99
 
96
100
  # 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
101
+ def self._cache!(path, sum, cache_dir)
102
+ FileUtils.mkdir_p cache_dir
103
+ File.write _cachefile(cache_dir, path), sum
100
104
  nil
101
105
  end
102
106
 
103
107
  # cache file path
104
- def self._cachefile(path)
108
+ def self._cachefile(cache_dir, path)
105
109
  sha1 = Digest::SHA1.hexdigest path
106
- Pathname.new(DEFAULT_CACHE).join(sha1).to_s
110
+ Pathname.new(cache_dir).join(sha1).to_s
107
111
  end
108
112
 
109
113
  end
@@ -1,4 +1,4 @@
1
1
  module ManifestDL
2
- VERSION = '0.1.0'
3
- DATE = '2014-10-16'
2
+ VERSION = '0.1.1'
3
+ DATE = '2014-10-20'
4
4
  end
@@ -3,10 +3,10 @@ require File.expand_path('../lib/manifest-dl/version', __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'manifest-dl'
5
5
  s.homepage = 'https://github.com/obfusk/manifest-dl'
6
- s.summary = 'download extra files for your app'
6
+ s.summary = 'download extra files for your ruby app'
7
7
 
8
8
  s.description = <<-END.gsub(/^ {4}/, '')
9
- download extra files for your app
9
+ download extra files for your ruby app
10
10
 
11
11
  ...
12
12
  END
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifest-dl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix C. Stegerman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: |
28
- download extra files for your app
28
+ download extra files for your ruby app
29
29
 
30
30
  ...
31
31
  email:
@@ -65,6 +65,6 @@ rubyforge_project:
65
65
  rubygems_version: 2.2.2
66
66
  signing_key:
67
67
  specification_version: 4
68
- summary: download extra files for your app
68
+ summary: download extra files for your ruby app
69
69
  test_files: []
70
70
  has_rdoc: