port_upgrade 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  History.txt
2
2
  Manifest.txt
3
- README.txt
3
+ README.rdoc
4
4
  Rakefile
5
5
  lib/port_purge/cli.rb
6
6
  lib/port_upgrade.rb
@@ -16,15 +16,15 @@ A clean way to keep your MacPorts up to date.
16
16
  Updates your MacPorts while also removing old dependent versions of libraries and applications.
17
17
 
18
18
  == SYNOPSIS:
19
- 0) Install a port_upgrade config file into ~/.port_upgrade.conf,
20
- a sample is included with the gem (optional)
21
- 1) Update your ports database from macports.org
22
- sudo port selfupdate (or sync)
23
- 2) Run port_upgrade to generate a shell script
24
- port_upgrade -output upgrade.sh
25
- 3) Run the shell script to update your ports tree
26
- sudo ./upgrade.sh
27
- 4) There is no step 4
19
+
20
+ * Install a port_upgrade config file into ~/.port_upgrade.conf, a sample is included with the gem (optional)
21
+ * Update your ports database from macports.org
22
+ * sudo port selfupdate (or sync)
23
+ * Run port_upgrade to generate a shell script
24
+ * port_upgrade -output upgrade.sh
25
+ * Run the shell script to update your ports tree
26
+ * sudo ./upgrade.sh
27
+ * There is no step 4
28
28
 
29
29
  == REQUIREMENTS:
30
30
 
@@ -2,8 +2,6 @@ require 'optparse'
2
2
  require 'ostruct'
3
3
  require 'yaml'
4
4
 
5
- include Ports
6
-
7
5
  module PortPurge
8
6
  class CLI
9
7
  DOTFILEPATH = File.join(ENV['HOME'],".port_upgrade_ports")
@@ -25,7 +23,7 @@ module PortPurge
25
23
  rescue ArgumentError
26
24
  $stderr.puts("Badly formed .port_upgrade_ports file. Skipping.")
27
25
  end
28
- @pdb = PortsDB.new
26
+ @pdb = Ports::PortsDB.new
29
27
  ports = @pdb.db.query('select port from ports').collect{|p| p[0]}
30
28
  deps = @pdb.db.query('select dep from deps').collect{|p| p[0]}
31
29
  $stderr.puts "Leaves:"
@@ -29,7 +29,7 @@ class String
29
29
  end
30
30
 
31
31
  module Ports
32
- VERSION = '0.1.0'
32
+ VERSION = '0.1.1'
33
33
  RECEIPT_PATH = '/opt/local/var/macports/receipts'
34
34
  MACPORTS_DB='/opt/local/var/macports/sources/rsync.macports.org/release/ports'
35
35
  CONFIG_FILE = 'port_upgrade.conf'
@@ -205,6 +205,7 @@ module Ports
205
205
 
206
206
  class PortsDB
207
207
  def initialize(path=nil,outdated=nil)
208
+ @path=path
208
209
  @db = SQLite3::Database.new(':memory:')#('port_tree.db')
209
210
  @pt = PortTree.new(self,path)
210
211
  @installed = @pt.installed
@@ -425,6 +426,10 @@ module Ports
425
426
  get_port_action(portname,:final_install)
426
427
  end
427
428
 
429
+ def [](portname)
430
+ Port.new(portname,@path)
431
+ end
432
+
428
433
  private
429
434
 
430
435
  def get_port_action(portname,type)
@@ -70,7 +70,8 @@ module PortUpgrade
70
70
  pdb = Ports::PortsDB.new(options.receipts)
71
71
  pdb.set_outdated(options.outdated) if options.outdated
72
72
  end
73
- $stderr.puts("Outdated(#{pdb.outdated.size}): #{pdb.outdated.join(' ')}")
73
+ $stderr.puts("Outdated(#{pdb.outdated.size}):")
74
+ $stderr.puts "#{pdb.outdated.uniq.collect {|portname| p=pdb[portname] ;"#{portname}(#{p.versions.join(", ")}) < #{p.portfile.version}"}.join("\n")}"
74
75
  to_remove = pdb.to_remove
75
76
  $stderr.puts "#{to_remove.size} ports to remove: #{to_remove.join(',')}"
76
77
  pdb.upgrade(options.output)
@@ -2,8 +2,9 @@ module Ports
2
2
  class Port
3
3
  attr_reader :name,:versions,:portfile_path
4
4
 
5
- def initialize(portname)
6
- tmpp = File.join(RECEIPT_PATH,portname)
5
+ def initialize(portname,receipt_path=nil)
6
+ receipt_path ||= RECEIPT_PATH
7
+ tmpp = File.join(receipt_path,portname)
7
8
  @name = portname
8
9
  @versions = []
9
10
  if File.exist?(tmpp) and File.readable?(tmpp)
@@ -1,9 +1,9 @@
1
1
  module Ports
2
2
  class Version
3
3
  include Comparable
4
- attr_reader :parts
4
+ attr_reader :parts,:portrev
5
5
  def initialize(s)
6
- @parts = breakup_version(s)
6
+ @parts,@portrev = breakup_version(s)
7
7
  end
8
8
 
9
9
  def <=>(other)
@@ -13,62 +13,25 @@ module Ports
13
13
  cmp = 0
14
14
  numparts = @parts.size>other.parts.size ? @parts.size : other.parts.size
15
15
  0.upto(numparts-1) do |i|
