ddollar-github-backup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Dollar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = github-backup
2
+
3
+ Back up your Github repositories locally.
4
+
5
+ To install it as a Gem, just run:
6
+
7
+ $ sudo gem install ddollar-github-backup
8
+
9
+ To use it:
10
+
11
+ $ github-backup /path/to/my/backup/root
12
+
13
+ == Authenticated Usage
14
+
15
+ === Seamless authentication using .gitconfig defaults
16
+
17
+ You will need a <tt>~/.gitconfig</tt> file in place with a [github] section
18
+ See: http://github.com/guides/tell-git-your-user-name-and-email-address)
19
+
20
+ == Author
21
+
22
+ * David Dollar - http://daviddollar.org
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2009 David Dollar. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "github-backup"
8
+ gem.summary = %Q{Backup your Github repositories}
9
+ gem.email = "<ddollar@gmail.com>"
10
+ gem.homepage = "http://github.com/ddollar/github-backup"
11
+ gem.authors = ["David Dollar"]
12
+ gem.add_runtime_dependency 'ddollar-octopi', '= 0.0.13'
13
+ gem.default_executable = 'github-backup'
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION.yml')
46
+ config = YAML.load(File.read('VERSION.yml'))
47
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "github-backup #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
57
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/github-backup ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'octopi'
6
+ require 'github-backup'
7
+
8
+ unless ARGV.length == 1
9
+ puts "usage: github-backup <local backup root>"
10
+ exit 1
11
+ end
12
+
13
+ backup = Github::Backup.new(ARGV.first)
14
+ backup.execute
@@ -0,0 +1,69 @@
1
+ require 'octopi'
2
+ require 'pp'
3
+
4
+ module Github; end
5
+
6
+ class Github::Backup
7
+
8
+ include Octopi
9
+
10
+ attr_reader :backup_root, :debug
11
+
12
+ def initialize(backup_root)
13
+ @backup_root = backup_root
14
+ @debug = false
15
+ end
16
+
17
+ def execute
18
+ FileUtils::mkdir_p(backup_root)
19
+ authenticated do |api|
20
+ repositories = User.find('ddollar').repositories.sort_by { |r| r.name }
21
+ repositories.each do |repository|
22
+ puts "Backing up: #{repository.name}"
23
+ backup_repository repository
24
+ end
25
+ end
26
+ rescue Errno::ENOENT
27
+ puts "Please install git and create a ~/.gitconfig"
28
+ puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
29
+ rescue NoMethodError
30
+ puts "Please add a [github] section to your ~/.gitconfig"
31
+ puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
32
+ end
33
+
34
+ private ######################################################################
35
+
36
+ def backup_directory_for(repository)
37
+ File.join(backup_root, repository.name)
38
+ end
39
+
40
+ def backup_repository(repository)
41
+ if File.exists?(backup_directory_for(repository))
42
+ backup_repository_incremental(repository)
43
+ else
44
+ backup_repository_initial(repository)
45
+ end
46
+ end
47
+
48
+ def backup_repository_initial(repository)
49
+ FileUtils::cd(backup_root) do
50
+ shell("git clone -n #{repository.clone_url}")
51
+ end
52
+ end
53
+
54
+ def backup_repository_incremental(repository)
55
+ FileUtils::cd(backup_directory_for(repository)) do
56
+ shell("git remote update")
57
+ end
58
+ end
59
+
60
+ def shell(command)
61
+ puts "EXECUTING: #{command}" if debug
62
+ IO.popen(command, 'r') do |io|
63
+ output = io.read
64
+ puts "OUTPUT:" if debug
65
+ puts output if debug
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class GithubBackupTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'github-backup'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddollar-github-backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Dollar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-14 00:00:00 -07:00
13
+ default_executable: github-backup
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ddollar-octopi
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.13
24
+ version:
25
+ description:
26
+ email: <ddollar@gmail.com>
27
+ executables:
28
+ - github-backup
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/github-backup
42
+ - lib/github-backup.rb
43
+ - test/github-backup_test.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: false
46
+ homepage: http://github.com/ddollar/github-backup
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Backup your Github repositories
71
+ test_files:
72
+ - test/github-backup_test.rb
73
+ - test/test_helper.rb