github_downloader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6bde27212d1f9823b9bd580c9beb38134fb30b2f
4
+ data.tar.gz: 8598e26553c658c728e0e1b1e15f460e6cdac8da
5
+ SHA512:
6
+ metadata.gz: e671a044ab224e15ee2bf36c2679f4c0f1203c63af140d976604ee25f150563be73f43ca12cfaa9f9db3246559175b33c31ab0984296ccc9afa85d75ad77eaf2
7
+ data.tar.gz: 4ac523ecb512bfb0fec77ec4e977b928b071331ee8bcc9624153b642017c5fb4467f3b4517e6ccd8d7255cbe7f7822aaf39d0d93c6c9f7aa65551c1a6c6807de
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .idea/
20
+ testing/
21
+ github_downloader_error.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in github_downloader.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nacho L.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GithubDownloader
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'github_downloader'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install github_downloader
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/github_downloader/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ghdl ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'github_downloader'
4
+
5
+ begin
6
+ GithubDownloader.from_cmdline ARGV
7
+ rescue => e
8
+ abort e.message
9
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'github_downloader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "github_downloader"
8
+ spec.version = GithubDownloader::VERSION
9
+ spec.authors = ["Nacho Lopez"]
10
+ spec.email = ["nacho@nlopez.io"]
11
+ spec.summary = %q{Downloader for GitHub projects for users or organizations}
12
+ spec.description = %q{With this gem you can bulk download all the repositories from a single user or an organization, archived in zip files.}
13
+ spec.homepage = "http://github.com/mrmans0n/github-downloader"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.executables << "ghdl"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", "~> 0"
25
+
26
+ spec.required_ruby_version = ">= 1.9.2"
27
+
28
+ spec.add_dependency "github_api", "~> 0.11"
29
+ end
@@ -0,0 +1,75 @@
1
+ require 'github_downloader/version'
2
+ require 'fileutils'
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'pathname'
6
+ require 'securerandom'
7
+ require 'net/http'
8
+ require 'uri'
9
+ require 'github_api'
10
+ require 'github_downloader/parser'
11
+ require 'github_downloader/string'
12
+
13
+ module GithubDownloader
14
+
15
+ def self.show_error(error_string)
16
+ puts 'Error!'.red
17
+ puts error_string
18
+ exit
19
+ end
20
+
21
+ def self.run(command)
22
+ output = `#{command} 2> github_downloader_error.log`
23
+ if $?.exitstatus > 0
24
+ print "Failed!\n".red
25
+ puts output
26
+ exit(-1)
27
+ else
28
+ print "Done!\n".green
29
+ end
30
+ end
31
+
32
+ def self.from_cmdline(args)
33
+ show_error 'no options specified, try with --help and see all the available options' unless ARGV.size > 0
34
+
35
+ options = Parser.new do |p|
36
+ p.banner = 'GitHub Repo Downloader'
37
+ p.version = VERSION
38
+ p.option :username, 'Your GitHub user', :default => '', :short => 'u'
39
+ p.option :password, 'Your GitHub password', :default => '', :short => 'p'
40
+ p.option :organization, 'GitHub Organization (optional)', :default => '', :short => 'g'
41
+ p.option :from, 'GitHub user from which we want to download (optional)', :default => '', :short => 'r'
42
+ p.option :output, 'Output directory', :default => '.', :short => 'o'
43
+ end.process!
44
+
45
+ show_error 'no user specified, please check --help to see all available options' if options[:username].blank?
46
+ show_error 'no password specified, please check --help to see all available options' if options[:password].blank?
47
+ if (options[:organization].blank? && options[:from].blank?) || (!options[:organization].blank? && !options[:from].blank?)
48
+ show_error 'either an organization or an user must be provided to download repositories, not both or none'
49
+ end
50
+
51
+ output_dir = options[:output]
52
+ user = options[:username]
53
+ pass = options[:password]
54
+ organization = options[:organization]
55
+ user_repo = options[:from]
56
+
57
+ github = Github.new basic_auth: "#{user}:#{pass}" do |config|
58
+ config.org = organization
59
+ config.auto_pagination = true
60
+ end
61
+
62
+ FileUtils.makedirs output_dir if output_dir != '.'
63
+
64
+ # Either chose repos from an organization or an user
65
+ all_repos = github.repos.all unless organization.blank?
66
+ all_repos = github.repos.list user: user_repo unless user_repo.blank?
67
+
68
+ all_repos.each do |repo|
69
+ print "Downloading archive for #{repo.full_name}... "
70
+ Dir.chdir output_dir do
71
+ run "curl -i -u #{user}:#{pass} -o #{repo.name}-master-archived.zip -L #{repo.html_url}/archive/master.zip"
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,69 @@
1
+ class Parser
2
+ attr_accessor :banner, :version
3
+
4
+ def initialize
5
+ @options = []
6
+ @used_short = []
7
+ @default_values = nil
8
+ yield self if block_given?
9
+ end
10
+
11
+ def option(name, desc, settings = {})
12
+ @options << [name, desc, settings]
13
+ end
14
+
15
+ def short_from(name)
16
+ name.to_s.chars.each do |c|
17
+ next if @used_short.include?(c) || c == "_"
18
+ return c # returns from short_from method
19
+ end
20
+ end
21
+
22
+ def validate(options) # remove this method if you want fewer lines of code and don't need validations
23
+ options.each_pair do |key, value|
24
+ opt = @options.find_all { |o| o[0] == key }.first
25
+ key = "--" << key.to_s.gsub("_", "-")
26
+ unless opt[2][:value_in_set].nil? || opt[2][:value_in_set].include?(value)
27
+ puts "Parameter for #{key} must be in [" << opt[2][:value_in_set].join(", ") << "]"; exit(1)
28
+ end
29
+ unless opt[2][:value_matches].nil? || opt[2][:value_matches] =~ value
30
+ puts "Parameter for #{key} must match /" << opt[2][:value_matches].source << "/"; exit(1)
31
+ end
32
+ unless opt[2][:value_satisfies].nil? || opt[2][:value_satisfies].call(value)
33
+ puts "Parameter for #{key} must satisfy given conditions (see description)"; exit(1)
34
+ end
35
+ end
36
+ end
37
+
38
+ def process!(arguments = ARGV)
39
+ @result = (@default_values || {}).clone # reset or new
40
+ @optionparser ||= OptionParser.new do |p| # prepare only once
41
+ @options.each do |o|
42
+ @used_short << short = o[2][:short] || short_from(o[0])
43
+ @result[o[0]] = o[2][:default] || false # set default
44
+ klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
45
+
46
+ if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
47
+ p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), o[1]) { |x| @result[o[0]] = x }
48
+ else # argument with parameter
49
+ p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << o[2][:default].to_s, klass, o[1]) { |x| @result[o[0]] = x }
50
+ end
51
+ end
52
+
53
+ p.banner = @banner unless @banner.nil?
54
+ p.on_tail("-h", "--help", "Show this message") { puts p; exit }
55
+ short = @used_short.include?("v") ? "-V" : "-v"
56
+ p.on_tail(short, "--version", "Print version") { puts @version; exit } unless @version.nil?
57
+ @default_values = @result.clone # save default values to reset @result in subsequent calls
58
+ end
59
+
60
+ begin
61
+ @optionparser.parse!(arguments)
62
+ rescue OptionParser::ParseError => e
63
+ puts e.message; exit(1)
64
+ end
65
+
66
+ validate(@result) if self.respond_to?("validate")
67
+ @result
68
+ end
69
+ end
@@ -0,0 +1,37 @@
1
+ class String
2
+ def self.colorize(text, color_code)
3
+ "\e[#{color_code}m#{text}\e[0m"
4
+ end
5
+
6
+ def cyan
7
+ self.class.colorize(self, 36)
8
+ end
9
+
10
+ def green
11
+ self.class.colorize(self, 32)
12
+ end
13
+
14
+ def yellow
15
+ self.class.colorize(self, 33)
16
+ end
17
+
18
+ def red
19
+ self.class.colorize(self, 31)
20
+ end
21
+
22
+ def underscore
23
+ self.gsub(/::/, '/').
24
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
25
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
26
+ tr("-", "_").
27
+ downcase
28
+ end
29
+
30
+ def uncapitalize
31
+ self[0, 1].downcase + self[1..-1]
32
+ end
33
+
34
+ def blank?
35
+ self.nil? || self.empty?
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module GithubDownloader
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_downloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nacho Lopez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github_api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ description: With this gem you can bulk download all the repositories from a single
56
+ user or an organization, archived in zip files.
57
+ email:
58
+ - nacho@nlopez.io
59
+ executables:
60
+ - ghdl
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/ghdl
70
+ - github_downloader.gemspec
71
+ - lib/github_downloader.rb
72
+ - lib/github_downloader/parser.rb
73
+ - lib/github_downloader/string.rb
74
+ - lib/github_downloader/version.rb
75
+ homepage: http://github.com/mrmans0n/github-downloader
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.9.2
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Downloader for GitHub projects for users or organizations
99
+ test_files: []