dr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/dr CHANGED
@@ -107,36 +107,36 @@ class RepoCLI < ExtendedThor
107
107
  :codenames => []
108
108
  }
109
109
 
110
- name = ask " Repository name "<< "[#{repo_conf[:name].fg("yellow")}]:"
110
+ name = ask " Repository name "<< "[#{repo_conf[:name].fg("yellow")}]:"
111
111
  repo_conf[:name] = name if name.length > 0
112
112
 
113
- desc = ask " Description [#{repo_conf[:desc]}]:"
113
+ desc = ask " Description [#{repo_conf[:desc]}]:"
114
114
  repo_conf[:desc] = desc if desc.length > 0
115
115
 
116
- arches = ask " Architectures [#{repo_conf[:arches].join(" ").fg("yellow")}]:"
116
+ arches = ask " Architectures [#{repo_conf[:arches].join(" ").fg("yellow")}]:"
117
117
  repo_conf[:arches] = arches.split /\s+/ if arches.length > 0
118
118
 
119
- components = ask " Components [#{repo_conf[:components].join(" ").fg("yellow")}]:"
119
+ components = ask " Components [#{repo_conf[:components].join(" ").fg("yellow")}]:"
120
120
  repo_conf[:components] = components.split /\s+/ if components.length > 0
121
121
 
122
122
  repo_conf[:gpg_name] = ""
123
123
  while repo_conf[:gpg_name].length == 0
124
- repo_conf[:gpg_name] = ask " Cert owner name (#{"required".fg("red")}):"
124
+ repo_conf[:gpg_name] = ask " Cert owner name (#{"required".fg("red")}):"
125
125
  repo_conf[:gpg_name].strip!
126
126
  end
127
127
 
128
128
  repo_conf[:gpg_mail] = ""
129
129
  while repo_conf[:gpg_mail].length == 0
130
- repo_conf[:gpg_mail] = ask " Cert owner e-mail (#{"required".fg("red")}):"
130
+ repo_conf[:gpg_mail] = ask " Cert owner e-mail (#{"required".fg("red")}):"
131
131
  repo_conf[:gpg_mail].strip!
132
132
  end
133
133
 
134
- print " Passphrase (#{"optional".fg("green")}): "
134
+ print " Passphrase (#{"optional".fg("green")}): "
135
135
  repo_conf[:gpg_pass] = STDIN.noecho(&:gets).chomp
136
136
  print "\n"
137
137
 
138
138
  repo_conf[:suites].each do |s|
139
- codename = ask " Codename for '#{s.fg("yellow")}':"
139
+ codename = ask " Codename for '#{s.fg("yellow")}':"
140
140
  repo_conf[:codenames].push codename
141
141
  end
142
142
 
@@ -149,7 +149,7 @@ class RepoCLI < ExtendedThor
149
149
  :desc => "Add source package managed in a git repo"
150
150
  method_option :deb, :aliases => "-d",
151
151
  :desc => "Add a prebuilt binary deb package only"
152
- method_option :force, :aliases => "-f",
152
+ method_option :force, :aliases => "-f", :type => :boolean,
153
153
  :desc => "Proceed even if the package already exists"
154
154
  method_option :branch, :aliases => "-b",
155
155
  :desc => "Set a default branch other than master (valid only with --git)"
@@ -163,18 +163,12 @@ class RepoCLI < ExtendedThor
163
163
 
164
164
  Dr::GitPackage::setup repo, options["git"], branch
165
165
  when options.has_key?("deb")
166
- Dr::DebPackage::setup repo, options["deb"]
166
+ Dr::DebPackage::setup repo, options["deb"], options["force"]
167
167
  else
168
168
  raise ArgumentError, "Either --git or --deb must be specified"
169
169
  end
170
170
  end
171
171
 
172
- # drepo build [pkg-name] --branch [topic-branch]
173
- # drepo build [pkg-name] --branch [topic-branch] --push [suite] -f
174
- #
175
- # - The old script basically
176
- # - Change versions to date stamps
177
- # - Add support for scratch suite builds
178
172
  desc "build [pkg-name]", "build a package from the sources"
179
173
  method_option :branch, :aliases => "-b", :type => :string,
180
174
  :desc => "build from a different branch"
@@ -203,7 +197,6 @@ class RepoCLI < ExtendedThor
203
197
  end
204
198
  end
205
199
 
206
- # drepo push [pkg-name] -f --suite X --version Y
207
200
  desc "push [pkg-name]", "push a built package to a specified suite"
208
201
  method_option :suite, :aliases => "-s", :type => :string,
209
202
  :desc => "the target suite (defaults to testing)"
data/lib/dr/buildroot.rb CHANGED
@@ -15,7 +15,7 @@ module Dr
15
15
  @repo = "http://mirrordirector.raspbian.org/raspbian/"
16
16
 
17
17
  if br_archive == nil || !File.exists?(br_archive)
18
- setup
18
+ setup arch
19
19
  end
20
20
  end
21
21
 
data/lib/dr/debpackage.rb CHANGED
@@ -2,17 +2,27 @@ require "dr/package"
2
2
 
3
3
  module Dr
4
4
  class DebPackage < Package
5
- def self.setup(repo, deb_file)
6
- puts "Adding the #{File.basename deb_file} package ..."
7
- src_name = `dpkg-deb --field #{deb_file} Source`.chomp
5
+ def self.setup(repo, deb_file, force=false)
6
+ dpkg = ShellCmd.new "dpkg-deb --field #{deb_file} Source", :tag => "dpkg"
7
+ src_name = dpkg.out.chomp
8
8
  if src_name == ""
9
- src_name = `dpkg-deb --field #{deb_file} Package`.chomp
9
+ dpkg = ShellCmd.new "dpkg-deb --field #{deb_file} Package", :tag => "dpkg"
10
+ src_name = dpkg.out.chomp
10
11
  end
11
- puts "Source package: #{src_name}"
12
12
 
13
- version = `dpkg-deb --field #{deb_file} Version`.chomp
13
+ log :info, "Adding the #{File.basename(deb_file).fg("blue")} package"
14
+
15
+ dpkg = ShellCmd.new "dpkg-deb --field #{deb_file} Version", :tag => "dpkg"
16
+ version = dpkg.out.chomp
14
17
 
15
18
  deb_dir = "#{repo.location}/packages/#{src_name}/builds/#{version}"
19
+
20
+ if File.exists?("#{deb_dir}/#{File.basename deb_file}") && !force
21
+ raise "This deb file is already in the repo"
22
+ end
23
+
24
+ log :info, "Adding a build to the #{src_name.fg "blue"} source package"
25
+
16
26
  FileUtils.mkdir_p deb_dir
17
27
  FileUtils.cp "#{deb_file}", "#{deb_dir}/"
18
28
  end
@@ -20,5 +30,11 @@ module Dr
20
30
  def initialize(name, repo)
21
31
  super name, repo
22
32
  end
33
+
34
+ def build(branch=nil, force=false)
35
+ log :warn, "The source of the #{@name.fg "blue"} package is not " +
36
+ "managed by #{"dr".bright}"
37
+ raise "Unable to build the package"
38
+ end
23
39
  end
24
40
  end
data/lib/dr/gitpackage.rb CHANGED
@@ -174,15 +174,6 @@ EOS
174
174
  version
175
175
  end
176
176
 
177
- def build_exists?(version)
178
- File.directory? "#{@repo.location}/packages/#{@name}/builds/#{version}"
179
- end
180
-
181
- def remove_build(version)
182
- raise "Build #{version.fg("blue")} not found" unless build_exists? version
183
- FileUtils.rm_rf "#{@repo.location}/packages/#{@name}/builds/#{version}"
184
- end
185
-
186
177
  private
187
178
  def update_from_origin(branch)
188
179
  log :info, "Pulling changes from origin"
data/lib/dr/package.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "dr/logger"
2
+ require "dr/shellcmd"
2
3
 
3
4
  module Dr
4
5
  class Package
@@ -22,5 +23,14 @@ module Dr
22
23
 
23
24
  versions.sort.reverse
24
25
  end
26
+
27
+ def build_exists?(version)
28
+ File.directory? "#{@repo.location}/packages/#{@name}/builds/#{version}"
29
+ end
30
+
31
+ def remove_build(version)
32
+ raise "Build #{version.fg("blue")} not found" unless build_exists? version
33
+ FileUtils.rm_rf "#{@repo.location}/packages/#{@name}/builds/#{version}"
34
+ end
25
35
  end
26
36
  end
data/lib/dr/pkgversion.rb CHANGED
@@ -38,8 +38,7 @@ module Dr
38
38
  end
39
39
 
40
40
  def ==(o)
41
- @upstream == o.upstream && @debian == o.debian &&
42
- @date == o.date && @build == o.build
41
+ self.to_s == o.to_s
43
42
  end
44
43
 
45
44
  def to_s
data/lib/dr/repo.rb CHANGED
@@ -46,7 +46,7 @@ module Dr
46
46
  f.puts "Codename: #{conf[:codenames][i]}"
47
47
  end
48
48
 
49
- if conf[:name][i].length > 0
49
+ if conf[:name].length > 0
50
50
  f.puts "Origin: #{conf[:name]} - #{s}"
51
51
  f.puts "Label: #{conf[:name]} - #{s}"
52
52
  end
@@ -150,7 +150,7 @@ module Dr
150
150
  versions[suite] = {}
151
151
  reprepro_cmd = "reprepro --basedir #{location}/archive " +
152
152
  "--list-format '${package} ${version}\n' " +
153
- "listfilter #{suite} 'Source (== raspberrypi-firmware)' " +
153
+ "listfilter #{suite} 'Source (== #{pkg_name})' " +
154
154
  "2>/dev/null"
155
155
  reprepro = ShellCmd.new reprepro_cmd, :tag => "reprepro"
156
156
  reprepro.out.chomp.each_line do |line|
@@ -170,7 +170,7 @@ module Dr
170
170
  end
171
171
  else
172
172
  if pkg.history.length == 0
173
- log :err, "Package #{pkg_name} has not been built yet"
173
+ log :err, "No built packages available for #{pkg_name}"
174
174
  log :err, "Please, run a build first and the push."
175
175
  raise "Push failed"
176
176
  end
@@ -186,11 +186,19 @@ module Dr
186
186
  suite = "testing"
187
187
  end
188
188
 
189
- # FIXME: This will not work with packages that don't build a deb
190
- # with the same name as the source package
191
- current_version = query_for_deb_version suite, pkg.name
189
+ debs = Dir["#{@location}/packages/#{pkg.name}/builds/#{version}/*"]
190
+ names = debs.map { |deb| File.basename(deb).split("_")[0] }
191
+
192
+ used_versions = get_subpackage_versions(pkg.name)[to_suite(suite)]
193
+
194
+ is_of_higher_version = true
195
+ names.each do |name|
196
+ if used_versions.has_key?(name) && version <= used_versions[name]
197
+ is_of_higher_version = false
198
+ end
199
+ end
192
200
 
193
- if current_version != nil && current_version >= version
201
+ unless is_of_higher_version
194
202
  log :warn, "Version #{version.fg("blue")} already available in #{suite}"
195
203
  if force
196
204
  reprepro = "reprepro -b #{@location}/archive " +
@@ -204,7 +212,6 @@ module Dr
204
212
  end
205
213
 
206
214
  log :info, "Pushing #{pkg_name} version #{version} to #{suite}"
207
- debs = Dir["#{@location}/packages/#{pkg.name}/builds/#{version}/*"]
208
215
  reprepro = "reprepro -b #{@location}/archive " +
209
216
  "--gnupghome #{location}/gnupg-keyring/ includedeb " +
210
217
  "#{suite} #{debs.join " "}"
@@ -232,20 +239,18 @@ module Dr
232
239
  pkg = get_package pkg_name
233
240
 
234
241
  if is_used? pkg_name
235
- log :warn, "Package #{pkg_name} is still used"
236
- raise "The '#{pkg_name}' package is still used." unless force
242
+ log :warn, "The #{pkg_name.fg "blue"} package is still used"
243
+ raise "Operation canceled, add -f to remove anyway" unless force
237
244
 
238
245
  log :info, "Will be force-removed anyway"
239
- get_suites.zip(versions).each do |suite, version|
240
- log :info, "Removing #{pkg_name} v#{version} from #{suite}"
241
- unpush pkg_name, suite[0] if version != nil
246
+ versions = get_subpackage_versions(pkg_name)
247
+ get_suites.each do |suite, codename|
248
+ unpush pkg_name, suite unless versions[suite].empty?
242
249
  end
243
250
  end
244
251
 
245
- if !is_used?(pkg_name) || force
246
- log :info, "Removing #{pkg_name} from the repository"
247
- FileUtils.rm_rf "#{location}/packages/#{pkg_name}"
248
- end
252
+ log :info, "Removing #{pkg_name} from the repository"
253
+ FileUtils.rm_rf "#{location}/packages/#{pkg_name}"
249
254
  end
250
255
 
251
256
  def remove_build(pkg_name, version, force=false)
@@ -296,5 +301,13 @@ module Dr
296
301
  end
297
302
  end
298
303
  end
304
+
305
+ def to_suite(codename_or_suite)
306
+ get_suites.each do |suite, codename|
307
+ return suite if codename_or_suite == suite || codename_or_suite == codename
308
+ end
309
+
310
+ nil
311
+ end
299
312
  end
300
313
  end
data/lib/dr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dr
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-03 00:00:00.000000000 Z
12
+ date: 2014-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor