Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 269b8b4 + 5ecc7d4 commit 45f76d896adab01edb724548f649a594dc5ce89a Michael van Rooijen committed Mar 16, 2011
View
@@ -3,8 +3,16 @@
source 'http://rubygems.org'
##
-# Bundle gems defined inside the gemspec file
-gemspec
+# Load Backup::Dependency
+%w[cli dependency].each do |path|
+ require File.expand_path("../lib/backup/#{path}", __FILE__)
+end
+
+##
+# Dynamically define the dependencies specified in Backup::Dependency.all
+Backup::Dependency.all.each do |name, gemspec|
+ gem(name, gemspec[:version])
+end
##
# Define gems to be used in the 'test' environment
View
@@ -1,15 +1,3 @@
-PATH
- remote: .
- specs:
- backup (3.0.7)
- dropbox (~> 1.2.3)
- fog (~> 0.5.3)
- mail (~> 2.2.15)
- net-scp (~> 1.0.4)
- net-sftp (~> 2.0.5)
- thor (~> 0.14.6)
- twitter (~> 1.1.2)
-
GEM
remote: http://rubygems.org/
specs:
@@ -29,9 +17,9 @@ GEM
rack (< 2, >= 1.1.0)
faraday_middleware (0.3.2)
faraday (~> 0.5.4)
- fog (0.5.3)
+ fog (0.6.0)
builder
- excon (>= 0.5.2)
+ excon (>= 0.5.5)
formatador (>= 0.0.16)
json
mime-types
@@ -70,7 +58,7 @@ GEM
notifiers (1.1.0)
oauth (0.4.4)
polyglot (0.3.1)
- rack (1.2.1)
+ rack (1.2.2)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
@@ -83,7 +71,6 @@ GEM
ruby-hmac (0.4.0)
ruby-progressbar (0.0.9)
simple_oauth (0.1.4)
- thor (0.14.6)
timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
@@ -100,9 +87,15 @@ PLATFORMS
ruby
DEPENDENCIES
- backup!
+ dropbox (~> 1.2.3)
+ fog (~> 0.6.0)
fuubar
infinity_test
+ mail (~> 2.2.15)
mocha
+ net-scp (~> 1.0.4)
+ net-sftp (~> 2.0.5)
+ net-ssh (~> 2.1.3)
rspec
timecop
+ twitter (~> 1.1.2)
View
@@ -74,6 +74,7 @@ Syncers
-------
- RSync
+- Amazon Simple Storage Service (S3)
[Syncer Wiki Page](https://github.com/meskyanichi/backup/wiki/Syncers)
View
@@ -34,12 +34,6 @@ Gem::Specification.new do |gem|
##
# Production gem dependencies
- gem.add_dependency 'thor', ['~> 0.14.6'] # CLI
- gem.add_dependency 'fog', ['~> 0.5.3' ] # Amazon S3, Rackspace Cloud Files
- gem.add_dependency 'dropbox', ['~> 1.2.3' ] # Dropbox
- gem.add_dependency 'mail', ['~> 2.2.15'] # Mail
- gem.add_dependency 'net-sftp', ['~> 2.0.5' ] # SFTP Protocol
- gem.add_dependency 'net-scp', ['~> 1.0.4' ] # SCP Protocol
- gem.add_dependency 'twitter', ['~> 1.1.2' ] # Twitter
+ gem.add_dependency 'thor', ['~> 0.14.6']
end
View
@@ -200,6 +200,44 @@ class BackupCLI < Thor
end
##
+ # [Dependencies]
+ # Returns a list of Backup's dependencies
+ desc 'dependencies', 'Display the list of dependencies for Backup, or install them through Backup.'
+ method_option :install, :type => :string
+ method_option :list, :type => :boolean
+ def dependencies
+ unless options.any?
+ puts
+ puts "To display a list of available dependencies, run:\n\n"
+ puts " backup dependencies --list"
+ puts
+ puts "To install one of these dependencies (with the correct version), run:\n\n"
+ puts " backup dependencies --install <name>"
+ exit
+ end
+
+ if options[:list]
+ Backup::Dependency.all.each do |name, gemspec|
+ puts
+ puts name
+ puts "--------------------------------------------------"
+ puts "version: #{gemspec[:version]}"
+ puts "lib required: #{gemspec[:require]}"
+ puts "used for: #{gemspec[:for]}"
+ end
+ end
+
+ if options[:install]
+ puts
+ puts "Installing \"#{options[:install]}\" version \"#{Backup::Dependency.all[options[:install]][:version]}\".."
+ puts "If this doesn't work, please issue the following command yourself:\n\n"
+ puts " gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}'\n\n"
+ puts "Please wait..\n\n"
+ puts %x[gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}']
+ end
+ end
+
+ ##
# [Version]
# Returns the current version of the Backup gem
map '-v' => :version
View
@@ -44,12 +44,13 @@ module Backup
##
# Autoload Backup base files
- autoload :Model, File.join(LIBRARY_PATH, 'model')
- autoload :Archive, File.join(LIBRARY_PATH, 'archive')
- autoload :CLI, File.join(LIBRARY_PATH, 'cli')
- autoload :Finder, File.join(LIBRARY_PATH, 'finder')
- autoload :Logger, File.join(LIBRARY_PATH, 'logger')
- autoload :Version, File.join(LIBRARY_PATH, 'version')
+ autoload :Model, File.join(LIBRARY_PATH, 'model')
+ autoload :Archive, File.join(LIBRARY_PATH, 'archive')
+ autoload :CLI, File.join(LIBRARY_PATH, 'cli')
+ autoload :Finder, File.join(LIBRARY_PATH, 'finder')
+ autoload :Dependency, File.join(LIBRARY_PATH, 'dependency')
+ autoload :Logger, File.join(LIBRARY_PATH, 'logger')
+ autoload :Version, File.join(LIBRARY_PATH, 'version')
##
# Autoload Backup configuration files
@@ -0,0 +1,84 @@
+# encoding: utf-8
+
+module Backup
+
+ ##
+ # A little self-contained gem manager for Backup.
+ # Rather than specifying hard dependencies in the gemspec, forcing users
+ # to install gems they do not want/need, Backup will notify them when a gem
+ # has not been installed, or when the gem's version is incorrect, and provide the
+ # command to install the gem. These dependencies are dynamically loaded in the Gemfile
+ class Dependency
+ extend Backup::CLI
+
+ ##
+ # Returns a hash of dependencies that Backup requires
+ # in order to run every available feature
+ def self.all
+ {
+ 'fog' => {
+ :require => 'fog',
+ :version => '~> 0.6.0',
+ :for => 'Amazon S3, Rackspace Cloud Files (S3, CloudFiles Storages)'
+ },
+
+ 'dropbox' => {
+ :require => 'dropbox',
+ :version => '~> 1.2.3',
+ :for => 'Dropbox Web Service (Dropbox Storage)'
+ },
+
+ 'net-sftp' => {
+ :require => 'net/sftp',
+ :version => '~> 2.0.5',
+ :for => 'SFTP Protocol (SFTP Storage)'
+ },
+
+ 'net-scp' => {
+ :require => 'net/scp',
+ :version => '~> 1.0.4',
+ :for => 'SCP Protocol (SCP Storage)'
+ },
+
+ 'net-ssh' => {
+ :require => 'net/ssh',
+ :version => '~> 2.1.3',
+ :for => 'SSH Protocol (SSH Storage)'
+ },
+
+ 'mail' => {
+ :require => 'mail',
+ :version => '~> 2.2.15',
+ :for => 'Sending Emails (Mail Notifier)'
+ },
+
+ 'twitter' => {
+ :require => 'twitter',
+ :version => '~> 1.1.2',
+ :for => 'Send Twitter Updates (Twitter Notifier)'
+ }
+ }
+ end
+
+ ##
+ # Attempts to load the specified gem (by name and version).
+ # If the gem with the correct version cannot be found, it'll display a message
+ # to the user with instructions on how to install the required gem
+ def self.load(name)
+ begin
+ gem(name, all[name][:version])
+ require(all[name][:require])
+ rescue LoadError
+ Backup::Logger.error("Dependency missing. Please install #{name} version #{all[name][:version]} and try again.")
+ puts "\n\s\sgem install #{name} -v '#{all[name][:version]}'\n\n"
+ puts "Dependency required for:"
+ puts "\n\s\s#{all[name][:for]}"
+ puts "\nTrying to install the #{name} gem for you.. please wait."
+ puts "Once installed, retry the backup procedure.\n\n"
+ puts run("#{ utility(:gem) } install #{name} -v '#{all[name][:version]}'")
+ exit
+ end
+ end
+
+ end
+end
@@ -2,7 +2,7 @@
##
# Only load the Mail gem and Erb library when using Mail notifications
-require 'mail'
+Backup::Dependency.load('mail')
require 'erb'
module Backup
@@ -2,7 +2,7 @@
##
# Only load the Twitter gem when using Twitter notifications
-require 'twitter'
+Backup::Dependency.load('twitter')
module Backup
module Notifier
@@ -2,7 +2,7 @@
##
# Only load the Fog gem when the Backup::Storage::CloudFiles class is loaded
-require 'fog'
+Backup::Dependency.load('fog')
module Backup
module Storage
@@ -2,7 +2,7 @@
##
# Only load the Dropbox gem when the Backup::Storage::Dropbox class is loaded
-require 'dropbox'
+Backup::Dependency.load('dropbox')
module Backup
module Storage
@@ -2,7 +2,7 @@
##
# Only load the Net::SSH library when the Backup::Storage::RSync class is loaded
-require 'net/ssh'
+Backup::Dependency.load('net-ssh')
module Backup
module Storage
@@ -2,7 +2,7 @@
##
# Only load the Fog gem when the Backup::Storage::S3 class is loaded
-require 'fog'
+Backup::Dependency.load('fog')
module Backup
module Storage
@@ -3,8 +3,9 @@
##
# Only load the Net::SSH and Net::SCP library/gems
# when the Backup::Storage::SCP class is loaded
-require 'net/ssh'
-require 'net/scp'
+Backup::Dependency.load('net-ssh')
+Backup::Dependency.load('net-scp')
+
module Backup
module Storage
@@ -2,7 +2,7 @@
##
# Only load the Net::SFTP library/gem when the Backup::Storage::SFTP class is loaded
-require 'net/sftp'
+Backup::Dependency.load('net-sftp')
module Backup
module Storage
@@ -13,7 +13,7 @@ class Version
# Defines the minor version
# PATCH:
# Defines the patch version
- MAJOR, MINOR, PATCH = 3, 0, 7
+ MAJOR, MINOR, PATCH = 3, 0, 8
##
# Returns the major version ( big release based off of multiple minor releases )

0 comments on commit 45f76d8

Please sign in to comment.