Class: Aptly::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/aptly/snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Snapshot

Instantiates a new Aptly::Snapshot instance

Parameters:

name

The name of the snapshot

Returns:

An Aptly::Snapshot instance



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/aptly/snapshot.rb', line 145

def initialize name
  if !Aptly::list_snapshots.include? name
    raise AptlyError.new("Snapshot '#{name}' does not exist")
  end

  info = Aptly::snapshot_info name
  @name = info['Name']
  @created_at = info['Created At']
  @description = info['Description']
  @num_packages = info['Number of packages'].to_i
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



129
130
131
# File 'lib/aptly/snapshot.rb', line 129

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



129
130
131
# File 'lib/aptly/snapshot.rb', line 129

def description
  @description
end

#nameObject

Returns the value of attribute name.



129
130
131
# File 'lib/aptly/snapshot.rb', line 129

def name
  @name
end

#num_packagesObject

Returns the value of attribute num_packages.



129
130
131
# File 'lib/aptly/snapshot.rb', line 129

def num_packages
  @num_packages
end

Instance Method Details

#drop(kwargs = {}) ⇒ Object

Drops an existing snapshot

Parameters:

force

When true, drops a snapshot regardless of relationships



163
164
165
166
167
168
169
170
171
# File 'lib/aptly/snapshot.rb', line 163

def drop kwargs={}
  force = kwargs.arg :force, false

  cmd = 'aptly snapshot drop'
  cmd += ' -force' if force
  cmd += " #{@name.quote}"

  Aptly::runcmd cmd
end

#list_packagesObject

List all packages contained in a snapshot

Returns:

An array of packages



178
179
180
181
182
# File 'lib/aptly/snapshot.rb', line 178

def list_packages
  res = []
  out = Aptly::runcmd "aptly snapshot show -with-packages #{@name.quote}"
  Aptly::parse_indented_list out.lines
end

#publish(args) ⇒ Object

Shortcut method to publish a snapshot from an Aptly::Snapshot instance.



266
267
268
# File 'lib/aptly/snapshot.rb', line 266

def publish args
  Aptly::publish 'snapshot', @name, args
end

#pull_from(source, dest, kwargs = {}) ⇒ Object

Shortcut method to pull packages to the current snapshot



223
224
225
226
227
228
229
# File 'lib/aptly/snapshot.rb', line 223

def pull_from source, dest, kwargs={}
  packages = kwargs.arg :packages, []
  deps = kwargs.arg :deps, true
  remove = kwargs.arg :remove, true

  pull @name, source, dest, :packages => packages, :deps => deps, :remove => remove
end

#push_to(dest, source, kwargs = {}) ⇒ Object

Shortcut method to push packages from the current snapshot



232
233
234
235
236
237
238
# File 'lib/aptly/snapshot.rb', line 232

def push_to dest, source, kwargs={}
  packages = kwargs.arg :packages, []
  deps = kwargs.arg :deps, true
  remove = kwargs.arg :remove, true

  pull source, @name, dest, :packages => packages, :deps => deps, :remove => remove
end

#verify(kwargs = {}) ⇒ Object

Verifies an existing snapshot is able to resolve dependencies. This method currently only returns true/false status.

Parameters:

sources

Additional snapshot sources to be considered during verification

follow_source

When true, verify all source packages as well

Returns:

An array containing any missing deps. Empty list means all verified.



252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/aptly/snapshot.rb', line 252

def verify kwargs={}
  sources = kwargs.arg :sources, []
  follow_source = kwargs.arg :follow_source, false

  cmd = 'aptly snapshot verify'
  cmd += ' -dep-follow-source' if follow_source
  cmd += " #{@name.quote}"
  cmd += " #{sources.join(' ')}" if !sources.empty?

  out = Aptly::runcmd cmd
  Aptly::parse_indented_list out
end