archive_uploader 0.1.0 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a76e506b3fd29c8d67484dbe865c0af07ec42b93
4
- data.tar.gz: bf381c80762bb0b2bf2fc116ba534fa1c441d860
3
+ metadata.gz: 1107ecbcb18b38de6731e64ca3bd90e61b1f6ec5
4
+ data.tar.gz: 5adbcf5ff19e898e74bd1633a896c84f540ed4f6
5
5
  SHA512:
6
- metadata.gz: bd45bb4ec796b90ebf2c805485df1c18fddb628d49ea0b0ce4a22874b289a12334ff6a50f6cf3fc416144b02ce7d7eefa028baf6361a7495b183507eaecab66c
7
- data.tar.gz: 4001ff8ce55ebb46fafd7ae0fc391fa3d9b861ebc740fd26886a2e9ed8f23ad014a3cb3098f2fe54c28953870a9a21eeb637e7f99fea2b7d1b6338b6933a2d98
6
+ metadata.gz: 9a830ce2bf306e5c152cef5d21e896bd46aaa75c8f69c80c5e73b9e56e66468fc8e8d68f8bcc7b0970efd25348c283a758471841aac8e35b417e1b9ffa80078c
7
+ data.tar.gz: 95b6f09668382378c044ae155c4811a4281aaf127d087c02db4ec78e7f36f7ec421ae29c897cb5b43f537ed6e27eb4e2fc5d1cfcfcd8747078abfc5cb2cf9a8f
data/Gemfile CHANGED
@@ -3,4 +3,11 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in archive_uploader.gemspec
4
4
  gemspec
5
5
 
6
- gem 'curb'
6
+ gem 'curb'
7
+
8
+ group :development do
9
+ gem 'pry', :require => 'pry'
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'rspec'
13
+ end
data/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard :rspec do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
9
 
@@ -20,8 +20,4 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "guard"
25
- spec.add_development_dependency "guard-rspec"
26
- spec.add_development_dependency "pry"
27
23
  end
@@ -10,4 +10,6 @@ $:.unshift File.expand_path("../../lib", bin_file)
10
10
 
11
11
  # start up the CLI
12
12
  require "archive_uploader"
13
- ArchiveUploader.start(*ARGV)
13
+
14
+ options = ArchiveUploader::CLI.parse(ARGV)
15
+ ArchiveUploader.start(options)
@@ -1,21 +1,30 @@
1
1
  require 'curl'
2
+ require 'optparse'
3
+ require 'ostruct'
2
4
  require 'tempfile'
3
5
  require "archive_uploader/archiver"
4
6
  require "archive_uploader/curb"
5
7
  require "archive_uploader/git"
6
8
  require "archive_uploader/version"
7
- require 'pry'
9
+ require "archive_uploader/cli"
8
10
 
9
11
  module ArchiveUploader
10
12
  module_function
11
- def start(*args)
13
+ def start(options)
14
+ @options = options
15
+ puts get_url
12
16
  puts "Start uploading files"
13
- @file = Archiver.new(:files => args).perform!
17
+ @file = Archiver.new(:files => options.directories).perform!
14
18
  @git_data = Git.data
15
19
  # puts @git_data
16
- puts Curb.new(:file => @file.path, :fields => @git_data, :url => ENV["ARCHIVE_UPLOADER_URL"]).perform!
20
+ puts Curb.new(:file => @file.path, :fields => @git_data, :url => ENV["ARCHIVE_UPLOADER_URL"], :auth => options.auth).perform!
17
21
 
18
22
  ensure
19
23
  FileUtils.rm(@file)
20
24
  end
25
+
26
+
27
+ def get_url
28
+ ENV["ARCHIVE_UPLOADER_URL"] || @options.url
29
+ end
21
30
  end
@@ -0,0 +1,79 @@
1
+ module ArchiveUploader
2
+ AUTH_METHODS = [:basic]
3
+ class CLIError < StandardError; end
4
+ class CLI
5
+ # return a structure describing the options
6
+ def self.parse(args)
7
+ options = OpenStruct.new
8
+ options.directories = []
9
+ options.verbose = false
10
+ options.auth = OpenStruct.new
11
+
12
+ opt_parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: archive_uploader [options]"
14
+
15
+ opts.separator ""
16
+ opts.separator "Specific options:"
17
+
18
+ # Directory
19
+ opts.on("-d", "--directory PATH",
20
+ "Add directory to archive") do |dir|
21
+ options.directories << dir
22
+ end
23
+
24
+ # List of arguments.
25
+ opts.on("-D x,y,z", Array, "Add list of files/directories") do |list|
26
+ options.directories += list
27
+ end
28
+
29
+ # Optional argument; auth method
30
+ opts.on("-a", "--authmethod [TYPE]",
31
+ "Set auth method",
32
+ " (default disabled)") do |method|
33
+
34
+ raise CLIError unless AUTH_METHODS.include?(method.to_sym)
35
+ # Screw ruby object defining #method
36
+ options.auth._method = method.to_sym
37
+ end
38
+
39
+ # Optional argument; auth user
40
+ opts.on("-u", "--authuser [USER]",
41
+ "Set auth user",
42
+ " (default none)") do |user|
43
+ options.auth.user = user
44
+ end
45
+
46
+ # Optional argument; auth password
47
+ opts.on("-p", "--authpassword [PASSWORD]",
48
+ "Set auth password",
49
+ " (default none)") do |password|
50
+ options.auth.password = password
51
+ end
52
+
53
+ # Verbose
54
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
55
+ options.verbose = v
56
+ end
57
+
58
+ opts.separator ""
59
+ opts.separator "Common options:"
60
+
61
+ # No argument, shows at tail. This will print an options summary.
62
+ # Try it and see!
63
+ opts.on_tail("-h", "--help", "Show this message") do
64
+ puts opts
65
+ exit
66
+ end
67
+
68
+ # Another typical switch to print the version.
69
+ opts.on_tail("--version", "Show version") do
70
+ puts ArchiveUploder::VERSION.join('.')
71
+ exit
72
+ end
73
+ end
74
+
75
+ opt_parser.parse!(args)
76
+ options
77
+ end
78
+ end
79
+ end
@@ -3,12 +3,22 @@ module ArchiveUploader
3
3
  def initialize(options={})
