dr 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Mkpkg
1
+ # Debian Repository Management Tool
2
2
 
3
3
  TODO: Write a gem description
4
4
 
data/bin/dr CHANGED
@@ -50,45 +50,103 @@ class Archive < ExtendedThor
50
50
  end
51
51
 
52
52
  class List < ExtendedThor
53
- desc "packages", "show a list of source packages in the repo"
53
+ desc "packages", "Show a list of source packages in the repo"
54
54
  def packages()
55
55
  repo = get_repo_handle
56
56
  log :info, "Listing all source packages in the repository"
57
57
 
58
58
  repo.list_packages.each do |pkg|
59
- log :info, " #{pkg.name}"
59
+ log :info, " #{pkg.name.fg "orange"}"
60
60
  end
61
61
  end
62
62
 
63
- desc "versions PACKAGE", "show the history of all available versions for a package"
63
+ desc "versions PACKAGE", "Show the history of all available versions for a package"
64
64
  def versions(pkg_name)
65
65
  repo = get_repo_handle
66
- log :info, "Listing all built versions of '#{pkg_name}'"
66
+ log :info, "Listing all built versions of #{pkg_name.style "pkg-name"}"
67
67
 
68
68
  suites = repo.get_suites
69
69
 
70
70
  pkg = repo.get_package pkg_name
71
71
  pkg.history.each do |version|
72
- line = "#{version}"
73
- suites.each do |suite, codename|
74
- codename = suite if codename == nil
75
- if pkg.build_exists? version
76
- debs = repo.get_build pkg.name, version
77
- subpkgs = debs.map { |p| subpkg = File.basename(p).split("_")[0] }
78
-
79
- all_included = true
80
- subpkgs.each do |subpkg|
81
- unless repo.query_for_deb_version(suite, subpkg) == version
82
- all_included = false
72
+ line = "#{version.style "version"}"
73
+
74
+ if pkg.build_exists? version
75
+ debs = repo.get_build pkg.name, version
76
+
77
+ metadata = repo.get_build_metadata pkg.name, version
78
+ if metadata.has_key? "branch"
79
+ open = "{".fg "dark-grey"
80
+ close = "}".fg "dark-grey"
81
+ line << " " + open + metadata["branch"].fg("blue") + close
82
+ end
83
+
84
+ subpkgs = debs.map { |p| subpkg = File.basename(p).split("_")[0] }
85
+ end
86
+
87
+ open = "[".fg "dark-grey"
88
+ close = "]".fg "dark-grey"
89
+
90
+ if subpkgs.length == 0
91
+ line << " " + open + "broken".fg("red") + close
92
+ else
93
+ suites.each do |suite, codename|
94
+ codename = suite if codename == nil
95
+
96
+ colour = case suite
97
+ when "stable" then "red"
98
+ when "testing" then "yellow"
99
+ when "unstable" then "green"
100
+ else nil end
101
+
102
+ all_included = true
103
+ subpkgs.each do |subpkg|
104
+ unless repo.query_for_deb_version(suite, subpkg) == version
105
+ all_included = false
106
+ end
83
107
  end
84
- end
85
108
 
86
- line << " [#{codename}]" if all_included
109
+ if all_included
110
+ if colour
111
+ line << " " + open + codename.fg(colour) + close
112
+ else
113
+ line << " " + open + codename + close
114
+ end
115
+ end
87
116
  end
88
117
  end
89
118
  log :info, " #{line}"
90
119
  end
91
120
  end
121
+
122
+ desc "suite SUITE", "Show the names and versions of packages in the suite"
123
+ def suite(suite)
124
+ repo = get_repo_handle
125
+
126
+ suites = repo.get_suites
127
+ exists = suites.inject(false) { |r, s| r || s.include?(suite) }
128
+ raise "Suite '#{suite}' doesn't exist" unless exists
129
+
130
+ log :info, "Listing all the packages in #{suite.fg "blue"}"
131
+
132
+ suite = repo.codename_to_suite suite
133
+ suite_packages = repo.list_packages
134
+ suite_packages.each do |pkg|
135
+ versions = repo.get_subpackage_versions pkg.name
136
+ unless versions[suite].empty?
137
+ if versions[suite].length == 1 && versions[suite].has_key?(pkg.name)
138
+ log :info, " #{pkg.name.style "pkg-name"} " +
139
+ "#{versions[suite][pkg.name].style "version"}"
140
+ else
141
+ log :info, " #{pkg.name.style "pkg-name"}"
142
+ versions[suite].each do |subpkg, version|
143
+ log :info, " #{subpkg.style "subpkg-name"} " +
144
+ "#{version.style "version"}"
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
92
150
  end
93
151
 
94
152
  class RepoCLI < ExtendedThor
@@ -188,6 +246,11 @@ class RepoCLI < ExtendedThor
188
246
  pkg = repo.get_package pkg_name
189
247
  version = pkg.build branch, force
190
248
 
249
+ unless version
250
+ log :warn, "Build stopped (add -f to build anyway)"
251
+ return
252
+ end
253
+
191
254
  if options["push"] && version
192
255
  if options["push"] == "push"
193
256
  repo.push pkg.name, version, "testing" # FIXME: should be configurable
@@ -223,6 +286,7 @@ class RepoCLI < ExtendedThor
223
286
  end
224
287
 
225
288
  desc "list SUBCOMMAND [ARGS]", "show information about packages"
289
+ map "l" => :list, "ls" => :list
226
290
  subcommand "list", List
227
291
 
228
292
  desc "rm [pkg-name]", "remove a package completely from the build system"
@@ -241,7 +305,30 @@ class RepoCLI < ExtendedThor
241
305
  repo.remove_build pkg_name, version, options["force"] == true
242
306
  end
243
307
 
244
- desc "release", "push all the packages from testing to release"
308
+ desc "update", "Update and rebuild (if necessary) all the packages in the suite"
309
+ def update(suite="testing")
310
+ log :info, "Updating all packages in the #{suite.fg "blue"} suite"
311
+ repo = get_repo_handle
312
+
313
+ updated = 0
314
+ repo.list_packages(suite).each do |pkg|
315
+ log :info, "Updating #{pkg.name.style "pkg-name"}"
316
+ begin
317
+ version = pkg.build
318
+ rescue Dr::Package::UnableToBuild
319
+ log :info, ""
320
+ next
321
+ end
322
+
323
+ log :info, ""
324
+ repo.push pkg.name, version, suite if version
325
+ updated += 1
326
+ end
327
+
328
+ log :info, "Updated #{updated.to_s.fg "blue"} packages in #{suite.fg "blue"}"
329
+ end
330
+
331
+ desc "release", "Push all the packages from testing to release"
245
332
  def release
246
333
  repo = get_repo_handle
247
334
 
@@ -251,6 +338,19 @@ class RepoCLI < ExtendedThor
251
338
  end
252
339
  end
253
340
 
341
+ desc "force-sync", "Force cloning the sources repository from scratch again"
342
+ def force_sync(pkg_name)
343
+ repo = get_repo_handle
344
+ pkg = repo.get_package pkg_name
345
+
346
+ if pkg.is_a? Dr::GitPackage
347
+ pkg.reinitialise_repo
348
+ else
349
+ raise "The source of #{pkg_name.style "pkg-name"} is not managed by " +
350
+ "#{"dr".bright}"
351
+ end
352
+ end
353
+
254
354
  desc "snapshot", "save a snapshot of the archive"
255
355
  def snapshot(tag)
256
356
  repo = get_repo_handle
@@ -263,7 +363,7 @@ class RepoCLI < ExtendedThor
263
363
  end
264
364
 
265
365
  begin
266
- RepoCLI.start ARGV
366
+ RepoCLI.start ARGV
267
367
  rescue Exception => e
268
368
  Dr::Logger.log :err, e.to_s
269
369
  end
data/lib/dr/debpackage.rb CHANGED
@@ -10,24 +10,24 @@ module Dr
10
10
  src_name = dpkg.out.chomp
11
11
  end
12
12
 
13
- log :info, "Adding the #{File.basename(deb_file).fg("blue")} package"
13
+ deb_file_name = File.basename(deb_file)
14
+ log :info, "Adding the #{deb_file_name.style "subpkg-name"} package"
14
15
 