16
- p = i>=@parts.size ? ["-1"] : @parts[i]
17
- q = i>=other.parts.size ? ["-1"] : other.parts[i]
18
- numsubparts = p.size>q.size ? p.size : q.size
19
- 0.upto(numsubparts-1) do |j|
20
- r = j>=p.size ? "-1" : p[j]
21
- s = j>=q.size ? "-1" : q[j]
22
-
23
- $stderr.puts("p of #{j}: #{r}") if $DEBUG
24
- $stderr.puts("q of #{j}: #{s}") if $DEBUG
25
- a = r =~ /^-?[0-9]+$/ ? r.to_i : r
26
- b = s =~ /^-?[0-9]+$/ ? s.to_i : s
27
- $stderr.puts "#{a.inspect} <=> #{b.inspect}" if $DEBUG
28
- if a.instance_of?(b.class)
29
- cmp = a <=> b
30
- else
31
- $stderr.puts "Can't compare different classes #{a.class.to_s} <=> #{b.class.to_s}" if $DEBUG
32
- cmp = 0
33
- end
34
- return cmp if cmp != 0
16
+ p = i>=@parts.size ? "-1" : @parts[i]
17
+ q = i>=other.parts.size ? "-1" : other.parts[i]
18
+ #numsubparts = p.size>q.size ? p.size : q.size
19
+ a = p =~ /^-?[0-9]+$/ ? p.to_i : p
20
+ b = q =~ /^-?[0-9]+$/ ? q.to_i : q
21
+ $stderr.puts "#{a.inspect} <=> #{b.inspect}" if $DEBUG
22
+ if a.instance_of?(b.class)
23
+ cmp = a <=> b
24
+ else
25
+ $stderr.puts "Can't compare different classes #{a.class.to_s} <=> #{b.class.to_s}" if $DEBUG
26
+ cmp = 0
35
27
  end
36
28
  return cmp if cmp != 0
37
29
  end
30
+ cmp = @portrev <=> other.portrev
38
31
  cmp
39
32
  end
40
33
 
41
34
  private
42
- def get_state(c)
43
- case c
44
- when /[0-9]/
45
- state = 'd'
46
- else
47
- state = 'o'
48
- end
49
- end
50
-
51
- def subparts(s)
52
- state = get_state(s[0,1])
53
- #puts "State: #{state}"
54
- parts = []
55
- part = ""
56
- s.each_byte do |c|
57
- newstate = get_state(c)
58
- case newstate
59
- when state
60
- part << c
61
- else
62
- parts << part #[part,state]
63
- part = ""
64
- part << c
65
- state = newstate
66
- end
67
- end
68
- parts << part #[part,state]
69
- parts
70
- end
71
-
72
35
  def breakup_version(v)
73
36
  return nil if v.nil?
74
37
  raise "Bad input to version; not String" unless v.is_a?(String)
@@ -76,12 +39,16 @@ module Ports
76
39
  $stderr.puts "code version: #{v}"
77
40
  result = ["0"]
78
41
  else
79
- result = []
80
- v.split(/[-_.]/).each do |part|
81
- result << subparts(part)
42
+ md = v.match(/(.*)_(\d+)$/)
43
+ if md.nil?
44
+ portrev = 0
45
+ else
46
+ v = md[1]
47
+ portrev = md[2]
82
48
  end
49
+ result = v.scan(/[0-9]+|[a-zA-Z]+/)
83
50
  end
84
- result
51
+ return result,portrev
85
52
  end
86
53
  end
87
54
  end
@@ -1,4 +1,4 @@
1
- #require File.join(File.dirname(__FILE__), "test_helper.rb")
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
2
  require 'test/unit'
3
3
  require 'stringio'
4
4
  require 'port_purge/cli'
@@ -75,6 +75,12 @@ class TestVersion < Test::Unit::TestCase
75
75
  end
76
76
  end
77
77
 
78
+ def test_6
79
+ v1 = Version.new("1.8.7-p72_3")
80
+ v2 = Version.new("1.8.7-p160_1")
81
+ assert_equal(v1 <=> v2, -1)
82
+ end
83
+
78
84
  def test_other_class
79
85
  assert_raise RuntimeError do
80
86
  v = Version.new(["2"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: port_upgrade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Doan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-12 00:00:00 -07:00
12
+ date: 2009-04-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.2.3
43
+ version: 1.3.0
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: hoe
@@ -63,11 +63,11 @@ extensions: []
63
63
  extra_rdoc_files:
64
64
  - History.txt
65
65
  - Manifest.txt
66
- - README.txt
66
+ - README.rdoc
67
67
  files:
68
68
  - History.txt
69
69
  - Manifest.txt
70
- - README.txt
70
+ - README.rdoc
71
71
  - Rakefile
72
72
  - lib/port_purge/cli.rb
73
73
  - lib/port_upgrade.rb
@@ -80,10 +80,12 @@ files:
80
80
  - etc/port_upgrade.conf.sample
81
81
  has_rdoc: true
82
82
  homepage: http://portupgrade.rubyforge.org/
83
+ licenses: []
84
+
83
85
  post_install_message:
84
86
  rdoc_options:
85
87
  - --main
86
- - README.txt
88
+ - README.rdoc
87
89
  require_paths:
88
90
  - lib
89
91
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -101,9 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  requirements: []
102
104
 
103
105
  rubyforge_project: portupgrade
104
- rubygems_version: 1.3.1
106
+ rubygems_version: 1.3.2
105
107
  signing_key:
106
- specification_version: 2
108
+ specification_version: 3
107
109
  summary: Cleanly upgrade your MacPorts.
108
110
  test_files:
109
111
  - test/test_helper.rb