4
4
  @options = options
5
5
  @curl = Curl::Easy.new(@options[:url])
6
+ check_for_auth
6
7
  end
7
8
 
8
9
  def perform!
9
10
  @curl.multipart_form_post = true
10
11
  @curl.http_post(*post_data)
11
12
  end
13
+
14
+ def check_for_auth
15
+ return unless @options[:auth]
16
+ if @options[:auth]._method == :basic
17
+ @curl.http_auth_types = :basic
18
+ @curl.username = @options[:auth].user
19
+ @curl.password = @options[:auth].password
20
+ end
21
+ end
12
22
 
13
23
  def post_data
14
24
  fields = @options[:fields].collect do |field, value|
@@ -17,4 +27,4 @@ module ArchiveUploader
17
27
  [Curl::PostField.file('file[file]', @options[:file])] + fields
18
28
  end
19
29
  end
20
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module ArchiveUploader
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArchiveUploader::CLI do
4
+ it "returns list of directories when sent with -D" do
5
+ @argv = ["-D", "spec,bin"]
6
+ opts = ArchiveUploader::CLI.parse(@argv)
7
+ opts.directories.should =~ ["spec", "bin"]
8
+ end
9
+
10
+ it "returns list of directories when sent with -d" do
11
+ @argv = ["-d", "spec", "-d", "bin"]
12
+ opts = ArchiveUploader::CLI.parse(@argv)
13
+ opts.directories.should =~ ["spec", "bin"]
14
+ end
15
+
16
+ it "sets auth.method to basic" do
17
+ @argv = ["-a", "basic"]
18
+ opts = ArchiveUploader::CLI.parse(@argv)
19
+ opts.auth._method.should eql(:basic)
20
+ end
21
+
22
+ it "sets auth.user to root" do
23
+ @argv = ["-u", "root"]
24
+ opts = ArchiveUploader::CLI.parse(@argv)
25
+ opts.auth.user.should eql("root")
26
+ end
27
+
28
+ it "sets auth.password to password" do
29
+ @argv = ["-p", "asdf"]
30
+ opts = ArchiveUploader::CLI.parse(@argv)
31
+ opts.auth.password.should eql("asdf")
32
+ end
33
+ end
@@ -46,4 +46,19 @@ describe ArchiveUploader::Curb do
46
46
  end
47
47
  end
48
48
  end
49
- end
49
+
50
+ describe "auth data" do
51
+ before :each do
52
+ @fields = {:branch => "master", :commit => "12345abc"}
53
+ @auth = OpenStruct.new(:_method => :basic, :user => "asdf", :password => "1234")
54
+ @curb = ArchiveUploader::Curb.new(:url => @url, :file => @tmpfile, :fields => @fields, :auth => @auth)
55
+ end
56
+
57
+ it "sets auth vars to curl object" do
58
+ @curl = @curb.instance_variable_get("@curl")
59
+ @curl.http_auth_types.should eql(1)
60
+ @curl.username.should eql("asdf")
61
+ @curl.password.should eql("1234")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe ArchiveUploader do
5
+ #it "sets basic methods (black box)" do
6
+ #@argv = ["-a", "basic", "-u", "user123", "-p", "sekret"]
7
+
8
+ #ArchiveUploader::Curb.any_instance.stub(:new) do
9
+ #@curl.http_auth_types.should eql(1)
10
+ #@curl.username.should eql("user123")
11
+ #@curl.password.should eql("sekret")
12
+ #end
13
+
14
+ #options = ArchiveUploader::CLI.parse(@argv)
15
+ #ArchiveUploader.start(options)
16
+ #end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archive_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Teodor Pripoae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-31 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,62 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
41
  description: Upload stats to stat_fu webserver
98
42
  email:
99
43
  - teodor.pripoae@gmail.com
@@ -113,10 +57,13 @@ files:
113
57
  - bin/archive_uploader
114
58
  - lib/archive_uploader.rb
115
59
  - lib/archive_uploader/archiver.rb
60
+ - lib/archive_uploader/cli.rb
116
61
  - lib/archive_uploader/curb.rb
117
62
  - lib/archive_uploader/git.rb
118
63
  - lib/archive_uploader/version.rb
64
+ - spec/archive_uploader/cli_spec.rb
119
65
  - spec/archive_uploader/curb_spec.rb
66
+ - spec/archive_uploader_spec.rb
120
67
  - spec/spec_helper.rb
121
68
  homepage: ''
122
69
  licenses:
@@ -143,5 +90,7 @@ signing_key:
143
90
  specification_version: 4
144
91
  summary: Upload stats to stat_fu webserver
145
92
  test_files:
93
+ - spec/archive_uploader/cli_spec.rb
146
94
  - spec/archive_uploader/curb_spec.rb
95
+ - spec/archive_uploader_spec.rb
147
96
  - spec/spec_helper.rb