Class: Aptly::Repo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Repo

Instantiates an Aptly::Repo object

Parameters:

name

The name of the repository

Returns:

An Aptly::Repo object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/aptly/repo.rb', line 79

def initialize name
  if !Aptly::list_repos.include? name
    raise AptlyError.new "Repo '#{name}' does not exist"
  end

  info = Aptly::repo_info name
  @name = info['Name']
  @comment = info['Comment']
  @dist = info['Default Distribution']
  @component = info['Default Component']
  @num_packages = info['Number of packages'].to_i
end

Instance Attribute Details

#archlistObject

Returns the value of attribute archlist.



62
63
64
# File 'lib/aptly/repo.rb', line 62

def archlist
  @archlist
end

#commentObject

Returns the value of attribute comment.



62
63
64
# File 'lib/aptly/repo.rb', line 62

def comment
  @comment
end

#componentObject

Returns the value of attribute component.



61
62
63
# File 'lib/aptly/repo.rb', line 61

def component
  @component
end

#distObject

Returns the value of attribute dist.



61
62
63
# File 'lib/aptly/repo.rb', line 61

def dist
  @dist
end

#nameObject

Returns the value of attribute name.



61
62
63
# File 'lib/aptly/repo.rb', line 61

def name
  @name
end

#num_packagesObject

Returns the value of attribute num_packages.



62
63
64
# File 'lib/aptly/repo.rb', line 62

def num_packages
  @num_packages
end

Instance Method Details

#add(path, kwargs = {}) ⇒ Object

Add debian packages to a repo

Parameters:

path

The path to the file or directory source

remove_files

When true, deletes source after import



116
117
118
119
120
121
122
123
124
# File 'lib/aptly/repo.rb', line 116

def add path, kwargs={}
  remove_files = kwargs.arg :remove_files, false

  cmd = 'aptly repo add'
  cmd += ' -remove-files' if remove_files
  cmd += " #{@name.quote} #{path}"

  Aptly::runcmd cmd
end

#copy_from(from_repo, pkg_spec, kwargs = {}) ⇒ Object

Shortcut method to copy resources in from another repository



176
177
178
179
# File 'lib/aptly/repo.rb', line 176

def copy_from from_repo, pkg_spec, kwargs={}
  deps = kwargs.arg :deps, false
  copy from_repo, @name, pkg_spec, :deps => deps
end

#copy_to(to_repo, pkg_spec, kwargs = {}) ⇒ Object

Shortcut method to copy resources out to another repository



182
183
184
185
# File 'lib/aptly/repo.rb', line 182

def copy_to to_repo, pkg_spec, kwargs={}
  deps = kwargs.arg :deps, false
  copy @name, to_repo, pkg_spec, :deps => deps
end

#dropObject

Drops an existing aptly repository



93
94
95
# File 'lib/aptly/repo.rb', line 93

def drop
  Aptly::runcmd "aptly repo drop #{@name.quote}"
end

#import(from_mirror, kwargs = {}) ⇒ Object

Imports package resources from existing mirrors

Parameters:

from_mirror

The name of the mirror to import from

packages

A list of debian pkg_spec strings (e.g. “libc6 (>= 2.7-1)”)

deps

When true, follows package dependencies and adds them



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/aptly/repo.rb', line 136

def import from_mirror, kwargs={}
  deps = kwargs.arg :deps, false
  packages = kwargs.arg :packages, []

  if packages.length == 0
    raise AptlyError.new '1 or more packages are required'
  end

  cmd = 'aptly repo import'
  cmd += ' -with-deps' if deps
  cmd += " #{from_mirror.quote} #{@name.quote}"
  packages.each {|p| cmd += " #{p.quote}"}

  Aptly::runcmd cmd
end

#list_packagesObject

List all packages contained in a repository

Returns:

An array of packages



102
103
104
105
106
# File 'lib/aptly/repo.rb', line 102

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

#move_from(from_repo, pkg_spec, kwargs = {}) ⇒ Object

Shortcut method to move packages in from another repo



211
212
213
214
# File 'lib/aptly/repo.rb', line 211

def move_from from_repo, pkg_spec, kwargs={}
  deps = kwargs.arg :deps, false
  move from_repo, @name, pkg_spec, :deps => deps
end

#move_to(to_repo, pkg_spec, kwargs = {}) ⇒ Object

Shortcut method to move packages out to another repository



217
218
219
220
# File 'lib/aptly/repo.rb', line 217

def move_to to_repo, pkg_spec, kwargs={}
  deps = kwargs.arg :deps, false
  move @name, to_repo, pkg_spec, :deps => deps
end

#publish(args) ⇒ Object

Shortcut method to publish a repo from an Aptly::Repo instance.



238
239
240
# File 'lib/aptly/repo.rb', line 238

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

#remove(pkg_spec) ⇒ Object

Remove packages selectively from a repository

Parameters:

pkg_spec

A debian pkg_spec string to select packages by



228
229
230
# File 'lib/aptly/repo.rb', line 228

def remove pkg_spec
  Aptly::runcmd "aptly repo remove #{@name.quote} #{pkg_spec.quote}"
end

#saveObject

save allows you to modify the repository distribution, comment, or component string by using the attr_accessor’s, and then calling this method to persist them to aptly.



245
246
247
248
249
250
251
252
253
# File 'lib/aptly/repo.rb', line 245

def save
  cmd = "aptly repo edit"
  cmd += " -distribution=#{@dist.quote}"
  cmd += " -comment=#{@comment.quote}"
  cmd += " -component=#{@component.quote}"
  cmd += " #{@name.quote}"

  Aptly::runcmd cmd
end

#snapshot(name) ⇒ Object

Shortcut method to snapshot an Aptly::Repo object



233
234
235
# File 'lib/aptly/repo.rb', line 233

def snapshot name
  Aptly::create_repo_snapshot name, @name
end