nsrr 0.1.0.beta3 → 0.1.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 264d749d9908c859da8beac680941e7cf1d87ac3
4
- data.tar.gz: 6bb9f5bbb9f3dd79c522fa98e7543781ef8ad87a
3
+ metadata.gz: 9e5739cb4683537e512b1b4463f237bbd70a3247
4
+ data.tar.gz: 6059f16342f257f7282f40f78b6bc2fb7fe9464d
5
5
  SHA512:
6
- metadata.gz: 4ce4aacec2ce0cde8cc1fb459cacb60874fe6816efcb134baa0801b916ecc047631778504255eb4edaad6767a13fc4bd54850c9d290ba6d06a5a6784da17d75a
7
- data.tar.gz: cc22609fb152fca49f7cf8a516b5a637749cc74a4e2d9f41951780c99eb5b2e2e3e4e9d4d1388f597e620bfc2cb910228b5351a7d6ad5401ddc62e4430c1982a
6
+ metadata.gz: 36389482d66a709f8fda17d9dfc0caa0e020fe947f67ddb8a1d3f9a6dafdbc35df6fd63470e62cc4f0e76ad400fd6dbdec986b239bd5a18362a1312e1d8bcc47
7
+ data.tar.gz: b3823a0956ce76fc9077cfb7bee1fc8821021e9bbe3c203d9c922f339b0c3ea5888a46829f3916da6e9027997b964f440068608b567599104e6676b5188d3073
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  ## 0.1.0
2
2
 
3
3
  ### Enhancements
4
+ - Added a `nsrr download` command that allows users to download partial or entire datasets
5
+ - Example: `nsrr download shhs`
4
6
  - Added a `nsrr console` command that allows users to access and download datasets and files
5
7
  - Datasets can be loaded in the console environment
6
8
  - `d = Dataset.find 'shhs'`
data/README.md CHANGED
@@ -26,6 +26,46 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### Download files from a dataset
30
+
31
+ **Note:** You can type `Ctrl-C` to pause downloads and resume later by retyping the command.
32
+
33
+ Download an entire dataset.
34
+
35
+ ```console
36
+ $ nsrr download shhs
37
+ ```
38
+
39
+ Download a subfolder of a dataset.
40
+
41
+ ```console
42
+ $ nsrr download shhs/forms
43
+ ```
44
+
45
+ Download a folder without downloading contents of subfolders. By default, when not specified, the command will recursively download all contents of the specified folder and subfolders.
46
+
47
+ ```console
48
+ $ nsrr download shhs/datasets --shallow
49
+ ```
50
+
51
+ Continue an in progress download and only compare file sizes. By default, when a downloaded file already exists, the command will do an MD5 file comparison to verify the file is identical to the one on the server. The MD5 comparison is exact, but can be slow on older machines. If you want a quick check, you can tell the command to simply compare the file sizes of the local file and the file on the server which speeds up the comparison process, however it may in some cases be inaccurate.
52
+
53
+ ```console
54
+ $ nsrr download shhs --fast
55
+ ```
56
+
57
+ Redownload all files and overwrite any existing downloaded files.
58
+
59
+ ```console
60
+ $ nsrr download shhs --fresh
61
+ ```
62
+
63
+ You can combine the file check flag with the folder depth flag as well.
64
+
65
+ ```console
66
+ $ nsrr download shhs/datasets --shallow --fast
67
+ ```
68
+
29
69
  ### Open the console and download entire datasets
30
70
 
