ploy 0.0.5 → 0.0.6

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: 9b4bb8c3355ea0bf3b8fb3cb621f0c9f3608ec8a
4
- data.tar.gz: 150fa76924b37b6463669a5e2648b0070121840a
3
+ metadata.gz: 2144fca6b9fec5eeed9fb7a1bf24221b968b3854
4
+ data.tar.gz: 8b26ad40c631590974ebb6a25bf1a51457c29bb7
5
5
  SHA512:
6
- metadata.gz: dd9b8d5d3d0929a3f3c8498a54e6fc9acdb9f280be873c120e9dba6f88da6440714ef09584082612900549700a355f695e86446dc42ea987d440b60090dba679
7
- data.tar.gz: 09967bc6259db66be7d4965d419abf8862f405b1bf60d95ad181f80c67b925c842d7619560380740b3d7da5b764b08689e679bf5406124eaf5cbd07e4a404927
6
+ metadata.gz: b79fc823b4544bf03a4971d7675dcc99bdb53b02b3f829d2547fb76690e89371786954eee2a60d59c81a7ebca89576b9e0fa3be0dcd59bb11b4df2b1826f48c1
7
+ data.tar.gz: abfeecafbdadfa36996e9b8886dac2af96e154831465308335b9310700a78be1376b4527190682dd210de1fe03b4bc39dfb2130908e5cc0b35226e2a32664e2c
data/lib/ploy/command.rb CHANGED
@@ -3,6 +3,7 @@ require 'ploy/command/publish'
3
3
  require 'ploy/command/help'
4
4
  require 'ploy/command/bless'
5
5
  require 'ploy/command/oracle'
6
+ require 'ploy/command/client'
6
7
 
7
8
  module Ploy
8
9
  module Command
@@ -13,6 +14,7 @@ module Ploy
13
14
  'help' => Ploy::Command::Help,
14
15
  'publish' => Ploy::Command::Publish,
15
16
  'oracle' => Ploy::Command::Oracle,
17
+ 'client' => Ploy::Command::Client,
16
18
  }
17
19
  mod = lookup[topic] || lookup['help']
18
20
  return mod.new
