Class: Aptly::CliHelper

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CliHelper

Returns a new instance of CliHelper.



10
11
12
13
14
15
# File 'lib/cli_helper.rb', line 10

def initialize(options)
  require 'json'
  require 'open3'

  @aptly = options.delete(:aptly_binary_path) || 'aptly'
end

Instance Method Details

#mirror_create(name, url, distribution, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cli_helper.rb', line 17

def mirror_create(name, url, distribution, options = {})
  cmd = [@aptly, 'mirror', 'create']
  cmd += parse_common_options(options)
  cmd << "-filter=#{options[:filter]}" if options[:filter]
  cmd << '-filter-with-deps' if options[:filter_with_deps]
  cmd << '-force-architectures' if options[:force_architectures]
  cmd << '-force-components' if options[:force_components]
  cmd << '-ignore-signatures' if options[:ignore_signatures]
  cmd += Array(options[:keyring]).map { |x| "-keyring=#{x}" }
  cmd << "-max-tries=#{options[:max_tries]}" if options[:max_tries]
  cmd << '-with-installer' if options[:with_installer]
  cmd << '-with-sources' if options[:with_sources]
  cmd << '-with-udebs' if options[:with_udebs]
  cmd += [name, url, distribution]
  cmd += Array(options[:component])
  execute(cmd)
end

#mirror_drop(name, options = {}) ⇒ Object



54
55
56
# File 'lib/cli_helper.rb', line 54

def mirror_drop(name, options = {})
  something_drop('mirror', name, options)
end

#mirror_list(options = {}) ⇒ Object



50
51
52
# File 'lib/cli_helper.rb', line 50

def mirror_list(options = {})
  something_list('mirror', options)
end

#mirror_update(name, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cli_helper.rb', line 35

def mirror_update(name, options = {})
  cmd = [@aptly, 'mirror', 'update']
  cmd += parse_common_options(options)
  cmd << "-download-limit=#{options[:download_limit]}" if options[:download_limit]
  cmd << "-downloader=#{options[:downloader]}" if options[:downloader]
  cmd << '-force' if options[:force]
  cmd << '-ignore-checksums' if options[:ignore_checksums]
  cmd << '-ignore-signatures' if options[:ignore_signatures]
  cmd += Array(options[:keyring]).map { |x| "-keyring=#{x}" }
  cmd << "-max-tries=#{options[:max_tries]}" if options[:max_tries]
  cmd << '-skip-existing-packages' if options[:skip_existing_packages]
  cmd << name
  execute(cmd)
end

#publish_drop(distribution, prefix, options = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
# File 'lib/cli_helper.rb', line 151

def publish_drop(distribution, prefix, options = {})
  cmd = [@aptly, 'publish', 'drop']
  cmd += parse_common_options(options)
  cmd << '-force-drop' if options[:force_drop]
  cmd << '-skip-cleanup' if options[:skip_cleanup]
  cmd << distribution
  cmd << prefix
  execute(cmd)
end

#publish_list(options = {}) ⇒ Object



147
148
149
# File 'lib/cli_helper.rb', line 147

def publish_list(options = {})
  something_list('publish', options)
end

#publish_repo(names, prefix, options = {}) ⇒ Object



135
136
137
# File 'lib/cli_helper.rb', line 135

def publish_repo(names, prefix, options = {})
  publish_something('repo', names, prefix, options)
end

#publish_snapshot(names, prefix, options = {}) ⇒ Object



131
132
133
# File 'lib/cli_helper.rb', line 131

def publish_snapshot(names, prefix, options = {})
  publish_something('snapshot', names, prefix, options)
end

#publish_switch(distribution, prefix, snapshots, options = {}) ⇒ Object



139
140
141
# File 'lib/cli_helper.rb', line 139

def publish_switch(distribution, prefix, snapshots, options = {})
  publish_somehow('switch', distribution, prefix, snapshots, options)
end

#publish_update(distribution, prefix, options = {}) ⇒ Object



143
144
145
# File 'lib/cli_helper.rb', line 143

def publish_update(distribution, prefix, options = {})
  publish_somehow('update', distribution, prefix, nil, options)
end

#repo_add(name, package_or_directory, options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/cli_helper.rb', line 72

def repo_add(name, package_or_directory, options = {})
  cmd = [@aptly, 'repo', 'add']
  cmd += parse_common_options(options)
  cmd << '-force-replace' if options[:force_replace]
  cmd << '-remove-files' if options[:remove_files]
  cmd << name
  cmd << package_or_directory

  execute(cmd)
end

#repo_create(name, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cli_helper.rb', line 58

def repo_create(name, options = {})
  cmd = [@aptly, 'repo', 'create']
  cmd += parse_common_options(options)
  cmd << "-comment=#{options[:comment]}" if options[:comment]
  cmd << "-component=#{options[:component]}" if options[:component]
  cmd << "-distribution=#{options[:distribution]}" if options[:distribution]
  cmd << "-uploaders-file=#{options[:uploaders_file]}" if options[:uploaders_file]
  cmd << name

  cmd += ['from', 'snapshot', options[:snapshot]] if options[:snapshot]

  execute(cmd)
end

#repo_drop(name, options = {}) ⇒ Object



96
97
98
# File 'lib/cli_helper.rb', line 96

def repo_drop(name, options = {})
  something_drop('repo', name, options)
end

#repo_list(options = {}) ⇒ Object



92
93
94
# File 'lib/cli_helper.rb', line 92

def repo_list(options = {})
  something_list('repo', options)
end

#repo_remove(name, package_query, options = {}) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/cli_helper.rb', line 83

def repo_remove(name, package_query, options = {})
  cmd = [@aptly, 'repo', 'remove']
  cmd += parse_common_options(options)
  cmd << name
  cmd += Array(package_query)

  execute(cmd)
end

#snapshot_create(name, from, options = {}) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cli_helper.rb', line 100

def snapshot_create(name, from, options = {})
  cmd = [@aptly, 'snapshot', 'create']
  cmd += parse_common_options(options)
  cmd << name

  case from
  when 'mirror'
    raise Aptly::Error, '`mirror` option should be defined' unless options[:mirror]

    cmd += ['from', 'mirror', options[:mirror]]
  when 'repo'
    raise Aptly::Error, '`repo` option should be defined' unless options[:repo]

    cmd += ['from', 'repo', options[:repo]]
  when 'empty'
    cmd += %w[empty]
  else
    raise Aptly::Error, '`from` argument must be one of: mirror, repo, empty'
  end

  execute(cmd)
end

#snapshot_drop(name, options = {}) ⇒ Object



127
128
129
# File 'lib/cli_helper.rb', line 127

def snapshot_drop(name, options = {})
  something_drop('snapshot', name, options)
end

#snapshot_list(options = {}) ⇒ Object



123
124
125
# File 'lib/cli_helper.rb', line 123

def snapshot_list(options = {})
  something_list('snapshot', options)
end