31
71
  ```console
@@ -0,0 +1,62 @@
1
+ require 'colorize'
2
+
3
+ require 'nsrr/models/all'
4
+
5
+ module Nsrr
6
+ module Commands
7
+ class Download
8
+ class << self
9
+ def run(*args)
10
+ new(*args).run
11
+ end
12
+ end
13
+
14
+ attr_reader :dataset_slug, :folder, :file_comparison, :depth
15
+
16
+ def initialize(argv)
17
+ (@token, argv) = parse_parameter_with_value(argv, ['token'], '')
18
+ (@file_comparison, argv) = parse_parameter(argv, ['fast', 'fresh', 'md5'], 'md5')
19
+ (@depth, argv) = parse_parameter(argv, ['shallow', 'recursive'], 'recursive')
20
+ @dataset_slug = argv[1].to_s.split('/').first
21
+ @folder = (argv[1].to_s.split('/')[1..-1] || []).join('/')
22
+ end
23
+
24
+ def run
25
+ @dataset = Dataset.find @dataset_slug
26
+ if @dataset
27
+ @dataset.download_token = @token
28
+ @dataset.download(@folder, depth: @depth, method: @file_comparison)
29
+ else
30
+ if @dataset_slug == nil
31
+ puts "Please specify a dataset: " + "nsrr download DATASET".colorize(:white)
32
+ else
33
+ puts "The dataset " + "#{@dataset_slug}".colorize(:white) + " was not found."
34
+ end
35
+ puts "Read more on the download command here:"
36
+ puts " " + "https://github.com/nsrr/nsrr-gem".colorize( :blue ).on_white.underline
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def parse_parameter(argv, options, default)
43
+ result = default
44
+ options.each do |option|
45
+ result = option if argv.delete "--#{option}"
46
+ end
47
+ return [result, argv]
48
+ end
49
+
50
+ def parse_parameter_with_value(argv, options, default)
51
+ result = default
52
+ options.each do |option|
53
+ argv.each do |arg|
54
+ result = arg.gsub(/^--#{option}=/, '') if arg =~ /^--#{option}=\w/
55
+ end
56
+ end
57
+
58
+ return [result, argv]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,6 @@
1
1
  require 'colorize'
2
2
  require 'fileutils'
3
+ require 'irb'
3
4
 
4
5
  require 'nsrr/helpers/constants'
5
6
  require 'nsrr/helpers/hash_helper'
@@ -19,6 +20,7 @@ module Nsrr
19
20
  end
20
21
  end
21
22
 
23
+ attr_accessor :download_token
22
24
  attr_reader :slug, :name
23
25
 
24
26
  def initialize(json = {})
@@ -73,11 +75,11 @@ module Nsrr
73
75
 
74
76
  @downloaded_megabytes = @downloaded_bytes / (1024 * 1024)
75
77
 
76
- puts "\nFinished in #{Time.now - @start_time} seconds."
78
+ puts "\nFinished in #{Time.now - @start_time} seconds." if @start_time
77
79
  puts "\n#{@folders_created} folder#{"s" if @folders_created != 1} created".colorize(:white) + ", " +
78
80
  "#{@files_downloaded} file#{"s" if @files_downloaded != 1} downloaded".colorize(:green) + ", " +
79
81
  "#{@downloaded_megabytes} MiB#{"s" if @downloaded_megabytes != 1} downloaded".colorize(:green) + ", " +
80
- "#{@files_skipped} file#{"s" if @files_skipped != 1} skipped".colorize(:blue) + ", " +
82
+ "#{@files_skipped} file#{"s" if @files_skipped != 1} skipped".colorize(:light_blue) + ", " +
81
83
  "#{@files_failed} file#{"s" if @files_failed != 1} failed".colorize(:red) + "\n\n"
82
84
  nil
83
85
  end
@@ -107,15 +109,15 @@ module Nsrr
107
109
  end
108
110
 
109
111
  def create_folder(folder)
110
- puts " create".colorize( :white ) + " #{folder}"
112
+ puts " create".colorize(:white) + " #{folder}"
111
113
  FileUtils.mkdir_p folder
112
114
  @folders_created += 1
113
115
  end
114
116
 
115
117
  def set_download_token
116
- puts " Get your token here: " + "https://sleepdata.org/token".colorize( :blue ).on_white.underline
118
+ puts " Get your token here: " + "#{Nsrr::WEBSITE}/token".colorize( :blue ).on_white.underline
117
119
  print "Please enter your download token: "
118
- @download_token = gets.chomp
120
+ @download_token = STDIN.gets.chomp
119
121
  end
120
122
 
121
123
  end
@@ -52,17 +52,17 @@ module Nsrr
52
52
  download_request.get
53
53
 
54
54
  if download_request.error.to_s == ''
55
- puts " download".colorize( :green ) + " #{@name}"
55
+ puts " download".colorize(:green) + " #{@name}"
56
56
  download_request.file_size
57
57
  else
58
- puts " failed".colorize( :red ) + " #{@name}"
58
+ puts " failed".colorize(:red) + " #{@name}"
59
59
  puts " #{download_request.error}"
60
60
  'fail'
61
61
  end
62
62
  end
63
63
 
64
64
  def skip
65
- puts " identical".colorize( :blue ) + " #{self.name}"
65
+ puts " identical".colorize(:light_blue) + " #{self.name}"
66
66
  'skip'
67
67
  end
68
68
 
data/lib/nsrr/version.rb CHANGED
@@ -3,7 +3,7 @@ module Nsrr
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "beta3" # nil, "pre", "rc", "rc2"
6
+ BUILD = "beta4" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
data/lib/nsrr.rb CHANGED
@@ -1,7 +1,10 @@
1
+ require 'colorize'
2
+
1
3
  require "nsrr/version"
2
4
 
3
5
  Nsrr::COMMANDS = {
4
6
  'c' => :console,
7
+ 'd' => :download,
5
8
  'v' => :version
6
9
  }
7
10
 
@@ -13,23 +16,11 @@ module Nsrr
13
16
  def self.console(argv)
14
17
  require 'nsrr/commands/console'
15
18
  Nsrr::Commands::Console.start(argv)
16
- # console = Nsrr::Commands::Console.new(argv)
17
- # console.start
18
- # `#{File.expand_path('../', __FILE__)}/nsrr/commands/console2`
19
-
20
-
21
- # require 'irb'
22
- # require 'irb/completion'
23
- # IRB.setup nil
24
- # IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
25
- # require 'irb/ext/multi-irb'
26
- # IRB.irb nil, self
27
-
28
- # require 'irb'
29
- # ARGV.clear
30
- # @a = "hello"
31
- # IRB.start
19
+ end
32
20
 
21
+ def self.download(argv)
22
+ require 'nsrr/commands/download'
23
+ Nsrr::Commands::Download.run(argv)
33
24
  end
34
25
 
35
26
  def self.help(argv)
@@ -40,12 +31,16 @@ Usage: nsrr COMMAND [ARGS]
40
31
  The most common nsrr commands are:
41
32
  [c]onsole Load an interactive console to access
42
33
  and download datasets and files
34
+ [d]ownload Download all or some files in a DATASET
43
35
  [v]ersion Returns the version of nsrr gem
44
36
 
45
37
  Commands can be referenced by the first letter:
46
38
  Ex: `nsrr v`, for version
47
39
 
48
40
  EOT
41
+ puts "Read more on the download command here:"
42
+ puts " " + "https://github.com/nsrr/nsrr-gem".colorize( :blue ).on_white.underline
43
+ puts "\n"
49
44
  end
50
45
 
51
46
  def self.version(argv)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta3
4
+ version: 0.1.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
@@ -96,6 +96,7 @@ files:
96
96
  - bin/nsrr
97
97
  - lib/nsrr.rb
98
98
  - lib/nsrr/commands/console.rb
99
+ - lib/nsrr/commands/download.rb
99
100
  - lib/nsrr/helpers/constants.rb
100
101
  - lib/nsrr/helpers/download_request.rb
101
102
  - lib/nsrr/helpers/hash_helper.rb