Class: Ploy::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/ploy/package.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, deploy, branch, version, variant = nil, updatevia = nil) ⇒ Package

Returns a new instance of Package.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ploy/package.rb', line 12

def initialize(bucket, deploy, branch, version, variant = nil, updatevia = nil)
  @bucket = bucket
  @deploy_name = deploy
  @branch = branch
  @version = version
  @variant = variant
  @updatevia = 'ploy'
  unless updatevia.nil?
    @updatevia = updatevia
  end

  @store = Ploy::S3Storage.new(bucket)
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



7
8
9
# File 'lib/ploy/package.rb', line 7

def branch
  @branch
end

#deploy_nameObject

Returns the value of attribute deploy_name.



6
7
8
# File 'lib/ploy/package.rb', line 6

def deploy_name
  @deploy_name
end

#updateviaObject

Returns the value of attribute updatevia.



10
11
12
# File 'lib/ploy/package.rb', line 10

def updatevia
  @updatevia
end

#variantObject

Returns the value of attribute variant.



9
10
11
# File 'lib/ploy/package.rb', line 9

def variant
  @variant
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/ploy/package.rb', line 8

def version
  @version
end

Class Method Details

.from_metadata(bucket, meta) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/ploy/package.rb', line 77

def self.(bucket, meta)
  out = []
  meta.each do |k,v|
    out.push(self.new(bucket, v['name'], v['branch'], v['sha'], v['variant']))
  end
  return out
end

Instance Method Details

#bless(variant = "blessed") ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/ploy/package.rb', line 53

def bless(variant="blessed")
  b = self.blessed(variant)
  @store.copy(
    location,
    b.location
  )
  return b
end

#blessed(variant = "blessed") ⇒ Object



49
50
51
# File 'lib/ploy/package.rb', line 49

def blessed(variant="blessed")
  return Ploy::Package.new(@bucket, @deploy_name, @branch, @version, variant)
end

#check_new_versionObject



26
27
28
# File 'lib/ploy/package.rb', line 26

def check_new_version
  return (installed_version != remote_version)
end

#installObject



42
43
44
45
46
47
# File 'lib/ploy/package.rb', line 42

def install
  Tempfile.open(['ploy', '.deb']) do |f|
    @store.get(location, f)
    system("dpkg -i #{f.path}")
  end
end

#installed_versionObject



30
31
32
33
34
35
36
# File 'lib/ploy/package.rb', line 30

def installed_version
  version = `dpkg-query -W -f '${gitrev}' #{@deploy_name}`.chomp
  if version =~ /no packages found/i
    version = ''
  end
  return version
end

#locationObject



62
63
64
# File 'lib/ploy/package.rb', line 62

def location
  return Ploy::Util.remote_name(@deploy_name, @branch, @version, @variant)
end

#location_currentObject



65
66
67
# File 'lib/ploy/package.rb', line 65

def location_current
  return Ploy::Util.remote_name(@deploy_name, @branch, 'current', @variant)
end

#make_currentObject



73
74
75
# File 'lib/ploy/package.rb', line 73

def make_current
  @store.copy(location, location_current)
end

#remote_versionObject



38
39
40
# File 'lib/ploy/package.rb', line 38

def remote_version
  return @store.(location)['git_revision']
end

#upload(path) ⇒ Object



69
70
71
# File 'lib/ploy/package.rb', line 69

def upload(path)
  @store.put(path, location, {'git_revision' => @version})
end