opendelivery 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/opendelivery.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'opendelivery/version.rb'
1
+ require 'opendelivery/source_control.rb'
2
2
  require 'opendelivery/artifact.rb'
3
3
  require 'opendelivery/domain.rb'
4
4
  require 'opendelivery/image.rb'
@@ -1,3 +1,5 @@
1
+ require 'aws-sdk'
2
+
1
3
  module OpenDelivery
2
4
  class Image
3
5
 
@@ -0,0 +1,79 @@
1
+ module OpenDelivery
2
+ class SourceControl
3
+ def initialize(dir)
4
+ @dir = dir
5
+ end
6
+
7
+ def log(lines=10)
8
+ Dir.chdir(@dir) do
9
+ `git log --stat -n #{lines}`
10
+ end
11
+ end
12
+
13
+ def status
14
+ Dir.chdir(@dir) do
15
+ `git status -sb`
16
+ end
17
+ end
18
+
19
+ def remove_missing_files(status)
20
+ removed_files = []
21
+ files = find_removed_files(status)
22
+ files.each do |file|
23
+ Dir.chdir(@dir) do
24
+ removed_files << `git rm -rf #{file}`
25
+ end
26
+ end
27
+ removed_files
28
+ end
29
+
30
+ def add(files)
31
+ Dir.chdir(@dir) do
32
+ `git add #{files} -v`
33
+ end
34
+ end
35
+
36
+ def commit(message)
37
+ Dir.chdir(@dir) do
38
+ `git commit -m "#{message}"`
39
+ end
40
+ end
41
+
42
+ def push
43
+ Dir.chdir(@dir) do
44
+ `git push`
45
+ end
46
+ end
47
+
48
+ def pull
49
+ Dir.chdir(@dir) do
50
+ @result = `git pull`
51
+ end
52
+ if $?.to_i != 0
53
+ raise "Your pull failed. Probably because of a merge conflict!"
54
+ end
55
+ @result
56
+ end
57
+
58
+ def conflicted(status)
59
+ status.each_line do |stat|
60
+ if stat.match(/^UU /) || stat.match(/^U /) || stat.match(/^U /)
61
+ raise "You have file conflicts when trying to merge. Because this could end up horribly, we won't try to automatically fix these conflicts. Please go an manually merge the files!"
62
+ end
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+
69
+ def find_removed_files(status)
70
+ statuses = []
71
+ status.each_line do |stat|
72
+ if stat.match(/^ D /)
73
+ statuses << stat.split[1]
74
+ end
75
+ end
76
+ statuses
77
+ end
78
+ end
79
+ end
@@ -9,7 +9,7 @@ module OpenDelivery
9
9
  else
10
10
  @cfn = AWS::CloudFormation.new(:region => region)
11
11
  end
12
- @domain = OpenDelivery::Domain.new
12
+ @domain = OpenDelivery::Domain.new region
13
13
  end
14
14
 
15
15
 
@@ -63,10 +63,10 @@ module OpenDelivery
63
63
  end
64
64
  end
65
65
 
66
- def destroy(domain, stack_name)
66
+ def destroy(domain, stack_name, wait=false)
67
67
  stack = @cfn.stacks[stack_name]
68
68
  stack.delete
69
- while stack.exists?
69
+ while wait and stack.exists?
70
70
  sleep 20
71
71
  end
72
72
  @domain.destroy_item(domain, stack_name)
@@ -15,19 +15,31 @@ module OpenDelivery
15
15
  @s3.buckets[bucket].objects[key].copy_to(desired_key)
16
16
  end
17
17
 
18
- def upload(file, bucket, key)
18
+ def upload(bucket, file, key)
19
19
  @s3.buckets[bucket].objects[key].write(:file => file)
20
20
  end
21
21
 
22
22
  def download(bucket, key, output_directory)
23
+ # Puke if the bucket doesn't exist
24
+ raise "Bucket #{bucket} doesn't exist" unless @s3.buckets[bucket].exists?
25
+
26
+ # Puke if the key doesn't exist. This can cause problems with some bucket policies, so we catch and re-throw
27
+ begin
28
+ raise "File with key #{key} doesn't exist in bucket #{bucket}" unless @s3.buckets[bucket].objects[key].exists?
29
+ rescue Exception => e
30
+ raise "Exception [#{e.message}] occurred downloading key #{key} from bucket #{bucket}"
31
+ end
32
+
23
33
  obj = @s3.buckets[bucket].objects[key]
24
34
 
25
35
  base = Pathname.new("#{obj.key}").basename
26
36
 
27
37
  Dir.mkdir(output_directory) unless File.exists?(output_directory)
28
38
 
29
- File.open("#{output_directory}/#{base}", 'w') do |file|
30
- file.write(obj.read)
39
+ File.open("#{output_directory}/#{base}", 'wb') do |file|
40
+ obj.read do |chunk|
41
+ file.write(chunk)
42
+ end
31
43
  end
32
44
  end
33
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opendelivery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-28 00:00:00.000000000 Z
14
+ date: 2013-08-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: aws-sdk
@@ -71,9 +71,9 @@ files:
71
71
  - lib/opendelivery/artifact.rb
72
72
  - lib/opendelivery/domain.rb
73
73
  - lib/opendelivery/image.rb
74
+ - lib/opendelivery/source_control.rb
74
75
  - lib/opendelivery/stack.rb
75
76
  - lib/opendelivery/storage.rb
76
- - lib/opendelivery/version.rb
77
77
  homepage: http://stelligent.com
78
78
  licenses:
79
79
  - MIT
@@ -1,3 +0,0 @@
1
- module OpenDelivery
2
- VERSION = '0.0.5'
3
- end