dr 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f081cd07df3b86b2a8818d16a0c2b76c3205514d
4
- data.tar.gz: e873f13774d8f4bccf3d6b9ccec059150bfdd7ef
3
+ metadata.gz: 242402de0362275310fd746e3c9ba832a963fd0d
4
+ data.tar.gz: 5a0a15e68b0863c37c19dc556d9a3aff43a61989
5
5
  SHA512:
6
- metadata.gz: af79fd771e8a4ab7693ff38c5dfd78b490c57bf19eb9fd461d6a65c6e3fdcadfc86050055e45e32ca2f07dcbf275e4f1175b1ad81aec0e02a48e41984a6bab49
7
- data.tar.gz: 34932b9939ca7c0a433af6df9e6b83d1c009bbe74128bc5eebf7f43ca20ae453f0cf42649438fd0dea0490eae63d734db372c1134b60823a454a287abd8554b0
6
+ metadata.gz: 540afeb391762426284f47ff8defc361b1d7aad061c39af8ebe7ca494175d3b5357c9eb3af6141179d325f9250619c0a7460879a7a178b29daacc55f0dfdbf43
7
+ data.tar.gz: cabec28d4f33d8a1a0ee1cc5d6a9a59b27b004c86c96bf2d135b51514cb8fd70367e8c0351a6915159fbbf31fe714a208af4860f787a4635b8e0ce5b8c478e18
data/bin/dr CHANGED
@@ -7,6 +7,7 @@ require "thor"
7
7
  require "fileutils"
8
8
  require "io/console"
9
9
 
10
+ require "dr"
10
11
  require "dr/repo"
11
12
  require "dr/gitpackage"
12
13
  require "dr/debpackage"
@@ -21,15 +22,11 @@ class ExtendedThor < Thor
21
22
  include Dr::Logger
22
23
 
23
24
  def get_repo_handle
24
- unless @conf
25
- @conf = Dr::Config.new ["/etc/dr.conf", "~/.dr.conf"]
26
- end
27
-
28
25
  if options.has_key? "repo"
29
26
  Dr::Repo.new options["repo"]
30
27
  else
31
- if @conf.default_repo != nil
32
- Dr::Repo.new @conf.repositories[@conf.default_repo][:location]
28
+ if Dr.config.default_repo != nil
29
+ Dr::Repo.new Dr.config.repositories[Dr.config.default_repo][:location]
33
30
  else
34
31
  log :warn, "No repo was specified, using '#{Dir.pwd}'."
35
32
  Dr::Repo.new Dir.pwd
@@ -166,7 +163,7 @@ class RepoCLI < ExtendedThor
166
163
  :arches => ["amd64"],
167
164
  :components => ["main"],
168
165
  :suites => ["stable", "testing", "unstable"],
169
- :base => "Kano OS",
166
+ :distro => "Kano OS",
170
167
  :codenames => []
171
168
  }
172
169
 
@@ -176,27 +173,46 @@ class RepoCLI < ExtendedThor
176
173
  desc = ask " Description [#{repo_conf[:desc]}]:"
177
174
  repo_conf[:desc] = desc if desc.length > 0
178
175
 
179
- base_map = {}
180
- puts " Base OS [pick one]: "
181
- Dr::BuildRoot.os_bases.each_with_index do |base, index|
182
- base_name, base_params = base
183
- base_map[index+1] = base_name
176
+ distro_map = {}
177
+ puts " Distribution [pick one]: "
178
+ Dr::config.distros.each_with_index do |distro, index|
179
+ distro_name, distro_params = distro
180
+ distro_map[index+1] = distro_name
184
181
 
185
- base_name = base_name.fg "yellow" if base_name == repo_conf[:base]
186
- puts " [#{index+1}] #{base_name}"
182
+ distro_name = distro_name.fg "yellow" if distro_name == repo_conf[:distro]
183
+ puts " [#{index+1}] #{distro_name}"
187
184
  end
188
185
 
189
- base = ask " Your choice: "
190
- until base.length == 0 || base_map.has_key?(base.to_i)
191
- base = ask " Your choice: "
186
+ distro = ask " Your choice: "
187
+ until distro.length == 0 || distro_map.has_key?(distro.to_i)
188
+ distro = ask " Your choice: "
192
189
  end
193
- repo_conf[:base] = base_map[base.to_i] if base.length > 0
190
+ repo_conf[:distro] = distro_map[distro.to_i] if distro.length > 0
194
191
 
192
+ require 'pp'
195
193
  # guess default arch
196
- repo_conf[:arches] = [Dr::BuildRoot.os_bases[repo_conf[:base]][:arches][0]]
194
+ pp Dr::config.distros
195
+ pp Dr::config.distros[repo_conf[:distro]]
196
+ repo_conf[:arches] = [Dr::config.distros[repo_conf[:distro]][:arches][0]]
197
+
198
+ while true
199
+ str = ask " Architectures [#{repo_conf[:arches].join(" ").fg("yellow")}]:"
200
+ break if str.length == 0
201
+
202
+ arches = str.split(/\s+/)
203
+ arches_valid = arches.reduce(true) do |acc, arch|
204
+ supported = Dr::config.distros[repo_conf[:distro]][:arches].include?(arch)
205
+ if !supported
206
+ puts " " + "#{arch.fg "yellow"}" + " not supported by the distro"
207
+ end
197
208
 
198
- arches = ask " Architectures [#{repo_conf[:arches].join(" ").fg("yellow")}]:"
199
- repo_conf[:arches] = arches.split(/\s+/) if arches.length > 0
209
+ supported
210
+ end
211
+ next if !arches_valid
212
+
213
+ repo_conf[:arches] = arches
214
+ break
215
+ end
200
216
 
201
217
  components = ask " Components [#{repo_conf[:components].join(" ").fg("yellow")}]:"
202
218
  repo_conf[:components] = components.split /\s+/ if components.length > 0
@@ -360,6 +376,40 @@ class RepoCLI < ExtendedThor
360
376
  log :info, "Updated #{updated.to_s.fg "blue"} packages in #{suite.fg "blue"}"
361
377
  end
362
378
 
379
+ desc "git-tag-release", "Mark relased packages' repositories"
380
+ method_option :force, :aliases => "-f", :type => :boolean,
381
+ :desc => "Force override existing tags"
382
+ method_option :package, :aliases => "-p", :type => :string,
383
+ :desc => "Only tag a single package"
384
+ method_option :summary, :aliases => "-s", :type => :string,
385
+ :desc => "A summary for the release (Github only)"
386
+ method_option :title, :aliases => "-t", :type => :string,
387
+ :desc => "A title for the release (Github only)"
388
+ def git_tag_release(tag)
389
+ repo = get_repo_handle
390
+
391
+ packages = if options["package"] == nil
392
+ repo.list_packages "stable"
393
+ else
394
+ if repo.get_subpackage_versions(options["package"])["stable"].empty?
395
+ log :warn, "This package isn't in the #{"stable".fg "green"} branch, skipping."
396
+ end
397
+
398
+ [repo.get_package(options["package"])]
399
+ end
400
+
401
+ packages.each do |pkg|
402
+ if pkg.is_a? Dr::GitPackage
403
+ version = repo.get_subpackage_versions(pkg.name)["stable"].values.max
404
+ bm = repo.get_build_metadata pkg.name, version
405
+
406
+ pkg.tag_release tag, bm["revision"], options
407
+ else
408
+ log :info, "#{pkg.name.style "pkg-name"} is not associated with a git repo, skipping"
409
+ end
410
+ end
411
+ end
412
+
363
413
  desc "release", "Push all the packages from testing to release"
364
414
  method_option :force, :aliases => "-f", :type => :boolean,
365
415
  :desc => "Force-push all released packages"
@@ -368,8 +418,9 @@ class RepoCLI < ExtendedThor
368
418
 
369
419
  log :info, "Releasing all packages from testing"
370
420
  repo.list_packages("testing").each do |pkg|
421
+ v = repo.get_subpackage_versions(pkg.name)["testing"].values
371
422
  begin
372
- repo.push pkg.name, nil, "stable", (options["force"] == true)
423
+ repo.push pkg.name, v.max, "stable", (options["force"] == true)
373
424
  rescue Dr::AlreadyExists
374
425
  ;
375
426
  end
@@ -407,8 +458,14 @@ class RepoCLI < ExtendedThor
407
458
  end
408
459
  end
409
460
 
410
- begin
411
- RepoCLI.start ARGV
412
- rescue StandardError => e
461
+ #begin
462
+ Dr::check_dependencies [
463
+ "git", "reprepro", "gzip", "debuild", "debootstrap", "qemu-*-static",
464
+ "chroot", "curl", "gpg", "tar", "dpkg", "dpkg-deb", "dpkg-sig", "rm",
465
+ "sudo"
466
+ ]
467
+
468
+ RepoCLI.start ARGV
469
+ #rescue StandardError => e
413
470
  Dr::Logger.log :err, e.to_s
414
- end
471
+ #end
data/lib/dr.rb CHANGED
@@ -3,7 +3,19 @@
3
3
 
4
4
  require "dr/version"
5
5
  require "dr/repo"
6
+ require "dr/logger"
6
7
 
7
8
  module Dr