@@ -0,0 +1,106 @@
1
+ require 'ploy/command/base'
2
+ require 'ploy/yamlreader'
3
+ require 'ploy/packageset'
4
+ require 'optparse'
5
+
6
+ module Ploy
7
+ module Command
8
+ class Client < Base
9
+ def run(argv)
10
+ o = {
11
+ :target_packages => []
12
+ }
13
+ optparser(o).parse!(argv)
14
+ conf = conf_from_opts(o)
15
+
16
+ if conf then
17
+ ps = Ploy::PackageSet.new(conf)
18
+ if ps.locked?
19
+ puts "locked. taking no action."
20
+ else
21
+ ips = installable_packages(o[:target_packages], ps.packages)
22
+ ips.each do |package|
23
+ if package.check_new_version then
24
+ package.install
25
+ puts "installed #{package.deploy_name}"
26
+ else
27
+ puts "no new #{package.deploy_name} available"
28
+ end
29
+ end
30
+ end
31
+ else
32
+ puts "error reading conf"
33
+ help()
34
+ end
35
+ end
36
+
37
+ def help
38
+ return <<helptext
39
+ usage: ploy client OPTS
40
+
41
+ #{optparser}
42
+
43
+ Examples:
44
+
45
+ $ ploy client -f set.yml -d foo -d bar
46
+ $ ploy client -b bucket -n this/that/set.yml -d foo -d bar
47
+ $ ploy client -u http://example.com/set.yml -d foo -d bar
48
+
49
+ All of those examples will try to install the same packages, but use
50
+ different sources for configuration. The first uses a file, the second
51
+ uses S3, and the third uses a web service.
52
+
53
+ Summary:
54
+
55
+ The client command is like an "install" command that uses external
56
+ configuration instead of command-line options. It can use a file,
57
+ or talk to S3 or a web service.
58
+
59
+ helptext
60
+ end
61
+
62
+ def installable_packages(target_packages, packages)
63
+ tph = {}
64
+ target_packages.each { |tp| tph[tp] = true }
65
+ packages.find_all { |p| tph[p.deploy_name] }
66
+ end
67
+
68
+ private
69
+ def conf_from_opts(o)
70
+ yr = Ploy::YamlReader.new
71
+ conf = nil
72
+ if o[:bucket] and o[:stack] then
73
+ conf = yr.from_s3(o[:bucket], o[:s3_name])
74
+ elsif o[:hub_host] then
75
+ conf = yr.from_http(o[:http_url])
76
+ elsif o[:path] then
77
+ conf = yr.from_file(o[:path])
78
+ end
79
+ return conf
80
+ end
81
+
82
+ def optparser(o = {})
83
+ options = OptionParser.new do |opts|
84
+ opts.banner = ''
85
+ opts.on("-b", "--bucket BUCKET", "use the given S3 bucket") do |bucket|
86
+ o[:bucket] = bucket
87
+ end
88
+ opts.on("-n", "--s3-name S3_NAME", "use the given resource name") do |name|
89
+ o[:s3_name] = name
90
+ end
91
+ opts.on("-u", "--http-url HTTP_URL", "read config from an http URL") do |url|
92
+ o[:http_url] = url
93
+ end
94
+ opts.on("-f", "--file PATH", "read config from file") do |path|
95
+ o[:path] = path
96
+ end
97
+ opts.on("-d", "--deploy DEPLOY_NAME", "a deploy/remote package to install, subject to hub config") do |name|
98
+ o[:target_packages].push(name)
99
+ end
100
+ end
101
+ return options
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,23 @@
1
+ module Ploy
2
+ class PackageSet
3
+ attr_accessor :packages
4
+
5
+ def initialize(conf)
6
+ self.packages = []
7
+ conf['packages'].each do |k,v|
8
+ self.packages.push Ploy::Package.new(
9
+ conf['bucket'] || v['bucket'],
10
+ k,
11
+ v['branch'],
12
+ v['version']
13
+ )
14
+ end
15
+ @locked = conf['locked']
16
+ end
17
+
18
+ def locked?
19
+ return @locked ? true : false
20
+ end
21
+
22
+ end
23
+ end
@@ -16,7 +16,11 @@ module Ploy
16
16
  def copy(from, to)
17
17
  AWS::S3.new.buckets[@bucketname].objects[from].copy_to(to)
18
18
  end
19
-
19
+
20
+ def read(from)
21
+ AWS::S3.new.buckets[@bucketname].objects[from].read
22
+ end
23
+
20
24
  def get(from, fileio)
21
25
  AWS::S3.new.buckets[@bucketname].objects[from].read do |chunk|
22
26
  fileio.write(chunk)
@@ -0,0 +1,18 @@
1
+ require 'net/http'
2
+
3
+ module Ploy
4
+ class YamlReader
5
+ def from_file(path)
6
+ YAML.load(File.read(path))
7
+ end
8
+
9
+ def from_s3(bucket, name)
10
+ YAML.load(Ploy::S3Storage.new(bucket).read(name))
11
+ end
12
+
13
+ def from_http(url)
14
+ txt = Net::HTTP.get(URI(url))
15
+ YAML.load(txt)
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bruce
@@ -62,6 +62,7 @@ files:
62
62
  - lib/ploy/cli.rb
63
63
  - lib/ploy/command/base.rb
64
64
  - lib/ploy/command/bless.rb
65
+ - lib/ploy/command/client.rb
65
66
  - lib/ploy/command/help.rb
66
67
  - lib/ploy/command/install.rb
67
68
  - lib/ploy/command/oracle.rb
@@ -74,8 +75,10 @@ files:
74
75
  - lib/ploy/metaoracle.rb
75
76
  - lib/ploy/metasrc.rb
76
77
  - lib/ploy/package.rb
78
+ - lib/ploy/packageset.rb
77
79
  - lib/ploy/publisher.rb
78
80
  - lib/ploy/s3storage.rb
81
+ - lib/ploy/yamlreader.rb
79
82
  - bin/ploy
80
83
  homepage:
81
84
  licenses: []