ssync 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  ssync (0.3.3)
5
5
  aws-s3 (~> 0.6.2)
6
+ thor (~> 0.14.4)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
@@ -13,6 +14,7 @@ GEM
13
14
  xml-simple
14
15
  builder (2.1.2)
15
16
  mime-types (1.16)
17
+ thor (0.14.4)
16
18
  xml-simple (1.0.12)
17
19
 
18
20
  PLATFORMS
@@ -21,3 +23,4 @@ PLATFORMS
21
23
  DEPENDENCIES
22
24
  aws-s3 (~> 0.6.2)
23
25
  ssync!
26
+ thor (~> 0.14.4)
data/README.md CHANGED
@@ -31,14 +31,20 @@ or `ssync sync --force` to force a checksum comparison.
31
31
 
32
32
  If you would like to sync to more than one S3 buckets, you may do so by:
33
33
 
34
- ssync setup my-s3-bucket
35
- ssync sync my-s3-bucket
34
+ ssync setup -b my-s3-bucket
35
+ ssync sync -b my-s3-bucket
36
36
 
37
- ssync setup another-s3-bucket
38
- ssync sync another-s3-bucket
37
+ ssync setup -b another-s3-bucket
38
+ ssync sync -b another-s3-bucket
39
39
 
40
40
  Running `ssync setup` and `ssync sync` without any bucket names defaults to using the last bucket you used.
41
41
 
42
+ ## Need Help?
43
+
44
+ Use the command below to get to the help screen.
45
+
46
+ ssync help
47
+
42
48
  ## Why?
43
49
 
44
50
  This library was written because we needed to be able to back up loads of
data/bin/ssync CHANGED
@@ -3,4 +3,4 @@
3
3
  $:.unshift File.dirname(__FILE__) + "/../lib"
4
4
  require "ssync/command"
5
5
 
6
- Ssync::Command.run!(*ARGV)
6
+ Ssync::Command.start
@@ -1,64 +1,52 @@
1
1
  require "ssync"
2
+ require "thor"
2
3
 
3
4
  module Ssync
4
- class Command
5
+ class Command < ::Thor
5
6
  include Helpers
6
7
 
7
- def self.action
8
- @@action
9
- end
8
+ default_task :sync
10
9
 
11
- def self.args
12
- @@args
13
- end
10
+ desc "setup", "Sets up a configuration file for syncing"
11
+ method_option "bucket", :aliases => "-b", :type => :string,
12
+ :banner => "The S3 bucket (configurated with Ssync) to sync to"
13
+ def setup
14
+ %w{find xargs openssl}.each do |util|
15
+ e! "You do not have '#{util}' installed on your operating system." if `which #{util}`.empty?
16
+ end
14
17
 
15
- def self.run!(*args)
16
- new(*args).run!
18
+ if options.bucket?
19
+ e! "The S3 bucket config for '#{options.bucket}' does not exist." unless config_exists?(config_path(options.bucket))
20
+ write_default_config(options.bucket)
21
+ end
22
+ aquire_lock! { Ssync::Setup.run! }
17
23
  end
18
24
 
19
- def initialize(action = :sync, *args)
20
- @@action = action.to_sym
21
- @@args = args
22
-
23
- if @@args[0] && @@args[0][0, 1] != "-"
24
- Setup.default_config[:last_used_bucket] = @@args[0]
25
- write_default_config!(Setup.default_config)
25
+ desc "sync", "Syncs to Amazon S3"
26
+ method_option "bucket", :aliases => "-b", :type => :string,
27
+ :banner => "The S3 bucket (configurated with Ssync) to sync to"
28
+ method_option "force", :aliases => "-f", :type => :boolean,
29
+ :banner => "Forces a recalculate of the checksum, useful when the previous sync was incomplete or corrupted"
30
+ def sync
31
+ unless config_exists?(default_config_path) || config_exists?
32
+ e! "Cannot run the sync, there is no Ssync configuration, try 'ssync setup' to create one first."
26
33
  end
27
- end
28
34
 
29
- def run!
30
- util_check!
31
- pre_run_check!
32
- perform_action!
35
+ write_default_config(options.bucket) if options.bucket?
36
+ aquire_lock! { Ssync::Sync.run!(options) }
33
37
  end
34
38
 
35
- private
36
-
37
- def util_check!
38
- %w{find xargs openssl}.each do |util|
39
- e! "You do not have '#{util}' installed on your operating system." if `which #{util}`.empty?
40
- end
39
+ desc "version", "Prints Ssync's version information"
40
+ def version
41
+ puts "Ssync #{Ssync::VERSION}"
41
42
  end
43
+ map %w{-v --version} => :version
42
44
 
43
- def pre_run_check!
44
- if action_eq?(:sync) && !config_exists?(default_config_path) && !config_exists?
45
- e! "Cannot run the sync, there is no Ssync configuration, try 'ssync setup' to create one first."
46
- end
47
- end
45
+ private
48
46
 
49
- def perform_action!
50
- case @@action
51
- when :setup
52
- Ssync::Setup.run!
53
- when :sync
54
- aquire_lock! { Ssync::Sync.run! }
55
- when :help, :"--help", :"-h"
56
- display_help!
57
- when :version, :"--version", :"-v"
58
- puts Ssync::VERSION
59
- else
60
- e! "Cannot perform action '#{@action}', try 'ssync help' for usage."
61
- end
47
+ def write_default_config(bucket)
48
+ Setup.default_config[:last_used_bucket] = bucket
49
+ write_default_config!(Setup.default_config)
62
50
  end
63
51
  end
64
52
  end
@@ -1,9 +1,5 @@
1
1
  module Ssync
2
2
  module Helpers
3
- def display_help!
4
- display("Not implemented yet.")
5
- end
6
-
7
3
  def display(message)
8
4
  puts("[#{Time.now}] #{message}")
9
5
  end
@@ -26,10 +22,6 @@ module Ssync
26
22
  a.empty? ? config_item : a
27
23
  end
28
24
 
29
- def action_eq?(action)
30
- Ssync::Command.action == action.to_sym
31
- end
32
-
33
25
  def config_exists?(path = config_path)
34
26
  File.exist?(path)
35
27
  end
@@ -46,8 +38,8 @@ module Ssync
46
38
  "#{ssync_homedir}/defaults.yml"
47
39
  end
48
40
 
49
- def config_path
50
- "#{ssync_homedir}/#{ssync_filename}.yml"
41
+ def config_path(filename = nil)
42
+ "#{ssync_homedir}/#{filename || ssync_filename}.yml"
51
43
  end
52
44
 
53
45
  def lock_path
@@ -55,14 +47,15 @@ module Ssync
55
47
  end
56
48
 
57
49
  def aquire_lock!
50
+ return unless lock_path
58
51
  # better way is to write out the pid ($$) and read it back in, to make sure it's the same
59
52
  e! "Found a lock at #{lock_path}, is another instance of Ssync running?" if File.exist?(lock_path)
60
53
 
61
54
  begin
62
- system "touch #{lock_path}"
55
+ system "touch #{lock_path}" unless ssync_filename.empty?
63
56
  yield
64
57
  ensure
65
- system "rm #{lock_path}"
58
+ system "rm -f #{lock_path}"
66
59
  end
67
60
  end
68
61
 
@@ -94,12 +87,5 @@ module Ssync
94
87
  def create_homedir!
95
88
  `mkdir #{ssync_homedir}` unless File.exists?(ssync_homedir)
96
89
  end
97
-
98
- def options_set?(*options)
99
- false
100
- [options].flatten.each do |option|
101
- return true if Command.args.include?("#{option.to_s}")
102
- end
103
- end
104
90
  end
105
91
  end
@@ -3,14 +3,14 @@ module Ssync
3
3
  class << self
4
4
  include Helpers
5
5
 
6
- def run!
6
+ def run!(options)
7
7
  display "Initialising Ssync, performing pre-sync checks ..."
8
8
 
9
9
  e! "Couldn't connect to AWS with the credentials specified in '#{config_path}'." unless Setup.aws_credentials_is_valid?
10
10
  e! "Couldn't find the S3 bucket specified in '#{config_path}'." unless Setup.bucket_exists?
11
11
  e! "The local path specified in '#{config_path}' does not exist." unless Setup.local_file_path_exists?
12
12
 
13
- if options_set?("-f", "--force")
13
+ if options.force?
14
14
  display "Clearing previous sync state ..."
15
15
  clear_sync_state
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Ssync
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_runtime_dependency(%q<aws-s3>, ["~> 0.6.2"])
24
+ s.add_runtime_dependency(%q<thor>, ["~> 0.14.4"])
24
25
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Fred Wu
@@ -33,6 +33,21 @@ dependencies:
33
33
  version: 0.6.2
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: thor
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ - 14
47
+ - 4
48
+ version: 0.14.4
49
+ type: :runtime
50
+ version_requirements: *id002
36
51
  description: Ssync, an optimised S3 sync tool using the power of *nix!
37
52
  email:
38
53
  - fred@envato.com