8
- # Your code goes here...
9
+ def self.check_dependencies(deps=[])
10
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path_dir|
11
+ deps.delete_if do |dep_name|
12
+ Dir[File.join(path_dir, dep_name)].length > 0
13
+ end
14
+ end
15
+
16
+ if deps.length > 0
17
+ Logger.log :warn, "Missing some dependencies:"
18
+ deps.each { |dep| Logger.log :warn, " #{dep.fg "red"}" }
19
+ end
20
+ end
9
21
  end
data/lib/dr/buildroot.rb CHANGED
@@ -5,47 +5,12 @@ require "tco"
5
5
 
6
6
  require "dr/logger"
7
7
  require "dr/shellcmd"
8
+ require "dr/config"
8
9
 
9
10
  module Dr
10
11
  class BuildRoot
11
12
  include Logger
12
13
 
13
- @@os_bases = {
14
- "Kano OS" => {
15
- :arches => ["armhf", "armel"],
16
- :repos => {
17
- :raspbian => {
18
- :url => "http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/",
19
- :key => "http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian.public.key",
20
- :src => true,
21
- :codename => "wheezy",
22
- :components => "main contrib non-free rpi"
23
- },
24
-
25
- :raspi_foundation => {
26
- :url => "http://archive.raspberrypi.org/debian/",
27
- :key => "http://archive.raspberrypi.org/debian/raspberrypi.gpg.key",
28
- :src => false,
29
- :codename => "wheezy",
30
- :components => "main"
31
- },
32
-
33
- :kano => {
34
- :url => "http://dev.kano.me/archive/",
35
- :key => "http://dev.kano.me/archive/repo.gpg.key",
36
- :src => false,
37
- :codename => "devel",
38
- :components => "main"
39
- }
40
- },
41
- :base => :raspbian,
42
- :packages => []
43
- }
44
- }
45
- def self.os_bases
46
- @@os_bases
47
- end
48
-
49
14
  def initialize(base, arch, br_cache)
50
15
  @location = "#{br_cache}/#{base.strip.downcase.gsub(" ", "_")}-#{arch}.tar.gz"
51
16
  @base = base
@@ -82,17 +47,17 @@ module Dr
82
47
 
83
48
  private
84
49
  def setup(base, arch)
85
- unless @@os_bases.include? base
86
- raise "OS base #{base.fg "blue"} isn't supported by dr."
50
+ unless Dr.config.distros.include? base
51
+ raise "Sorry, OS base #{base.fg "blue"} isn't supported by dr."
87
52
  end
88
53
 
89
- unless @@os_bases[base][:arches].include? arch
54
+ unless Dr.config.distros[base][:arches].include? arch
90
55
  raise "Arch #{arch.fg "blue"} not supported by this base."
91
56
  end
92
57
 
93
- repos = @@os_bases[base][:repos]
94
- base_repo = @@os_bases[base][:base].to_sym
95
- additional_pkgs = @@os_bases[base][:packages].join ","
58
+ repos = Dr.config.distros[base][:repos]
59
+ base_repo = Dr.config.distros[base][:base_repo].to_sym
60
+ additional_pkgs = Dr.config.distros[base][:packages].join ","
96
61
 
97
62
  Dir.mktmpdir do |tmp|
98
63
  broot = "#{tmp}/broot"
data/lib/dr/config.rb CHANGED
@@ -3,10 +3,14 @@
3
3
 
4
4
  require "yaml"
5
5
 
6
+ require "dr/distros"
7
+
6
8
  module Dr
7
9
  class Config
8
10
  attr_reader :default_repo, :repositories
9
11
 
12
+ include Distros
13
+
10
14
  def initialize(locations)
11
15
  @default_repo = nil
12
16
  @repositories = {}
@@ -42,6 +46,18 @@ module Dr
42
46
  raise "Default repo #{@default_repo} doesn't exist"
43
47
  end
44
48
  end
49
+
50
+ if conf_file.has_key? "distros"
51
+ conf_file["distros"].each do |name, distro|
52
+ distro_sym_keys = distro.inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
53
+ add_distro(name, distro_sym_keys)
54
+ end
55
+ end
45
56
  end
46
57
  end
58
+
59
+ @config = Config.new ["/etc/dr.conf", "~/.dr.conf"]
60
+ def self.config
61
+ @config
62
+ end
47
63
  end
data/lib/dr/gitpackage.rb CHANGED
@@ -6,6 +6,7 @@ require "dr/pkgversion"
6
6
  require "dr/shellcmd"
7
7
 
8
8
  require "yaml"
9
+ require "octokit"
9
10
 
10
11
  module Dr
11
12
  class GitPackage < Package
@@ -250,6 +251,55 @@ EOS
250
251
  version
251
252
  end
252
253
 
254
+ def tag_release(tag_name, revision, options={})
255
+ url = get_repo_url
256
+
257
+ log :info, "Tagging #{@name.style "pkg-name"} package for " +
258
+ "#{tag_name.fg "yellow"} release"
259
+
260
+ gh_repo = case url
261
+ when /git\@github.com\:/i then url.split(":")[1].gsub(/\.git$/, "").strip
262
+ when /github.com\//i then url.split("/")[-2..-1].join("/").gsub(/\.git$/, "").strip
263
+ else nil
264
+ end
265
+
266
+ if gh_repo == nil
267
+ git_cmd = "git --git-dir #{@git_dir} tag #{tag}"
268
+ git = ShellCmd.new git_cmd,
269
+ :tag => "git",
270
+ :show_out => false,
271
+ :raise_on_error => false
272
+
273
+ if git.status == 128
274
+ log :warn, "Tag #{tag_name.fg "yellow"} already exists."
275
+ return
276
+ end
277
+
278
+ git_cmd = "git --git-dir #{@git_dir} push origin --tags"
279
+ git = ShellCmd.new git_cmd, :show_out => false
280
+
281
+ return
282
+ end
283
+
284
+ title = options["title"] || "Kano OS #{tag_name}"
285
+ summary = options["summary"] || "https://github.com/KanoComputing/peldins/wiki/Changelog-#{tag_name}"
286
+
287
+ token = ENV["GITHUB_API_TOKEN"]
288
+ client = Octokit::Client.new :access_token => token
289
+
290
+ releases = client.releases gh_repo
291
+ ri = releases.index { |r| r[:tag_name] == tag_name }
292
+
293
+ if ri == nil
294
+ client.create_release gh_repo, tag_name,
295
+ :target_commitish => revision,
296
+ :name => title,
297
+ :body => summary
298
+ else
299
+ log :warn, "The #{tag_name.fg "yellow"} release exists already for #{@name.style "pkg-name"}."
300
+ end
301
+ end
302
+
253
303
  private
254
304
  def update_from_origin(branch)
255
305
  log :info, "Pulling changes from origin"
@@ -269,6 +319,12 @@ EOS
269
319
  [original_rev, current_rev]
270
320
  end
271
321
 
322
+ def get_repo_url
323
+ git_cmd = "git --git-dir #{@git_dir} config --get remote.origin.url"
324
+ git = ShellCmd.new git_cmd, :tag => "git"
325
+ git.out
326
+ end
327
+
272
328
  def get_version(changelog_file)
273
329
  File.open changelog_file, "r" do |f|
274
330
  f.each_line do |l|
@@ -305,12 +361,6 @@ EOS
305
361
  arches.uniq
306
362
  end
307
363
 
308
- def get_repo_url
309
- git_cmd = "git --git-dir #{@git_dir} --bare remote show origin -n"
310
- git = ShellCmd.new git_cmd, :tag => "git"
311
- git.out.lines.grep(/Fetch URL/)[0].chomp[13..-1]
312
- end
313
-
314
364
  def get_current_branch
315
365
  git_cmd = ShellCmd.new "git --git-dir #{@git_dir} --bare branch", {
316
366
  :tag => "git"
data/lib/dr/repo.rb CHANGED
@@ -26,12 +26,15 @@ module Dr
26
26
  @packages_dir = "#{@location}/packages"
27
27
 
28
28
  meta = "#{@location}/metadata"
29
- @metadata = File.exists?(meta) ? YAML.load_file(meta) : {}
29
+ begin
30
+ @metadata = YAML.load_file(meta)
31
+ rescue
32
+ @metadata = {}
33
+ end
30
34
  end
31
35
 
32
36
  def setup(conf)
33
37
  log :info, "Creating the archive directory"
34
-
35
38
  begin
36
39
  FileUtils.mkdir_p location
37
40
  rescue Exception => e
@@ -75,7 +78,7 @@ module Dr
75
78
  FileUtils.mkdir_p @packages_dir
76
79
  FileUtils.mkdir_p "#{@location}/buildroots"
77
80
 
78
- @metadata = {"base-os" => conf[:base]}
81
+ @metadata = {"distro" => conf[:distro]}
79
82
  File.open("#{@location}/metadata", "w" ) do |out|
80
83
  YAML.dump(@metadata)
81
84
  end
@@ -108,7 +111,7 @@ module Dr
108
111
 
109
112
  def buildroot(arch)
110
113
  cache_dir = "#{@location}/buildroots/"
111
- BuildRoot.new @metadata["base-os"], arch, cache_dir
114
+ BuildRoot.new @metadata["distro"], arch, cache_dir
112
115
  end
113
116
 
114
117
  def get_package(name)
data/lib/dr/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
3
3
 
4
4
  module Dr
5
- VERSION = "0.1.14"
5
+ VERSION = "0.2.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radek Pazdera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor