datapimp 1.0.26 → 1.0.27

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: a42b604bf4e65ab42f866c53a65965fbda89a7f5
4
- data.tar.gz: 93fb5195047c3526751a596dc37bea8f0f641b43
3
+ metadata.gz: cfce180729b6e2c602a86df40edd9349b4f282aa
4
+ data.tar.gz: 76b302c41cee05dab82b51bb42599c6b6b62db36
5
5
  SHA512:
6
- metadata.gz: 1456e0203c464bf256bd59618b649336cdc81a22f5b0e9f404c41bb2e2a648d8bb72d0b8e8895ccc95f1142146ffe095fb1ed9f5a04f1dbfb481973ad33b4276
7
- data.tar.gz: 9639178e9e730e702451a4215194f534808b60582cc42c1e3ebb06f46d305f7a6b9627c333048a6894a56eaa2e2d97e9586675b4f98fa2d76d109e7132585b17
6
+ metadata.gz: ea267a7bc421320087d31f270fb8faee86acbcc87469d3331a020cf9e57a20f8b6d107bb0e36213dc05f7b8ec4f874173e45fcee2d7dd1614f5f549a80d7c3b7
7
+ data.tar.gz: f1e7bb996b15243c674b6de6a8d5d6605bdadff11cea2c0f6629c3ce4de0ff9a080e6a9a4cd603bca6cdcf80f33469befd83bb9d9fb91353758537a476875a90
@@ -4,29 +4,14 @@ command "sync folder" do |c|
4
4
 
5
5
  c.option '--type TYPE', String, "Which service is hosting the folder"
6
6
  c.option '--action ACTION', String, "Which sync action to run? push, pull"
7
+ c.option '--reset', nil, "Reset the local path (if supported by the syncable folder)"
7
8
 
8
9
  Datapimp::Cli.accepts_keys_for(c, :amazon, :google, :github, :dropbox)
9
10
 
10
11
  c.action do |args, options|
11
- options.default(action:"pull", type: "dropbox")
12
-
12
+ options.default(action:"pull", type: "dropbox", reset: false)
13
13
  local, remote = args
14
-
15
- folder = case
16
- when options.type == "dropbox"
17
- Datapimp::Sync::DropboxFolder.new(local: local, remote: remote)
18
- when options.type == "google"
19
- # Return the folders
20
- # collection = Datapimp::Sync.google.api.collections.first
21
- #
22
- # svg = collection.files.first
23
- # svg.export_as_file(/download/path, "image/svg+xml")
24
- Datapimp::Sync::GoogleDriveFolder.new(local: local, remote: remote)
25
- when options.type == "aws" || options.type == "s3"
26
- Datapimp::Sync::S3Bucket.new(local: local, remote: remote)
27
- end
28
-
29
- folder.run(options.action, options.to_hash.to_mash)
14
+ Datapimp::Sync.dispatch_sync_folder_action(local, remote, options.to_hash)
30
15
  end
31
16
  end
32
17
 
@@ -44,7 +29,7 @@ command "sync data" do |c|
44
29
  Datapimp::Cli.accepts_keys_for(c, :google, :github, :dropbox)
45
30
 
46
31
  c.action do |args, options|
47
- if options.type == "google-spreadsheet"
32
+ if options.type == "google-spreadsheet" || options.type == "google"
48
33
  Datapimp::DataSync.sync_google_spreadsheet(options, args)
49
34
  end
50
35
  end
@@ -124,6 +124,12 @@ module Datapimp
124
124
  def run_pull_action(options={})
125
125
  directories = Datapimp::Sync.amazon.storage.directories
126
126
  bucket = directories.get(remote)
127
+ options = options.to_mash
128
+
129
+ if options.reset == true
130
+ FileUtils.rm_rf(local_path)
131
+ FileUtils.mkdir_p(local_path)
132
+ end
127
133
 
128
134
  bucket.files.each do |file|
129
135
  local_file = local_path.join(file.key)
@@ -131,7 +137,7 @@ module Datapimp
131
137
 
132
138
  FileUtils.mkdir_p(local_file.dirname)
133
139
 
134
- local_file.open("w+") {|fh| log("Updating docs entry") ;fh.write(file.body) }
140
+ local_file.open("w+") {|fh| log("Updated #{ file.key }"); fh.write(file.body) }
135
141
  end
136
142
  end
137
143
 
@@ -157,9 +163,9 @@ module Datapimp
157
163
  elsif action == :create
158
164
  run_create_action(options)
159
165
  elsif action == :update_acl
160
- run_update_acl_action(options={})
166
+ run_update_acl_action(options)
161
167
  elsif action == :pull
162
- run_pull_action
168
+ run_pull_action(options)
163
169
  end
164
170
  end
165
171
  end
data/lib/datapimp/sync.rb CHANGED
@@ -7,6 +7,34 @@ module Datapimp
7
7
  %w(dropbox amazon github google json excel nokogiri)
8
8
  end
9
9
 
10
+ # Create any type of syncable folder and dispatch a run call to it
11
+ # with whatever options you want.
12
+ #
13
+ # options:
14
+ # - local: relative path to th local version of this folder
15
+ # - remote: an identifier for the remote folder in the remote system
16
+ # - action: push, pull, etc
17
+ def self.dispatch_sync_folder_action(local, remote, options)
18
+ options = options.to_mash
19
+ action = options.action
20
+
21
+ folder = case
22
+ when options.type == "dropbox"
23
+ Datapimp::Sync::DropboxFolder.new(local: local, remote: remote)
24
+ when options.type == "google"
25
+ # Return the folders
26
+ # collection = Datapimp::Sync.google.api.collections.first
27
+ #
28
+ # svg = collection.files.first
29
+ # svg.export_as_file(/download/path, "image/svg+xml")
30
+ Datapimp::Sync::GoogleDriveFolder.new(local: local, remote: remote)
31
+ when options.type == "aws" || options.type == "s3"|| options.type == "amazon"
32
+ Datapimp::Sync::S3Bucket.new(local: local, remote: remote)
33
+ end
34
+
35
+ folder.run(action, options)
36
+ end
37
+
10
38
  def self.amazon(options={})
11
39
  require 'datapimp/clients/amazon'
12
40
  Datapimp::Clients::Amazon.client(options)
@@ -1,3 +1,3 @@
1
1
  module Datapimp
2
- VERSION = "1.0.26"
2
+ VERSION = "1.0.27"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datapimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Soeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry