archive_uploader 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/archive_uploader.gemspec +27 -0
- data/bin/archive_uploader +13 -0
- data/lib/archive_uploader.rb +19 -0
- data/lib/archive_uploader/archiver.rb +13 -0
- data/lib/archive_uploader/curb.rb +20 -0
- data/lib/archive_uploader/git.rb +35 -0
- data/lib/archive_uploader/version.rb +3 -0
- data/spec/archive_uploader/curb_spec.rb +49 -0
- data/spec/spec_helper.rb +8 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80360d8abb17e9bbde3e25349e8145ac432585e0
|
4
|
+
data.tar.gz: cc4a59de582c5fd1261a3393a8e0ea0ce3700e30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 137e82ad25ca995a4ab817430a7ddeb05dc00baa0f11fb0ac49bc51ace759a6b8e5ed58a42f5ce0a0ec2afe315d8cf36ba5bc1fd6aed52b1602110ac6ac9173b
|
7
|
+
data.tar.gz: e96dff9d6cc760b16d7db8e0860675c63103cf53400651b800c6ebb7ca77b6a04191134c82dbec06dc93a2fb46ac8ee72d865f8eaab8fc4d96d2f580eb33d905
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Teodor Pripoae
|
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
|
+
# ArchiveUploader
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'archive_uploader'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install archive_uploader
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
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"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'archive_uploader/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "archive_uploader"
|
8
|
+
spec.version = ArchiveUploader::VERSION
|
9
|
+
spec.authors = ["Teodor Pripoae"]
|
10
|
+
spec.email = ["teodor.pripoae@gmail.com"]
|
11
|
+
spec.description = %q{Upload stats to stat_fu webserver}
|
12
|
+
spec.summary = %q{Upload stats to stat_fu webserver}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.add_development_dependency "bundler", "~> 1.3"
|
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
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# resolve bin path, ignoring symlinks
|
5
|
+
require "pathname"
|
6
|
+
bin_file = Pathname.new(__FILE__).realpath
|
7
|
+
|
8
|
+
# add self to libpath
|
9
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
10
|
+
|
11
|
+
# start up the CLI
|
12
|
+
require "archive_uploader"
|
13
|
+
ArchiveUploader.start(*ARGV)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'curl'
|
2
|
+
require 'tempfile'
|
3
|
+
require "archive_uploader/archiver"
|
4
|
+
require "archive_uploader/curb"
|
5
|
+
require "archive_uploader/git"
|
6
|
+
require "archive_uploader/version"
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
module ArchiveUploader
|
10
|
+
module_function
|
11
|
+
def start(*args)
|
12
|
+
puts "Start uploading files"
|
13
|
+
@file = Archiver.new(:files => args).perform!
|
14
|
+
@git_data = Git.data
|
15
|
+
Curb.new(:file => @file.path, :fields => @git_data, :url => ENV["STAT_FU_URL"]).perform!
|
16
|
+
ensure
|
17
|
+
FileUtils.rm(@file)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ArchiveUploader
|
2
|
+
class Archiver
|
3
|
+
def initialize(options={})
|
4
|
+
@files = options[:files] || []
|
5
|
+
@archive_file = options[:name] || Tempfile.new(["archive_uploader", ".tgz"])
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform!
|
9
|
+
`tar -czf #{@archive_file.path} #{@files.join(" ")}`
|
10
|
+
@archive_file
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ArchiveUploader
|
2
|
+
class Curb
|
3
|
+
def initialize(options={})
|
4
|
+
@options = options
|
5
|
+
@curl = Curl::Easy.new(@options[:url])
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform!
|
9
|
+
@curl.multipart_form_post = true
|
10
|
+
@curl.http_post(*post_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post_data
|
14
|
+
fields = @options[:fields].collect do |field, value|
|
15
|
+
Curl::PostField.content("file[#{field}]", value)
|
16
|
+
end
|
17
|
+
[Curl::PostField.file('file[file]', @options[:file])] + fields
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ArchiveUploader
|
2
|
+
module Git
|
3
|
+
class << self
|
4
|
+
def get_timestamp
|
5
|
+
`git --no-pager show -s --format='%ai' #{get_commit} | awk '{print $2, $3}' | sed 's/-//g;s/://g;s/ //g'`.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_author_name
|
9
|
+
`git --no-pager show -s --format='%an' #{get_commit}`.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_author_email
|
13
|
+
`git --no-pager show -s --format='%ae' #{get_commit}`.strip
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_commit
|
17
|
+
`git rev-parse HEAD`.strip
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_branch
|
21
|
+
`git rev-parse --abbrev-ref HEAD`.strip
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
{
|
26
|
+
:commit => get_commit,
|
27
|
+
:timestamp => get_timestamp,
|
28
|
+
:branch => get_branch,
|
29
|
+
:author_name => get_author_name,
|
30
|
+
:author_email => get_author_email
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArchiveUploader::Curb do
|
4
|
+
before :each do
|
5
|
+
@tmpfile = Tempfile.new("foo")
|
6
|
+
@url = "http://example.com/upload"
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
FileUtils.rm(@tmpfile)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets @curl instance" do
|
14
|
+
curb = ArchiveUploader::Curb.new(:url => @url, :file => @tmpfile)
|
15
|
+
curb.instance_variable_get("@curl").should be_an_instance_of(Curl::Easy)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets @options" do
|
19
|
+
curb = ArchiveUploader::Curb.new(:url => @url, :file => @tmpfile)
|
20
|
+
options = curb.instance_variable_get("@options")
|
21
|
+
options[:url].should eql(@url)
|
22
|
+
options[:file].should eq(@tmpfile)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "post data" do
|
26
|
+
before :each do
|
27
|
+
@fields = {:branch => "master", :commit => "12345abc"}
|
28
|
+
@curb = ArchiveUploader::Curb.new(:url => @url, :file => @tmpfile, :fields => @fields)
|
29
|
+
@data = @curb.post_data
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns file field as first argument" do
|
33
|
+
file_field = @data.first
|
34
|
+
file_field.should be_an_instance_of(Curl::PostField)
|
35
|
+
file_field.name.should eql("file[file]")
|
36
|
+
file_field.local_file.should eq(@tmpfile)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns rest of fields" do
|
40
|
+
@data.shift
|
41
|
+
@fields.each_with_index do |(key, value), index|
|
42
|
+
field = @data[index]
|
43
|
+
field.should be_an_instance_of(Curl::PostField)
|
44
|
+
field.name.should eql("file[#{key}]")
|
45
|
+
field.content.should eql(value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: archive_uploader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Teodor Pripoae
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-18 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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: 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
|
+
description: Upload stats to stat_fu webserver
|
98
|
+
email:
|
99
|
+
- teodor.pripoae@gmail.com
|
100
|
+
executables:
|
101
|
+
- archive_uploader
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .rspec
|
107
|
+
- Gemfile
|
108
|
+
- Guardfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- archive_uploader.gemspec
|
113
|
+
- bin/archive_uploader
|
114
|
+
- lib/archive_uploader.rb
|
115
|
+
- lib/archive_uploader/archiver.rb
|
116
|
+
- lib/archive_uploader/curb.rb
|
117
|
+
- lib/archive_uploader/git.rb
|
118
|
+
- lib/archive_uploader/version.rb
|
119
|
+
- spec/archive_uploader/curb_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: ''
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.0
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Upload stats to stat_fu webserver
|
145
|
+
test_files:
|
146
|
+
- spec/archive_uploader/curb_spec.rb
|
147
|
+
- spec/spec_helper.rb
|