15
16
  dpkg = ShellCmd.new "dpkg-deb --field #{deb_file} Version", :tag => "dpkg"
16
17
  version = dpkg.out.chomp
17
18
 
18
19
  deb_dir = "#{repo.location}/packages/#{src_name}/builds/#{version}"
19
20
 
20
- if File.exists?("#{deb_dir}/#{File.basename deb_file}") && !force
21
+ if File.exists?("#{deb_dir}/#{deb_file_name}") && !force
21
22
  raise "This deb file is already in the repo"
22
23
  end
23
24
 
24
- log :info, "Adding a build to the #{src_name.fg "blue"} source package"
25
-
26
- log :info, "Signing the deb file"
27
- repo.sign_deb deb_file
28
-
25
+ log :info, "Adding a build to the #{src_name.style "pkg-name"} source package"
29
26
  FileUtils.mkdir_p deb_dir
30
27
  FileUtils.cp "#{deb_file}", "#{deb_dir}/"
28
+
29
+ log :info, "Signing the deb file"
30
+ repo.sign_deb "#{deb_dir}/#{deb_file_name}"
31
31
  end
32
32
 
33
33
  def initialize(name, repo)
@@ -35,9 +35,9 @@ module Dr
35
35
  end
36
36
 
37
37
  def build(branch=nil, force=false)
38
- log :warn, "The source of the #{@name.fg "blue"} package is not " +
39
- "managed by #{"dr".bright}"
40
- raise "Unable to build the package"
38
+ log :warn, "The sources of the #{@name.style "pkg-name"} package are " +
39
+ "not managed by #{"dr".bright}"
40
+ raise UnableToBuild.new "Unable to build the package"
41
41
  end
42
42
  end
43
43
  end
data/lib/dr/gitpackage.rb CHANGED
@@ -2,20 +2,30 @@ require "dr/package"
2
2
  require "dr/pkgversion"
3
3
  require "dr/shellcmd"
4
4
 
5
+ require "yaml"
6
+
5
7
  module Dr
6
8
  class GitPackage < Package
7
9
  def self.setup(repo, git_addr, default_branch, force=false)
8
10
  Dir.mktmpdir do |tmp|
9
- git_cmd = "git clone --branch #{default_branch} #{git_addr} #{tmp}/git"
11
+ git_cmd = "git clone --mirror --branch #{default_branch} " +
12
+ "#{git_addr} #{tmp}/git"
13
+ ShellCmd.new git_cmd, :tag => "git", :show_out => true
14
+
15
+ FileUtils.mkdir_p "#{tmp}/src"
16
+
17
+ log :info, "Extracting the sources"
18
+ git_cmd ="git --git-dir #{tmp}/git --bare archive " +
19
+ "--format tar #{default_branch} | tar x -C #{tmp}/src"
10
20
  ShellCmd.new git_cmd, :tag => "git", :show_out => true
11
21
 
12
- unless File.exists? "#{tmp}/git/debian/control"
22
+ unless File.exists? "#{tmp}/src/debian/control"
13
23
  log :err, "The debian packaging files not found in the repository"
14
24
  raise "Adding a package from #{git_addr} failed"
15
25
  end
16
26
 
17
27
  src_name = nil
18
- File.open "#{tmp}/git/debian/control", "r" do |f|
28
+ File.open "#{tmp}/src/debian/control", "r" do |f|
19
29
  f.each_line do |line|
20
30
  match = line.match /^Source: (.+)$/
21
31
  if match
@@ -36,16 +46,16 @@ module Dr
36
46
  raise "Adding failed"
37
47
  end
38
48
 
39
- log :info, "Adding #{src_name.fg "blue"} to the repository"
49
+ log :info, "Adding #{src_name.style "pkg-name"} to the repository"
40
50
  FileUtils.mkdir_p "#{pkg_dir}"
41
51
 
42
52
  log :info, "Setting up builds directory"
43
53
  FileUtils.mkdir_p "#{pkg_dir}/builds"
44
54
 
45
55
  log :info, "Setting up the source directory"
46
- FileUtils.mv "#{tmp}/git/.git", "#{pkg_dir}/source"
56
+ FileUtils.mv "#{tmp}/git", "#{pkg_dir}/source"
47
57
 
48
- log :info, "Package #{src_name} added successfully"
58
+ log :info, "The #{src_name.style "pkg-name"} package added successfully"
49
59
  end
50
60
  end
51
61
 
@@ -53,11 +63,57 @@ module Dr
53
63
  super name, repo
54
64
 
55
65
  @git_dir = "#{repo.location}/packages/#{name}/source"
66
+ @default_branch = get_current_branch
67
+ end
56
68
 
57
- git_cmd = ShellCmd.new "git --git-dir #{@git_dir} branch", {
58
- :tag => "git-clone"
59
- }
60
- @default_branch = git_cmd.out.chomp.lines.grep(/^*/)[0][2..-1]
69
+ def reinitialise_repo
70
+ git_addr = get_repo_url
71
+
72
+ log :info, "Re-downloading the source repository of " +
73
+ "#{@name.style "pkg-name"}"
74
+ Dir.mktmpdir do |tmp|
75
+ git_cmd = "git clone --mirror --branch #{@default_branch} " +
76
+ "#{git_addr} #{tmp}/git"
77
+ ShellCmd.new git_cmd, :tag => "git", :show_out => true
78
+
79
+ src_dir = "#{tmp}/src"
80
+ FileUtils.mkdir_p src_dir
81
+
82
+ log :info, "Extracting the sources"
83
+ git_cmd ="git --git-dir #{@git_dir} --bare archive " +
84
+ "--format tar #{@default_branch} | tar x -C #{src_dir}"
85
+ ShellCmd.new git_cmd, :tag => "git", :show_out => true
86
+
87
+ unless File.exists? "#{tmp}/src/debian/control"
88
+ log :err, "The debian packaging files not found in the repository"
89
+ raise "Adding a package from #{git_addr} failed"
90
+ end
91
+
92
+ src_name = nil
93
+ File.open "#{tmp}/src/debian/control", "r" do |f|
94
+ f.each_line do |line|
95
+ match = line.match /^Source: (.+)$/
96
+ if match
97
+ src_name = match.captures[0]
98
+ break
99
+ end
100
+ end
101
+ end
102
+
103
+ unless src_name
104
+ log :err, "Couldn't identify the source package"
105
+ raise "Adding a package from #{git_addr} failed"
106
+ end
107
+
108
+ unless src_name == @name
109
+ log :err, "The name of the package in the repo has changed"
110
+ raise "Adding a package from #{git_addr} failed"
111
+ end
112
+
113
+ src_dir = "#{@repo.location}/packages/#{@name}/source"
114
+ FileUtils.rm_rf src_dir
115
+ FileUtils.mv "#{tmp}/git", "#{src_dir}"
116
+ end
61
117
  end
62
118
 
63
119
  def build(branch=nil, force=false)
@@ -68,17 +124,17 @@ module Dr
68
124
  if curr_rev != orig_rev || force
69
125
  Dir.mktmpdir do |src_dir|
70
126
  log :info, "Extracting the sources"
71
- git_cmd ="git --git-dir #{@git_dir} archive " +
127
+ git_cmd ="git --git-dir #{@git_dir} --bare archive " +
72
128
  "--format tar #{branch} | tar x -C #{src_dir}"
73
129
  ShellCmd.new git_cmd, :tag => "git", :show_out => true
74
130
 
75
131
  version = PkgVersion.new get_version "#{src_dir}/debian/changelog"
76
- log :info, "Source version: #{version}"
132
+ log :info, "Source version: #{version.to_s.style "version"}"
77
133
 
78
134
  while build_exists? version
79
135
  version.increment!
80
136
  end
81
- log :info, "Building version: #{version}"
137
+ log :info, "Building version: #{version.to_s.style "version"}"
82
138
 
83
139
  log :info, "Updating changelog"
84
140
  now = Time.new.strftime("%a, %-d %b %Y %T %z")
@@ -108,8 +164,9 @@ module Dr
108
164
  end
109
165
  arches.each do |arch|
110
166
  @repo.buildroot(arch).open do |br|
111
- log :info, "Building the #{@name.fg("blue")} package " +
112
- "v#{version} for #{arch}"
167
+ log :info, "Building the #{@name.style "pkg-name"} package " +
168
+ "version #{version.to_s.style "version"} for #{arch}"
169
+
113
170
  # Moving to the proper directory
114
171
  build_dir_name = "#{@name}-#{version.upstream}"
115
172
  build_dir = "#{br}/#{build_dir_name}"
@@ -164,15 +221,22 @@ EOS
164
221
  debs.each do |pkg|
165
222
  FileUtils.cp pkg, build_dir
166
223
 
167
- log :info, "Signing the #{File.basename(pkg).fg("blue")} package"
168
- @repo.sign_deb "#{build_dir}/#{File.basename(pkg)}"
224
+ deb_filename = File.basename(pkg)
225
+ log :info, "Signing the #{deb_filename.style "subpkg-name"} package"
226
+ @repo.sign_deb "#{build_dir}/#{deb_filename}"
227
+ end
228
+
229
+ log :info, "Writing package metadata"
230
+ File.open "#{build_dir}/.metadata", "w" do |f|
231
+ YAML.dump({"branch" => branch}, f)
169
232
  end
233
+ log :info, "The #{@name.style "pkg-name"} package has been " +
234
+ "built successfully."
170
235
  end
171
236
  end
172
237
  end
173
238
  else
174
- log :info, "There were no changes in the #{pkg.name.fg("blue")} package"
175
- log :info, "Build stopped (add -f to build anyway)"
239
+ log :info, "There were no changes in the #{@name.style "pkg-name"} package"
176
240
  end
177
241
  version
178
242
  end
@@ -181,26 +245,26 @@ EOS
181
245
  def update_from_origin(branch)
182
246
  log :info, "Pulling changes from origin"
183
247
 
184
- git_cmd = "git --git-dir #{@git_dir} rev-parse #{branch} 2>/dev/null"
248
+ git_cmd = "git --git-dir #{@git_dir} --bare rev-parse #{branch} 2>/dev/null"
185
249
  git = ShellCmd.new git_cmd, :tag => "git"
186
250
 
187
251
  original_rev = git.out.chomp
188
252
  original_rev = nil if original_rev == branch
189
253
 
190
254
  begin
191
- if @default_branch == branch
192
- git_cmd = "git --git-dir #{@git_dir} pull origin #{branch}"
255
+ #if @default_branch == branch
256
+ git_cmd = "git --git-dir #{@git_dir} --bare fetch origin"
193
257
  ShellCmd.new git_cmd, :tag => "git", :show_out => true
194
- else
195
- git_cmd = "git --git-dir #{@git_dir} fetch origin #{branch}:#{branch}"
196
- ShellCmd.new git_cmd, :tag => "git", :show_out => true
197
- end
258
+ #else
259
+ # git_cmd = "git --git-dir #{@git_dir} --bare fetch origin #{branch}:#{branch}"
260
+ # ShellCmd.new git_cmd, :tag => "git", :show_out => true
261
+ #end
198
262
  rescue Exception => e
199
263
  log :err, "Unable to pull from origin"
200
264
  raise e
201
265
  end
202
266
 
203
- git_cmd = "git --git-dir #{@git_dir} rev-parse #{branch} 2>/dev/null"
267
+ git_cmd = "git --git-dir #{@git_dir} --bare rev-parse #{branch} 2>/dev/null"
204
268
  git = ShellCmd.new git_cmd, :tag => "git"
205
269
  current_rev = git.out.chomp
206
270
 
@@ -242,5 +306,18 @@ EOS
242
306
 
243
307
  arches.uniq
244
308
  end
309
+
310
+ def get_repo_url
311
+ git_cmd = "git --git-dir #{@git_dir} --bare remote show origin -n"
312
+ git = ShellCmd.new git_cmd, :tag => "git"
313
+ git.out.lines.grep(/Fetch URL/)[0].chomp[13..-1]
314
+ end
315
+
316
+ def get_current_branch
317
+ git_cmd = ShellCmd.new "git --git-dir #{@git_dir} --bare branch", {
318
+ :tag => "git"
319
+ }
320
+ git_cmd.out.chomp.lines.grep(/^\*/)[0][2..-1].chomp
321
+ end
245
322
  end
246
323
  end
data/lib/dr/logger.rb CHANGED
@@ -4,11 +4,13 @@ tco_conf = Tco::config
4
4
 
5
5
  tco_conf.names["green"] = "#99ad6a"
6
6
  tco_conf.names["yellow"] = "#d8ad4c"
7
- tco_conf.names["red"] = "#cf6a4c"
7
+ tco_conf.names["red"] = "#cc333f" #"#cf6a4c"
8
8
  tco_conf.names["light-grey"] = "#ababab"
9
9
  tco_conf.names["dark-grey"] = "#2b2b2b"
10
10
  tco_conf.names["purple"] = "#90559e"
11
- tco_conf.names["blue"] = "#1b8efa"
11
+ tco_conf.names["blue"] = "#4D9EEB" #"#1b8efa"
12
+ tco_conf.names["orange"] = "#ff842a"
13
+ tco_conf.names["brown"] = "#6a4a3c"
12
14
 
13
15
  tco_conf.styles["info"] = {
14
16
  :fg => "green",
@@ -43,6 +45,27 @@ tco_conf.styles["log-head"] = {
43
45
  :underline => false
44
46
  }
45
47
 
48
+ tco_conf.styles["pkg-name"] = {
49
+ :fg => "orange",
50
+ :bg => "",
51
+ :bright => false,
52
+ :underline => false
53
+ }
54
+
55
+ tco_conf.styles["subpkg-name"] = {
56
+ :fg => "purple",
57
+ :bg => "",
58
+ :bright => false,
59
+ :underline => false
60
+ }
61
+
62
+ tco_conf.styles["version"] = {
63
+ :fg => "brown",
64
+ :bg => "",
65
+ :bright => false,
66
+ :underline => false
67
+ }
68
+
46
69
  Tco::reconfigure tco_conf
47
70
 
48
71
  module Dr
@@ -74,7 +97,7 @@ module Dr
74
97
  end
75
98
 
76
99
  def tag(tag, msg)
77
- tag.fg("blue") << " " << msg
100
+ tag.fg("blue").bg("dark-grey") << " " << msg
78
101
  end
79
102
  end
80
103
  end
data/lib/dr/package.rb CHANGED
@@ -3,6 +3,9 @@ require "dr/shellcmd"
3
3
 
4
4
  module Dr
5
5
  class Package
6
+ class UnableToBuild < RuntimeError
7
+ end
8
+
6
9
  attr_reader :name
7
10
 
8
11
  include Logger
@@ -32,5 +35,9 @@ module Dr
32
35
  raise "Build #{version.fg("blue")} not found" unless build_exists? version
33
36
  FileUtils.rm_rf "#{@repo.location}/packages/#{@name}/builds/#{version}"
34
37
  end
38
+
39
+ def <=>(o)
40
+ self.name <=> o.name
41
+ end
35
42
  end
36
43
  end
data/lib/dr/pkgversion.rb CHANGED
@@ -37,6 +37,14 @@ module Dr
37
37
  self
38
38
  end
39
39
 
40
+ def <(o)
41
+ self.to_s < o.to_s
42
+ end
43
+
44
+ def <=(o)
45
+ self.to_s <= o.to_s
46
+ end
47
+
40
48
  def ==(o)
41
49
  self.to_s == o.to_s
42
50
  end
data/lib/dr/repo.rb CHANGED
@@ -7,6 +7,7 @@ require "dr/gnupg"
7
7
  require "dr/buildroot"
8
8
 
9
9
  require "fileutils"
10
+ require "yaml"
10
11
 
11
12
  module Dr
12
13
  class Repo
@@ -72,15 +73,23 @@ module Dr
72
73
 
73
74
  def list_packages(suite=nil)
74
75
  pkgs = []
76
+
75
77
  if suite
76
- a = 1
78
+ Dir.foreach @packages_dir do |pkg_name|
79
+ unless pkg_name =~ /^\./
80
+ versions = get_subpackage_versions pkg_name
81
+ unless versions[codename_to_suite suite].empty?
82
+ pkgs.push get_package pkg_name
83
+ end
84
+ end
85
+ end
77
86
  else
78
87
  Dir.foreach @packages_dir do |pkg_name|
79
88
  pkgs.push get_package pkg_name unless pkg_name =~ /^\./
80
89
  end
81
90
  end
82
91
 
83
- pkgs
92
+ pkgs.sort
84
93
  end
85
94
 
86
95
  def buildroot(arch)
@@ -89,7 +98,7 @@ module Dr
89
98
 
90
99
  def get_package(name)
91
100
  unless File.exists? "#{@packages_dir}/#{name}"
92
- raise "Package '#{name}' doesn't exist in the repo."
101
+ raise "Package #{name.style "pkg-name"} doesn't exist in the repo"
93
102
  end
94
103
 
95
104
  if File.exists? "#{@packages_dir}/#{name}/source"
@@ -150,7 +159,8 @@ module Dr
150
159
  versions[suite] = {}
151
160
  reprepro_cmd = "reprepro --basedir #{location}/archive " +
152
161
  "--list-format '${package} ${version}\n' " +
153
- "listfilter #{suite} 'Source (== #{pkg_name})' " +
162
+ "listfilter #{suite} 'Source (== #{pkg_name}) | " +
163
+ "Package (== #{pkg_name})' " +
154
164
  "2>/dev/null"
155
165
  reprepro = ShellCmd.new reprepro_cmd, :tag => "reprepro"
156
166
  reprepro.out.chomp.each_line do |line|
@@ -189,7 +199,7 @@ module Dr
189
199
  debs = Dir["#{@location}/packages/#{pkg.name}/builds/#{version}/*"]
190
200
  names = debs.map { |deb| File.basename(deb).split("_")[0] }
191
201
 
192
- used_versions = get_subpackage_versions(pkg.name)[to_suite(suite)]
202
+ used_versions = get_subpackage_versions(pkg.name)[codename_to_suite(suite)]
193
203
 
194
204
  is_of_higher_version = true
195
205
  names.each do |name|
@@ -199,7 +209,9 @@ module Dr
199
209
  end
200
210
 
201
211
  unless is_of_higher_version
202
- log :warn, "Version #{version.fg("blue")} already available in #{suite}"
212
+ log :warn, "The #{suite} suite already contains " +
213
+ "#{pkg.name.style "pkg-name"} version " +
214
+ "#{version.to_s.style "version"}"
203
215
  if force
204
216
  reprepro = "reprepro -b #{@location}/archive " +
205
217
  "--gnupghome #{location}/gnupg-keyring/ removesrc " +
@@ -211,7 +223,8 @@ module Dr
211
223
  end
212
224
  end
213
225
 
214
- log :info, "Pushing #{pkg_name} version #{version} to #{suite}"
226
+ log :info, "Pushing #{pkg_name.style "pkg-name"} version " +
227
+ "#{version.to_s.style "version"} to #{suite}"
215
228
  reprepro = "reprepro -b #{@location}/archive " +
216
229
  "--gnupghome #{location}/gnupg-keyring/ includedeb " +
217
230
  "#{suite} #{debs.join " "}"
@@ -228,7 +241,7 @@ module Dr
228
241
  raise "Unpush failed"
229
242
  end
230
243
 
231
- log :info, "Removing #{pkg_name} from #{suite}"
244
+ log :info, "Removing #{pkg_name.style "pkg-name"} from #{suite}"
232
245
  reprepro = "reprepro -b #{@location}/archive " +
233
246
  "--gnupghome #{location}/gnupg-keyring/ removesrc " +
234
247
  "#{suite} #{pkg.name}"
@@ -239,7 +252,7 @@ module Dr
239
252
  pkg = get_package pkg_name
240
253
 
241
254
  if is_used? pkg_name
242
- log :warn, "The #{pkg_name.fg "blue"} package is still used"
255
+ log :warn, "The #{pkg_name.style "pkg-name"} package is still used"
243
256
  raise "Operation canceled, add -f to remove anyway" unless force
244
257
 
245
258
  log :info, "Will be force-removed anyway"
@@ -249,7 +262,7 @@ module Dr
249
262
  end
250
263
  end
251
264
 
252
- log :info, "Removing #{pkg_name} from the repository"
265
+ log :info, "Removing #{pkg_name.style "pkg-name"} from the repository"
253
266
  FileUtils.rm_rf "#{location}/packages/#{pkg_name}"
254
267
  end
255
268
 
@@ -258,20 +271,20 @@ module Dr
258
271
 
259
272
  if is_used?(pkg_name, version)
260
273
  if force
261
- log :info, "Force-removing #{version.fg("blue")} version of " +
262
- "#{pkg_name.fg("blue")}"
274
+ log :info, "Force-removing #{version.style "version"} version of " +
275
+ "#{pkg_name.style "pkg-name"}"
263
276
  versions_by_suite = get_subpackage_versions pkg_name
264
277
  versions_by_suite.each do |suite, versions|
265
278
  unpush pkg_name, suite if versions.has_value? version
266
279
  end
267
280
  else
268
- log :warn, "This build of #{pkg_name} is " +
281
+ log :warn, "This build of #{pkg_name.style "pkg-name"} is " +
269
282
  "still being used, add -f to force-remove"
270
283
  return
271
284
  end
272
285
  else
273
- log :info, "Removing the #{version.fg("blue")} version of " +
274
- "#{pkg_name.fg("blue")}"
286
+ log :info, "Removing the #{version.style "version"} version of " +
287
+ "#{pkg_name.style "pkg-name"}"
275
288
  end
276
289
 
277
290
  pkg.remove_build version
@@ -284,11 +297,25 @@ module Dr
284
297
  raise "The package hasn't been built yet." unless hist.length > 0
285
298
  version = hist[0] unless version
286
299
 
287
- raise "Build #{version} doesn't exist" unless pkg.build_exists? version
300
+ unless pkg.build_exists? version
301
+ raise "Build #{version.style "version"} doesn't exist"
302
+ end
288
303
 
289
304
  Dir["#{@location}/packages/#{pkg.name}/builds/#{version}/*"]
290
305
  end
291
306
 
307
+ def get_build_metadata(pkg_name, version)
308
+ pkg = get_package pkg_name
309
+ raise "Build #{version} doesn't exist" unless pkg.build_exists? version
310
+
311
+ md_file = "#{@location}/packages/#{pkg.name}/builds/#{version}/.metadata"
312
+ if File.exists? md_file
313
+ YAML.load_file md_file
314
+ else
315
+ {}
316
+ end
317
+ end
318
+
292
319
  def sign_deb(deb)
293
320
  keyring = "#{@location}/gnupg-keyring"
294
321
  gpg = GnuPG.new keyring
@@ -298,6 +325,14 @@ module Dr
298
325
  ShellCmd.new cmd, :tag => "dpkg-sig", :show_out => true
299
326
  end
300
327
 
328
+ def codename_to_suite(codename_or_suite)
329
+ get_suites.each do |suite, codename|
330
+ return suite if codename_or_suite == suite || codename_or_suite == codename
331
+ end
332
+
333
+ nil
334
+ end
335
+
301
336
  private
302
337
  def get_key
303
338
  File.open "#{@location}/archive/conf/distributions", "r" do |f|
@@ -319,13 +354,5 @@ module Dr
319
354
  end
320
355
  end
321
356
  end
322
-
323
- def to_suite(codename_or_suite)
324
- get_suites.each do |suite, codename|
325
- return suite if codename_or_suite == suite || codename_or_suite == codename
326
- end
327
-
328
- nil
329
- end
330
357
  end
331
358
  end
data/lib/dr/shellcmd.rb CHANGED
@@ -53,14 +53,14 @@ module Dr
53
53
  if @status.exitstatus != @expect
54
54
  out_lines = @out.split "\n"
55
55
  if out_lines.length > 10
56
- out_lines = out_lines[-9..-1]
56
+ out_lines = out_lines[-10..-1]
57
57
  end
58
58
 
59
59
  out_lines.each do |l|
60
- l = @tag.fg("#1b8efa") + " " + l if @tag
60
+ l = tag(@tag, l.fg("red")) if @tag
61
61
  log(:err, l.chomp)
62
62
  end
63
- raise "'#{@cmd}' failed!" if @raise_on_error
63
+ raise "'#{@cmd}' failed!".fg("red") if @raise_on_error
64
64
  end
65
65
  end
66
66
  end
data/lib/dr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dr
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
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.6
4
+ version: 0.1.0
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-05 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor