depends-client 0.1 → 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -29
- data/bin/depend +1 -12
- data/lib/depends/cli.rb +51 -0
- data/lib/depends/commands/configure.rb +9 -0
- data/lib/depends/commands/install.rb +61 -47
- data/lib/depends/commands/list.rb +19 -0
- data/lib/depends/commands/upload.rb +29 -53
- data/lib/depends/commands/versions.rb +19 -0
- data/lib/depends/config.rb +10 -3
- data/lib/depends/definition.rb +1 -3
- data/lib/depends/dsl/depend.rb +2 -2
- data/lib/depends/rest_client.rb +50 -29
- data/lib/depends/util.rb +1 -3
- data/lib/depends.rb +4 -8
- metadata +84 -44
- data/lib/depends/command_factory.rb +0 -31
- data/lib/depends/commands/base.rb +0 -87
- data/lib/depends/log/formatter.rb +0 -41
- data/lib/depends/log.rb +0 -6
data/README.md
CHANGED
@@ -15,13 +15,17 @@ Depends is quite simple.
|
|
15
15
|
```bash
|
16
16
|
gem install depends-client
|
17
17
|
```
|
18
|
+
2. Setup ~/.depends/config.rb
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
```ruby
|
21
|
+
api_key '<YOUR KEY HERE>'
|
22
|
+
server 'https://depends.aws.af.cm'
|
23
|
+
```
|
22
24
|
|
23
|
-
|
25
|
+
3. Define a Depends file at the root of your source repository. The format is as follows:
|
26
|
+
As of this release <code>source</code> is not longer necessary. The default location is always used.
|
24
27
|
|
28
|
+
```ruby
|
25
29
|
depend 'Qt', :version => '4', :destination => 'External/Qt'
|
26
30
|
depend 'SevenZipSharp', :version => '4', :destination => 'External/SevenZipSharp'
|
27
31
|
depend 'Sqlite', :version => '4', :destination => 'External/Sqlite'
|
@@ -30,46 +34,24 @@ gem install depends-client
|
|
30
34
|
|
31
35
|
```
|
32
36
|
|
33
|
-
_source_ defines that location of the depends server. Currently :local, :depends, or a string to some other depends
|
34
|
-
server, i.e. http://example.com.
|
35
|
-
|
36
37
|
_depend_ defines what the dependency is, the version to install and the path to unpack it to
|
37
38
|
|
38
|
-
|
39
|
+
4. Execute Depends
|
39
40
|
```bash
|
40
41
|
depend
|
41
42
|
```
|
42
43
|
|
43
|
-
|
44
|
+
5. Add your Depends file to source control
|
44
45
|
|
45
46
|
_We also recomend that you add depends destinations to your gitignore and hgignore files._
|
46
47
|
|
47
48
|
Your done, packages are download, extracted and installed per the instructions in your gem file
|
48
49
|
|
49
50
|
|
50
|
-
Uploading A Dependency
|
51
|
-
----------------------
|
52
|
-
This tutorial does not cover installing a depends server, but asuming that you have a depends server setup, adding a new
|
53
|
-
dependency is simple.
|
54
|
-
|
55
|
-
1. Install Depends
|
56
|
-
|
57
|
-
```bash
|
58
|
-
gem install depends
|
59
|
-
````
|
60
|
-
2. Setup a directory that models what you want to upload. I.e. Create /tmp/openssl and add some files to it.
|
61
|
-
3. Package and upload
|
62
|
-
|
63
|
-
```bash
|
64
|
-
depend upload -s /tmp/openssl -d 'depends' -n "OpenSSL" -v '1.2.3b'
|
65
|
-
```
|
66
|
-
|
67
|
-
That's it, your package is created and uploaded to the depends server.
|
68
|
-
|
69
51
|
The Future
|
70
52
|
==========
|
71
53
|
* Polish the client a bit further
|
72
54
|
* Better error handling
|
73
|
-
* Auto Updating of .gitignore and .hgignore files based on your Depends
|
55
|
+
* <s>Auto Updating of .gitignore and .hgignore files based on your Depends</s>
|
74
56
|
* Windows support
|
75
57
|
* Rake tasks
|
data/bin/depend
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'depends'
|
4
|
-
|
5
|
-
begin
|
6
|
-
a = Depends::CommandFactory.build.new
|
7
|
-
a.run
|
8
|
-
rescue Depends::Exceptions::SubCommandMissing => e
|
9
|
-
Depends::Log.debug ("Exception: #{e.inspect}")
|
10
|
-
Depends::Log.fatal ("SubCommand is not defined #{e.message}")
|
11
|
-
Process.exit 1
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Depends::Log.debug ":total_runtime => #{time*1000} milliseconds"
|
4
|
+
require 'depends/cli'
|
16
5
|
|
17
6
|
|
data/lib/depends/cli.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'commander/import'
|
2
|
+
|
3
|
+
# :name is optional, otherwise uses the basename of this executable
|
4
|
+
program :name, 'depends'
|
5
|
+
program :version, '0.2.0'
|
6
|
+
program :description, 'Simple binary dependency management '
|
7
|
+
|
8
|
+
command :install do |c|
|
9
|
+
c.syntax = 'install'
|
10
|
+
c.description = 'Install application dependencies'
|
11
|
+
c.action do |args,options|
|
12
|
+
Depends::Commands::Install.new.run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
command :list do |c|
|
18
|
+
c.syntax = 'list'
|
19
|
+
c.description = 'List application dependencies'
|
20
|
+
c.action do |args,options|
|
21
|
+
Depends::Commands::List.new.run
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
command :versions do |c|
|
26
|
+
c.syntax = 'versions'
|
27
|
+
c.description = 'List version if an application'
|
28
|
+
c.action do |args,options|
|
29
|
+
Depends::Commands::Versions.new.run(args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
command :upload do |c|
|
35
|
+
c.syntax = 'upload'
|
36
|
+
c.description = 'Upload a dependency to the server'
|
37
|
+
c.option '--source DIR', String, 'Directory to be uploaded'
|
38
|
+
c.option '--name NAME', String, 'Name of the dependency'
|
39
|
+
c.option '--num VERSION', String, 'Version String'
|
40
|
+
c.option '--create','Create if does not exist'
|
41
|
+
c.option '--description', String, 'Description of the dependency'
|
42
|
+
c.action do |args,options|
|
43
|
+
|
44
|
+
options.source = ask("Source Directory: ") unless options.source
|
45
|
+
options.name = ask("Dependency Name: ") unless options.dep
|
46
|
+
options.num = ask("Version Number: ") unless options.num
|
47
|
+
options.description = ask("Description:") if not options.description and options.create
|
48
|
+
|
49
|
+
Depends::Commands::Upload.new.run(options)
|
50
|
+
end
|
51
|
+
end
|
@@ -1,77 +1,85 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
module Depends
|
3
3
|
module Commands
|
4
|
-
class Install
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def setup_application
|
15
|
-
Log.info "Installing dependencies..."
|
4
|
+
class Install
|
5
|
+
|
6
|
+
def run
|
7
|
+
Depends::Config.load
|
8
|
+
say 'Installing Dependencies...'
|
9
|
+
check_for_file
|
10
|
+
load_depends_file
|
11
|
+
download_extract
|
12
|
+
link
|
13
|
+
update_ignores
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
Depends::Log.debug ":check_for_file => #{time*1000} milliseconds"
|
24
|
-
|
25
|
-
time = Benchmark.realtime do
|
26
|
-
load_depends_file
|
16
|
+
private
|
17
|
+
def check_for_file
|
18
|
+
unless Dir.entries(Dir.pwd).include?('Depends')
|
19
|
+
color "Missing Depends file", :red
|
20
|
+
exit 1
|
27
21
|
end
|
28
|
-
|
22
|
+
end
|
29
23
|
|
30
|
-
|
31
|
-
|
24
|
+
def update_ignores
|
25
|
+
if File.exist?('.git')
|
26
|
+
file = '.gitignore'
|
27
|
+
elsif File.exists?('.hg')
|
28
|
+
file = '.hgignore'
|
29
|
+
else
|
30
|
+
file = nil
|
32
31
|
end
|
33
|
-
Depends::Log.debug ":download_extract => #{time*1000} milliseconds"
|
34
32
|
|
35
|
-
|
36
|
-
|
33
|
+
say "Updating #{file} with external dependencies..." if file
|
34
|
+
unless file.nil?
|
35
|
+
FileUtils.touch(file) unless File.exist? file
|
36
|
+
ignore_file = File.read(file)
|
37
|
+
ignore = files_to_ignore
|
38
|
+
ignore_file.each_line do |line|
|
39
|
+
if ignore.include? line.chomp
|
40
|
+
ignore.delete(line.chomp)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
File.open(file, 'a') { |f|
|
44
|
+
ignore.each do |i|
|
45
|
+
f.puts ""
|
46
|
+
f.puts i
|
47
|
+
end
|
48
|
+
}
|
37
49
|
end
|
38
|
-
Depends::Log.debug ":link => #{time*1000} milliseconds"
|
39
|
-
|
40
50
|
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
unless Dir.entries(Dir.pwd).include?('Depends')
|
45
|
-
Depends::Log.error "Missing Depends file"
|
46
|
-
exit 1
|
47
|
-
end
|
52
|
+
def files_to_ignore
|
53
|
+
@def.dependencies.collect { |d| d[:destination] }
|
48
54
|
end
|
49
55
|
|
56
|
+
|
50
57
|
def load_depends_file
|
51
|
-
|
58
|
+
say "Loading Dependencies..."
|
52
59
|
@def = Depends::DSL::Depend.evaluate('Depends')
|
53
60
|
unless @def.unmet_dependencies.empty?
|
54
|
-
|
61
|
+
color "You have unmet dependencies in your sources, #{@def.unmet_dependencies.inspect}", :red
|
55
62
|
Process.exit 1
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
59
66
|
|
60
67
|
def download_extract
|
61
|
-
|
68
|
+
say "Downloading and extracting missing dependencies..."
|
62
69
|
@def.dependencies.each do |dep|
|
63
|
-
|
64
|
-
|
70
|
+
file_name = "#{dep[:name]}-#{dep['number']}.zip"
|
71
|
+
cache_file = File.join(Depends::Config.cache,file_name)
|
72
|
+
cache_directory = File.join(Depends::Config.cache,File.basename(file_name,'.zip'))
|
65
73
|
|
66
74
|
unless File.exist?(cache_file) # and Digest::SHA1.file(cache_file).to_s.eql? dep["sha1"]
|
67
|
-
|
75
|
+
say "Downloading #{dep[:name]}..."
|
68
76
|
just_downloaded = true
|
69
77
|
dep[:source].download_depend_version(dep[:name],dep["number"])
|
70
78
|
end
|
71
79
|
|
72
80
|
if just_downloaded or not File.exist? cache_directory
|
73
|
-
|
74
|
-
Util.un_zip(cache_file,cache_directory)
|
81
|
+
say "Extracting #{cache_file}"
|
82
|
+
Util.un_zip(cache_file,cache_directory)
|
75
83
|
end
|
76
84
|
|
77
85
|
end
|
@@ -79,12 +87,18 @@ module Depends
|
|
79
87
|
|
80
88
|
def link
|
81
89
|
@def.dependencies.each do |dep|
|
82
|
-
source = File.join(Depends::Config.cache,File.basename(dep["
|
90
|
+
source = File.join(Depends::Config.cache,File.basename("#{dep[:name]}-#{dep['number']}",'.zip'))
|
83
91
|
base_dir = File.dirname(dep[:destination])
|
84
92
|
FileUtils.mkdir_p(base_dir) unless File.exist? base_dir
|
85
|
-
|
86
|
-
|
87
|
-
|
93
|
+
say "Linking #{source} to #{dep[:destination]}"
|
94
|
+
|
95
|
+
if RUBY_PLATFORM =~ /mingw32|mswin32/
|
96
|
+
Dir.delete dep[:destination] if File.exist? dep[:destination]
|
97
|
+
Dir.create_junction(dep[:destination], source)
|
98
|
+
else
|
99
|
+
FileUtils.rm(dep[:destination]) if File.exist? dep[:destination]
|
100
|
+
FileUtils.symlink(source, dep[:destination])
|
101
|
+
end
|
88
102
|
end
|
89
103
|
end
|
90
104
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module Depends
|
3
|
+
module Commands
|
4
|
+
class List
|
5
|
+
|
6
|
+
def run
|
7
|
+
Depends::Config.load
|
8
|
+
client = Depends::RestClient.new()
|
9
|
+
deps = client.list
|
10
|
+
headers = ['Name','Description']
|
11
|
+
rows = deps.collect{ |i| [i['name'] ,i['description']] }
|
12
|
+
table = Terminal::Table.new :title => "Dependencies", :headings => headers, :rows => rows
|
13
|
+
puts table
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,75 +1,51 @@
|
|
1
1
|
module Depends
|
2
2
|
module Commands
|
3
|
-
class Upload
|
3
|
+
class Upload
|
4
4
|
|
5
|
-
class UploadConfig
|
6
|
-
extend(Mixlib::Config)
|
7
|
-
end
|
8
|
-
|
9
|
-
banner "Upload a dependency to a depends server"
|
10
|
-
|
11
|
-
option :source,
|
12
|
-
:short => "-s source",
|
13
|
-
:long => "--source source",
|
14
|
-
:description => "Source directory for dependency",
|
15
|
-
:required => true
|
16
|
-
|
17
|
-
option :name,
|
18
|
-
:short => "-n name",
|
19
|
-
:long => "--name name",
|
20
|
-
:description => "Dependency Name",
|
21
|
-
:required => true
|
22
|
-
|
23
|
-
option :version,
|
24
|
-
:short => "-v version",
|
25
|
-
:long => "--version version",
|
26
|
-
:description => "Version to publish",
|
27
|
-
:required => true
|
28
|
-
|
29
|
-
option :destination,
|
30
|
-
:short => "-d destination",
|
31
|
-
:long => "--destination destination",
|
32
|
-
:description => "Destination to publish depend to",
|
33
|
-
:default => 'https://depends.io',
|
34
|
-
:proc => Proc.new { |o|
|
35
|
-
Depends::Util.depends_source o
|
36
|
-
}
|
37
|
-
|
38
|
-
option :log_level,
|
39
|
-
:short => "-l LEVEL",
|
40
|
-
:long => "--log_level LEVEL",
|
41
|
-
:description => "Set the log level (debug, info, warn, error, fatal)",
|
42
|
-
:proc => Proc.new { |l| l.downcase.to_sym }
|
43
5
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def run_application
|
49
|
-
client = Depends::RestClient.new(config[:destination])
|
6
|
+
def run(options)
|
7
|
+
Depends::Config.load
|
8
|
+
client = Depends::RestClient.new
|
9
|
+
puts "CREATE: #{options.create}"
|
50
10
|
|
51
11
|
begin
|
52
|
-
@dep = client.get_depend(
|
12
|
+
@dep = client.get_depend(options.dep)
|
53
13
|
rescue Nestful::ResourceNotFound => e
|
54
|
-
|
14
|
+
if options.create
|
15
|
+
say("Creating dependency")
|
16
|
+
@dep = client.create_depend(options.dep,options.description)
|
17
|
+
|
18
|
+
else
|
19
|
+
color("Dependency does not exist and --create flag was not specified", :red)
|
20
|
+
exit 1
|
21
|
+
end
|
55
22
|
end
|
56
23
|
|
57
|
-
file = build_package
|
24
|
+
file = build_package(options)
|
58
25
|
sha1 = Digest::SHA1.file(file).to_s
|
59
26
|
|
60
|
-
if @dep['versions'].select { |v| v.eql?
|
61
|
-
|
27
|
+
if @dep['versions'].select { |v| v.eql? options.num }.empty?
|
28
|
+
puts "File #{file}"
|
29
|
+
puts "SHA #{sha1}"
|
30
|
+
puts "Number #{options.num}"
|
31
|
+
begin
|
32
|
+
client.create_version(@dep['name'], :file => file, :sha1 => sha1, :number => options.num)
|
33
|
+
rescue Nestful::BadRequest => e
|
34
|
+
color(e.response.body, :red)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
color("Dependency already exists!", :red)
|
62
38
|
end
|
63
39
|
end
|
64
40
|
|
65
41
|
private
|
66
42
|
|
67
|
-
def build_package
|
43
|
+
def build_package(options)
|
68
44
|
upload_dir = File.join(Depends::Config.cache,'upload')
|
69
45
|
FileUtils.mkdir_p upload_dir unless File.exist? upload_dir
|
70
|
-
dest_file = File.join(upload_dir, "#{
|
46
|
+
dest_file = File.join(upload_dir, "#{options.dep}-#{options.num}.zip")
|
71
47
|
FileUtils.rm dest_file if File.exist? dest_file
|
72
|
-
source_path = File.expand_path(
|
48
|
+
source_path = File.expand_path(options.source)
|
73
49
|
Zip::ZipFile.open(dest_file, Zip::ZipFile::CREATE) { |zipfile|
|
74
50
|
Dir["#{source_path}/**/*"].each do |file|
|
75
51
|
relative_path = file.to_s.gsub(source_path, '')
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module Depends
|
3
|
+
module Commands
|
4
|
+
class Versions
|
5
|
+
|
6
|
+
def run(depend)
|
7
|
+
Depends::Config.load
|
8
|
+
client = Depends::RestClient.new()
|
9
|
+
dep = client.get_depend(depend[0])
|
10
|
+
|
11
|
+
headers = ['Version Number','SHA1', 'Publisher Address']
|
12
|
+
rows = dep['versions'].collect{ |i| [i['number'] ,i['sha1'],i['publisher']] }
|
13
|
+
table = Terminal::Table.new :title => "Versions for #{depend[0]}", :headings => headers, :rows => rows
|
14
|
+
puts table
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/depends/config.rb
CHANGED
@@ -2,6 +2,13 @@ module Depends
|
|
2
2
|
class Config
|
3
3
|
extend(Mixlib::Config)
|
4
4
|
|
5
|
-
cache File.expand_path('~/.
|
6
|
-
|
7
|
-
|
5
|
+
cache File.expand_path('~/.depends')
|
6
|
+
api_key ''
|
7
|
+
server 'https://depends.aws.af.cm'
|
8
|
+
|
9
|
+
def self.load(file = '~/.depends/config.rb')
|
10
|
+
config_file = File.expand_path(file)
|
11
|
+
Depends::Config.from_file(config_file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/depends/definition.rb
CHANGED
@@ -14,7 +14,6 @@ module Depends
|
|
14
14
|
def map(deps)
|
15
15
|
@dependencies = []
|
16
16
|
@unmet_dependencies = []
|
17
|
-
Log.debug " :definition => #{@def.inspect}"
|
18
17
|
deps.each do |dep|
|
19
18
|
dependency_met = false
|
20
19
|
sources.each do |source|
|
@@ -23,11 +22,10 @@ module Depends
|
|
23
22
|
server_dep[:source] = source
|
24
23
|
server_dep[:destination] = dep[:destination]
|
25
24
|
server_dep[:name] = dep[:name]
|
26
|
-
Log.debug ":server_dep => #{server_dep}"
|
27
25
|
@dependencies << server_dep
|
28
26
|
dependency_met = true
|
29
27
|
rescue Nestful::ResourceNotFound => e
|
30
|
-
|
28
|
+
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
data/lib/depends/dsl/depend.rb
CHANGED
@@ -13,7 +13,7 @@ module Depends
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize
|
16
|
-
@sources = []
|
16
|
+
@sources = [Depends::RestClient.new]
|
17
17
|
@dependencies = []
|
18
18
|
end
|
19
19
|
|
@@ -44,7 +44,7 @@ module Depends
|
|
44
44
|
|
45
45
|
private
|
46
46
|
def depends_source(source)
|
47
|
-
|
47
|
+
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
data/lib/depends/rest_client.rb
CHANGED
@@ -1,41 +1,69 @@
|
|
1
1
|
require 'nestful'
|
2
|
+
require 'cgi'
|
3
|
+
require 'uri'
|
2
4
|
module Depends
|
3
5
|
class RestClient
|
4
6
|
|
5
7
|
attr_accessor :source_url
|
6
8
|
attr_reader :cache
|
7
9
|
|
8
|
-
def initialize
|
9
|
-
@source_url =
|
10
|
-
cache_path = File.join(Depends::Config.cache,'rest',URI.parse(
|
11
|
-
Depends::Log.debug ":cache_path => #{cache_path}"
|
10
|
+
def initialize
|
11
|
+
@source_url = Depends::Config.server
|
12
|
+
cache_path = File.join(Depends::Config.cache,'rest',URI.parse(source_url.to_s).host )
|
12
13
|
@cache = ActiveSupport::Cache::FileStore.new(cache_path, :expires_in => 1.day)
|
13
14
|
end
|
14
15
|
|
16
|
+
def headers
|
17
|
+
{'key' => Depends::Config.api_key}
|
18
|
+
end
|
19
|
+
|
15
20
|
def create_version(name,options = {})
|
16
|
-
|
21
|
+
Nestful.post "#{source_url}/depends/#{name}/version", :headers => headers, :format => :multipart, :timeout => 3600, :params => {:number => options[:number] , :file => File.open(options[:file]), :sha1 => options[:sha1] }
|
17
22
|
end
|
18
23
|
|
19
|
-
def create_depend(name)
|
20
|
-
Nestful.post "#{source_url}/
|
24
|
+
def create_depend(name,description)
|
25
|
+
depend = Nestful.post "#{source_url}/depends", :headers => headers, :format => :json, :params => {:name => name, :description => description}
|
26
|
+
depend
|
21
27
|
end
|
22
28
|
|
23
29
|
def get_depend(name)
|
24
|
-
uri = "#{source_url}/
|
25
|
-
depend =
|
26
|
-
if depend.nil?
|
27
|
-
depend = Nestful.get uri, :format => :json
|
28
|
-
cache.write(uri,depend.to_json)
|
29
|
-
else
|
30
|
-
depend = ::MultiJson.load(depend)
|
31
|
-
end
|
30
|
+
uri = "#{source_url}/depends/#{name}"
|
31
|
+
depend = Nestful.get uri, :format => :json, :headers => headers
|
32
32
|
depend
|
33
33
|
end
|
34
34
|
|
35
35
|
def download_depend_version(name,version)
|
36
36
|
dest_file = File.join(Depends::Config.cache, "#{name}-#{version}.zip")
|
37
|
-
|
38
|
-
|
37
|
+
|
38
|
+
request = Nestful.get "#{source_url}/depends/#{name}/version/#{version}/download.url", :headers => headers
|
39
|
+
uri = URI.parse(request)
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
http.request_get("#{uri.path}#{'?' + uri.query if uri.query}") do |response|
|
44
|
+
temp_file = Tempfile.new("download")
|
45
|
+
temp_file.binmode
|
46
|
+
|
47
|
+
size = 0
|
48
|
+
progress = 0
|
49
|
+
total = response.header["Content-Length"].to_i
|
50
|
+
|
51
|
+
response.read_body do |chunk|
|
52
|
+
temp_file << chunk
|
53
|
+
size += chunk.size
|
54
|
+
new_progress = (size * 100) / total
|
55
|
+
unless new_progress == progress
|
56
|
+
say "\rDownloading %s (%3d%%) " % [name, new_progress]
|
57
|
+
end
|
58
|
+
progress = new_progress
|
59
|
+
end
|
60
|
+
|
61
|
+
temp_file.close
|
62
|
+
File.unlink dest_file if File.exists?(dest_file)
|
63
|
+
FileUtils.mkdir_p File.dirname(dest_file)
|
64
|
+
FileUtils.mv temp_file.path, dest_file, :force => true
|
65
|
+
end
|
66
|
+
|
39
67
|
dest_file
|
40
68
|
end
|
41
69
|
|
@@ -43,28 +71,21 @@ module Depends
|
|
43
71
|
params = {}
|
44
72
|
|
45
73
|
if params[:depends_list]
|
46
|
-
Nestful.post "#{source_url}/
|
74
|
+
Nestful.post "#{source_url}/depends/search", :params => params, :format => :json, :headers => headers
|
47
75
|
else
|
48
|
-
Nestful.get "#{source_url}/
|
76
|
+
Nestful.get "#{source_url}/depends", :format => :json, :headers => headers
|
49
77
|
end
|
50
78
|
|
51
79
|
end
|
52
80
|
|
53
81
|
def get_latest_version(name)
|
54
|
-
JSON.parse( Nestful.get "#{source_url}/
|
82
|
+
JSON.parse( Nestful.get "#{source_url}/depends/#{name}/version/latest", :headers => headers )
|
55
83
|
end
|
56
84
|
|
57
85
|
|
58
86
|
def get_dep_version(name,version)
|
59
|
-
|
60
|
-
|
61
|
-
depend = cache.read(uri)
|
62
|
-
if depend.nil?
|
63
|
-
depend = Nestful.get uri, :format => :json
|
64
|
-
cache.write(uri,depend.to_json)
|
65
|
-
else
|
66
|
-
depend = ::MultiJson.load(depend)
|
67
|
-
end
|
87
|
+
uri = "#{source_url}/depends/#{name}/version/#{version}"
|
88
|
+
depend = Nestful.get uri, :format => :json, :headers => headers
|
68
89
|
depend
|
69
90
|
end
|
70
91
|
|
data/lib/depends/util.rb
CHANGED
@@ -5,14 +5,12 @@ module Depends
|
|
5
5
|
|
6
6
|
def self.un_zip(source,destination, options = {})
|
7
7
|
options.reverse_merge!({:overwrite => true})
|
8
|
-
|
8
|
+
say "Opening #{source}"
|
9
9
|
Zip::ZipFile.open(source) do |zip|
|
10
10
|
zip.each do |entry|
|
11
|
-
Log.debug (":entry => #{entry.name}")
|
12
11
|
path = ::File.join(destination, entry.name)
|
13
12
|
FileUtils.mkdir_p(::File.dirname(path))
|
14
13
|
if options[:overwrite] && ::File.exists?(path) && !::File.directory?(path)
|
15
|
-
Log.debug("Removing #{path}")
|
16
14
|
FileUtils.rm(path)
|
17
15
|
end
|
18
16
|
zip.extract(entry, path)
|
data/lib/depends.rb
CHANGED
@@ -4,12 +4,9 @@ require 'net/http'
|
|
4
4
|
require 'json'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'logger'
|
7
|
-
require 'mixlib/log'
|
8
|
-
require 'mixlib/config'
|
9
|
-
require 'mixlib/cli'
|
10
7
|
require 'digest/sha1'
|
11
8
|
require 'multi_json'
|
12
|
-
|
9
|
+
require 'mixlib/config'
|
13
10
|
|
14
11
|
require 'depends/exceptions'
|
15
12
|
require 'depends/config'
|
@@ -17,10 +14,9 @@ require 'depends/util'
|
|
17
14
|
require 'depends/rest_client'
|
18
15
|
require 'depends/dsl/depend'
|
19
16
|
require 'depends/definition'
|
20
|
-
require '
|
21
|
-
require 'depends/log'
|
22
|
-
require 'depends/command_factory'
|
17
|
+
require 'terminal-table'
|
23
18
|
|
24
|
-
require 'depends/commands/base'
|
25
19
|
require 'depends/commands/install'
|
20
|
+
require 'depends/commands/list'
|
21
|
+
require 'depends/commands/versions'
|
26
22
|
require 'depends/commands/upload'
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: depends-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Roby
|
@@ -10,77 +10,59 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement:
|
16
|
+
name: nestful
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 0.0.8
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: nestful
|
28
|
-
requirement: &70141195519180 !ruby/object:Gem::Requirement
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
26
|
none: false
|
30
27
|
requirements:
|
31
28
|
- - ~>
|
32
29
|
- !ruby/object:Gem::Version
|
33
30
|
version: 0.0.8
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *70141195519180
|
37
31
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement:
|
32
|
+
name: rubyzip
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
40
34
|
none: false
|
41
35
|
requirements:
|
42
36
|
- - ~>
|
43
37
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
38
|
+
version: 0.9.7
|
45
39
|
type: :runtime
|
46
40
|
prerelease: false
|
47
|
-
version_requirements:
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rubyzip
|
50
|
-
requirement: &70141195516060 !ruby/object:Gem::Requirement
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
42
|
none: false
|
52
43
|
requirements:
|
53
44
|
- - ~>
|
54
45
|
- !ruby/object:Gem::Version
|
55
46
|
version: 0.9.7
|
56
|
-
type: :runtime
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: *70141195516060
|
59
47
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
-
requirement:
|
48
|
+
name: activesupport
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
62
50
|
none: false
|
63
51
|
requirements:
|
64
52
|
- - ~>
|
65
53
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
54
|
+
version: 3.2.3
|
67
55
|
type: :runtime
|
68
56
|
prerelease: false
|
69
|
-
version_requirements:
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: activesupport
|
72
|
-
requirement: &70141195543660 !ruby/object:Gem::Requirement
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
58
|
none: false
|
74
59
|
requirements:
|
75
60
|
- - ~>
|
76
61
|
- !ruby/object:Gem::Version
|
77
62
|
version: 3.2.3
|
78
|
-
type: :runtime
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: *70141195543660
|
81
63
|
- !ruby/object:Gem::Dependency
|
82
64
|
name: rack-cache
|
83
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
84
66
|
none: false
|
85
67
|
requirements:
|
86
68
|
- - ~>
|
@@ -88,10 +70,15 @@ dependencies:
|
|
88
70
|
version: '1.2'
|
89
71
|
type: :runtime
|
90
72
|
prerelease: false
|
91
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.2'
|
92
79
|
- !ruby/object:Gem::Dependency
|
93
80
|
name: multi_json
|
94
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
95
82
|
none: false
|
96
83
|
requirements:
|
97
84
|
- - ~>
|
@@ -99,7 +86,60 @@ dependencies:
|
|
99
86
|
version: 1.3.2
|
100
87
|
type: :runtime
|
101
88
|
prerelease: false
|
102
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.3.2
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: commander
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 4.1.2
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.1.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mixlib-config
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: terminal-table
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
type: :runtime
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
103
143
|
description:
|
104
144
|
email:
|
105
145
|
- croby@biaprotect.com
|
@@ -110,16 +150,16 @@ extensions: []
|
|
110
150
|
extra_rdoc_files: []
|
111
151
|
files:
|
112
152
|
- bin/depend
|
113
|
-
- lib/depends/
|
114
|
-
- lib/depends/commands/
|
153
|
+
- lib/depends/cli.rb
|
154
|
+
- lib/depends/commands/configure.rb
|
115
155
|
- lib/depends/commands/install.rb
|
156
|
+
- lib/depends/commands/list.rb
|
116
157
|
- lib/depends/commands/upload.rb
|
158
|
+
- lib/depends/commands/versions.rb
|
117
159
|
- lib/depends/config.rb
|
118
160
|
- lib/depends/definition.rb
|
119
161
|
- lib/depends/dsl/depend.rb
|
120
162
|
- lib/depends/exceptions.rb
|
121
|
-
- lib/depends/log/formatter.rb
|
122
|
-
- lib/depends/log.rb
|
123
163
|
- lib/depends/rest_client.rb
|
124
164
|
- lib/depends/util.rb
|
125
165
|
- lib/depends.rb
|
@@ -140,12 +180,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
181
|
none: false
|
142
182
|
requirements:
|
143
|
-
- - ! '
|
183
|
+
- - ! '>'
|
144
184
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
185
|
+
version: 1.3.1
|
146
186
|
requirements: []
|
147
187
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
188
|
+
rubygems_version: 1.8.24
|
149
189
|
signing_key:
|
150
190
|
specification_version: 3
|
151
191
|
summary: A simple dependency manager
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Depends
|
2
|
-
module CommandFactory
|
3
|
-
class << self
|
4
|
-
def build
|
5
|
-
subcommand_class
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
def subcommand_class
|
10
|
-
command_words = ARGV.select {|arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ }
|
11
|
-
if command_words.empty?
|
12
|
-
return Depends::Commands::Install
|
13
|
-
end
|
14
|
-
command_words.collect! {|word| word.titleize }
|
15
|
-
command_options = []
|
16
|
-
subcommand_class = nil
|
17
|
-
|
18
|
-
while ( !subcommand_class ) && ( !command_words.empty? )
|
19
|
-
constant_case_name = command_words.join('')
|
20
|
-
command_options << constant_case_name
|
21
|
-
command_constant = Depends::Commands.constants.select { |i| i.eql? constant_case_name.to_sym}
|
22
|
-
unless command_constant.empty?
|
23
|
-
return "Depends::Commands::#{constant_case_name}".constantize
|
24
|
-
end
|
25
|
-
command_words.pop
|
26
|
-
end
|
27
|
-
raise Depends::Exceptions::SubCommandMissing, "Possible SubCommands: #{command_options} "
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Depends
|
2
|
-
module Commands
|
3
|
-
class Base
|
4
|
-
|
5
|
-
include Mixlib::CLI
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
super
|
9
|
-
|
10
|
-
trap("TERM") do
|
11
|
-
Depends::Commands::Base.fatal!("SIGTERM received, stopping", 1)
|
12
|
-
end
|
13
|
-
|
14
|
-
trap("INT") do
|
15
|
-
Depends::Commands::Base.fatal!("SIGINT received, stopping", 2)
|
16
|
-
end
|
17
|
-
|
18
|
-
processor, platform, *rest = RUBY_PLATFORM.split("-")
|
19
|
-
|
20
|
-
unless platform == 'mswin32'
|
21
|
-
trap("QUIT") do
|
22
|
-
Depends::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n "))
|
23
|
-
end
|
24
|
-
|
25
|
-
trap("HUP") do
|
26
|
-
Depends::Log.info("SIGHUP received, reconfiguring")
|
27
|
-
reconfigure
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def reconfigure
|
34
|
-
parse_options
|
35
|
-
configure_depends
|
36
|
-
configure_logging
|
37
|
-
end
|
38
|
-
|
39
|
-
def run
|
40
|
-
reconfigure
|
41
|
-
setup_application
|
42
|
-
run_application
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
private
|
47
|
-
def configure_depends
|
48
|
-
|
49
|
-
if File.exist?('~/.depends')
|
50
|
-
Depends::Log.info "Loading config file from '~/.depends'"
|
51
|
-
Depends::Config.from_file('~/.depends')
|
52
|
-
end
|
53
|
-
|
54
|
-
FileUtils.mkdir_p Depends::Config.cache
|
55
|
-
end
|
56
|
-
|
57
|
-
def configure_logging
|
58
|
-
Depends::Log.formatter = Depends::Log::Formatter.new
|
59
|
-
Depends::Log.level = config[:log_level] || Logger::INFO
|
60
|
-
end
|
61
|
-
|
62
|
-
# Called prior to starting the application, by the run method
|
63
|
-
def setup_application
|
64
|
-
raise Depends::Exceptions::Application, "#{self.to_s}: you must override setup_application"
|
65
|
-
end
|
66
|
-
|
67
|
-
# Actually run the application
|
68
|
-
def run_application
|
69
|
-
raise Depends::Exceptions::Application, "#{self.to_s}: you must override run_application"
|
70
|
-
end
|
71
|
-
|
72
|
-
class << self
|
73
|
-
|
74
|
-
# Log a fatal error message to both STDERR and the Logger, exit the application
|
75
|
-
def fatal!(msg, err = -1)
|
76
|
-
Depends::Log.fatal(msg)
|
77
|
-
Process.exit err
|
78
|
-
end
|
79
|
-
|
80
|
-
def exit!(msg, err = -1)
|
81
|
-
Depends::Log.debug(msg)
|
82
|
-
Process.exit err
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'time'
|
3
|
-
|
4
|
-
module Depends
|
5
|
-
class Log
|
6
|
-
class Formatter < Logger::Formatter
|
7
|
-
@@show_time = false
|
8
|
-
|
9
|
-
COLOR_MAP = {'DEBUG' =>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
|
10
|
-
|
11
|
-
def self.show_time=(show=false)
|
12
|
-
@@show_time = show
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(severity, time, progname, msg)
|
16
|
-
color = COLOR_MAP[severity]
|
17
|
-
|
18
|
-
if @@show_time
|
19
|
-
sprintf("\033[0;37m%s \033[0m[\033[#{color}m%s\033[0m]: \033[0m%s\n", time.rfc2822(), severity, msg2str(msg))
|
20
|
-
else
|
21
|
-
sprintf("\033[#{color}m%s\033[0;37m: \033[0m%s\n", severity, msg2str(msg))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Converts some argument to a Logger.severity() call to a string. Regular strings pass through like
|
26
|
-
# normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
|
27
|
-
# put through "object.inspect"
|
28
|
-
def msg2str(msg)
|
29
|
-
case msg
|
30
|
-
when ::String
|
31
|
-
msg
|
32
|
-
when ::Exception
|
33
|
-
"#{ msg.message } (#{ msg.class })\n" <<
|
34
|
-
(msg.backtrace || []).join("\n")
|
35
|
-
else
|
36
|
-
msg.inspect
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|