port_upgrade 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +18 -0
- data/Manifest.txt +4 -0
- data/README.txt +2 -2
- data/Rakefile +1 -12
- data/bin/port_purge +10 -0
- data/etc/port_upgrade.conf.sample +6 -2
- data/lib/port_purge/cli.rb +73 -0
- data/lib/port_upgrade.rb +39 -23
- data/lib/port_upgrade/cli.rb +56 -34
- data/lib/port_upgrade/port.rb +64 -0
- data/lib/port_upgrade/port_upgrade_sh.erb +52 -0
- data/lib/port_upgrade/version.rb +3 -1
- data/test/test_helper.rb +3 -0
- data/test/test_port.rb +33 -0
- data/test/test_port_purge_cli.rb +16 -0
- data/test/test_port_upgrade_cli.rb +24 -0
- data/test/test_portfile.rb +12 -0
- data/test/test_version.rb +1 -0
- metadata +14 -21
data/History.txt
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
== 0.1.0 2009-03-12
|
2
|
+
* Removed use of optiflag gem. Using built-in optparse instead. The output flag has changed to -o from -ouput.
|
3
|
+
* New script output allowing for individual phases to be run. Default is still to run everything.
|
4
|
+
* Added experiment port_purge tool. USE WITH CAUTION. Does port removes directly so must be run as root.
|
5
|
+
* New Port class added to better encapsulate functionality specfic to a port. Not used yet by main line of code.
|
6
|
+
* More tests, more to come.
|
7
|
+
* Bugs
|
8
|
+
* Removed post install message which had hard coded path (despite best efforts to make it dynamic)
|
9
|
+
* Fixes for sameple config file.
|
10
|
+
* Moved class Port into it's own file.
|
11
|
+
* Catch errors when reading malformed config files.
|
12
|
+
* When prompting about conflicting variants remove dups.
|
13
|
+
* Fixes Ruby 1.8.6 compatibility in <=> routine of Version class.
|
14
|
+
* port_tree.rb uses PortsDB class instead of the SQLite3 database directly
|
15
|
+
* Clear cached to_remove when outdated changes.
|
16
|
+
* Better regex for parsing exceptionally weird version strings in Portfiles.
|
17
|
+
* Return 0 for version strings that contain TCL code, for now.
|
18
|
+
|
1
19
|
== 0.0.5 2009-01-06
|
2
20
|
* Bugs
|
3
21
|
* port install needs -x to actually give useful return codes
|
data/Manifest.txt
CHANGED
@@ -2,8 +2,12 @@ History.txt
|
|
2
2
|
Manifest.txt
|
3
3
|
README.txt
|
4
4
|
Rakefile
|
5
|
+
lib/port_purge/cli.rb
|
5
6
|
lib/port_upgrade.rb
|
6
7
|
lib/port_upgrade/cli.rb
|
8
|
+
lib/port_upgrade/port.rb
|
9
|
+
lib/port_upgrade/port_upgrade_sh.erb
|
7
10
|
lib/port_upgrade/version.rb
|
8
11
|
bin/port_upgrade
|
12
|
+
bin/port_purge
|
9
13
|
etc/port_upgrade.conf.sample
|
data/README.txt
CHANGED
@@ -16,7 +16,8 @@ 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
|
-
|
19
|
+
0) Install a port_upgrade config file into ~/.port_upgrade.conf,
|
20
|
+
a sample is included with the gem (optional)
|
20
21
|
1) Update your ports database from macports.org
|
21
22
|
sudo port selfupdate (or sync)
|
22
23
|
2) Run port_upgrade to generate a shell script
|
@@ -29,7 +30,6 @@ Updates your MacPorts while also removing old dependent versions of libraries an
|
|
29
30
|
|
30
31
|
* ruby-sqlite3 gem
|
31
32
|
* bz2 gem
|
32
|
-
* optiflag gem
|
33
33
|
|
34
34
|
== INSTALL:
|
35
35
|
|
data/Rakefile
CHANGED
@@ -7,21 +7,10 @@ $hoe = Hoe.new('port_upgrade',Ports::VERSION) do |p|
|
|
7
7
|
p.developer('Tony Doan', 'tdoan@tdoan.com')
|
8
8
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
9
|
p.summary = "Cleanly upgrade your MacPorts."
|
10
|
-
p.post_install_message = %Q{
|
11
|
-
|
12
|
-
A sample config file can be found in:
|
13
|
-
#{GEM_DIR}/port_upgrade-#{Ports::VERSION}/etc
|
14
|
-
To install copy it to ~/.port_upgrade.conf
|
15
|
-
|
16
|
-
|
17
|
-
}
|
18
|
-
|
19
10
|
p.rubyforge_name = "portupgrade"
|
20
|
-
p.summary = "Summary"
|
21
11
|
p.extra_deps = [
|
22
12
|
['sqlite3-ruby','>= 1.2.0'],
|
23
|
-
['bz2','>= 0.2']
|
24
|
-
['optiflag','>= 0.6.0'],
|
13
|
+
['bz2','>= 0.2']
|
25
14
|
]
|
26
15
|
p.extra_dev_deps = [
|
27
16
|
['newgem', ">= #{::Newgem::VERSION}"]
|
data/bin/port_purge
ADDED
@@ -5,7 +5,11 @@
|
|
5
5
|
ncursesw:
|
6
6
|
:after_uninstall: rm -rf /opt/local/share/terminfo
|
7
7
|
ImageMagick:
|
8
|
-
:before_uninstall: gem uninstall rmagick
|
8
|
+
:before_uninstall: gem uninstall -I rmagick
|
9
9
|
:after_install: gem install rmagick
|
10
|
+
:force_install: true
|
10
11
|
python25:
|
11
|
-
:
|
12
|
+
:final_install: python_select python25
|
13
|
+
sqlite3:
|
14
|
+
:before_uninstall: gem uninstall -I sqlite3-ruby
|
15
|
+
:after_install: gem install sqlite3-ruby
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
include Ports
|
6
|
+
|
7
|
+
module PortPurge
|
8
|
+
class CLI
|
9
|
+
DOTFILEPATH = File.join(ENV['HOME'],".port_upgrade_ports")
|
10
|
+
def self.execute(stdout, arguments=[])
|
11
|
+
options = OpenStruct.new
|
12
|
+
options.filter = nil
|
13
|
+
opts = OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: port_purge [-f filter]"
|
15
|
+
opts.on("-f", "--filter FILTER","FILTER ports to purge") do |filter|
|
16
|
+
options.filter = filter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
opts.parse!
|
20
|
+
|
21
|
+
@to_remove = []
|
22
|
+
@keep = []
|
23
|
+
begin
|
24
|
+
@keep = YAML::load(File.read(DOTFILEPATH)) if File.readable?(DOTFILEPATH)
|
25
|
+
rescue ArgumentError
|
26
|
+
$stderr.puts("Badly formed .port_upgrade_ports file. Skipping.")
|
27
|
+
end
|
28
|
+
@pdb = PortsDB.new
|
29
|
+
ports = @pdb.db.query('select port from ports').collect{|p| p[0]}
|
30
|
+
deps = @pdb.db.query('select dep from deps').collect{|p| p[0]}
|
31
|
+
$stderr.puts "Leaves:"
|
32
|
+
diff = (ports-deps).sort
|
33
|
+
$stderr.puts "Applying filter /#{options.filter}/" unless options.filter.nil?
|
34
|
+
diff.each do |leaf|
|
35
|
+
next if @keep.include? leaf
|
36
|
+
unless options.filter.nil?
|
37
|
+
next unless Regexp.compile(options.filter).match(leaf)
|
38
|
+
end
|
39
|
+
|
40
|
+
$stderr.print leaf
|
41
|
+
$stderr.print " Remove? (Y/N/S/Q)"
|
42
|
+
reply = $stdin.gets
|
43
|
+
case reply.strip
|
44
|
+
when /^(yes|y)$/i
|
45
|
+
@to_remove << leaf
|
46
|
+
when /^(quit|q)$/i
|
47
|
+
exit -1
|
48
|
+
when /^(skip|s)$/i
|
49
|
+
break
|
50
|
+
$stderr.puts
|
51
|
+
else
|
52
|
+
@keep << leaf
|
53
|
+
end
|
54
|
+
end
|
55
|
+
File.open(DOTFILEPATH,'w') do |f|
|
56
|
+
f.write(@keep.to_yaml)
|
57
|
+
end
|
58
|
+
exit 0 unless @to_remove.size > 0
|
59
|
+
$stderr.print "Really remove #{@to_remove.join(" ")} ? (type yes) "
|
60
|
+
reply = $stdin.gets
|
61
|
+
if reply =~ /^yes$/i
|
62
|
+
@to_remove.each do |leaf|
|
63
|
+
s = "port uninstall #{leaf}"
|
64
|
+
$stderr.puts s
|
65
|
+
system(s)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
$stderr.puts "Exiting"
|
69
|
+
exit -1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/port_upgrade.rb
CHANGED
@@ -11,14 +11,16 @@
|
|
11
11
|
# newer version instead, at your option.
|
12
12
|
# ====================================================================
|
13
13
|
#
|
14
|
-
|
14
|
+
require 'rubygems'
|
15
15
|
$:.unshift(File.dirname(__FILE__)) unless
|
16
16
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
17
|
-
|
17
|
+
require 'port_upgrade/port'
|
18
|
+
require 'port_upgrade/version'
|
18
19
|
require 'yaml'
|
19
20
|
require 'bz2'
|
20
21
|
require 'find'
|
21
22
|
require 'sqlite3'
|
23
|
+
require 'erb'
|
22
24
|
|
23
25
|
class String
|
24
26
|
def dot_clean
|
@@ -27,10 +29,11 @@ class String
|
|
27
29
|
end
|
28
30
|
|
29
31
|
module Ports
|
30
|
-
VERSION = '0.0
|
32
|
+
VERSION = '0.1.0'
|
31
33
|
RECEIPT_PATH = '/opt/local/var/macports/receipts'
|
32
34
|
MACPORTS_DB='/opt/local/var/macports/sources/rsync.macports.org/release/ports'
|
33
35
|
CONFIG_FILE = 'port_upgrade.conf'
|
36
|
+
SH_ERB_PATH = File.join(File.dirname(__FILE__),"port_upgrade","port_upgrade_sh.erb")
|
34
37
|
Struct.new('Edge',:port,:dep,:level)
|
35
38
|
class Struct::Edge
|
36
39
|
def <=>(other)
|
@@ -61,9 +64,6 @@ module Ports
|
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
|
-
class Port
|
65
|
-
end
|
66
|
-
|
67
67
|
class PortTree
|
68
68
|
def initialize(pdb,path=nil)
|
69
69
|
@path=path
|
@@ -121,7 +121,7 @@ module Ports
|
|
121
121
|
end
|
122
122
|
@pdb.db.execute("insert or ignore into remports values(\"#{a}\",\"\")")
|
123
123
|
end
|
124
|
-
|
124
|
+
#@pdb.db.execute('delete from remports where port="gimp-app" and dep="gimp"')
|
125
125
|
#File.open("remtree.dot",'w') do |f|
|
126
126
|
# pt = table_to_tree('remports','remports','port','port','dep')
|
127
127
|
# f.write(pt.to_dot)
|
@@ -208,7 +208,7 @@ module Ports
|
|
208
208
|
@db = SQLite3::Database.new(':memory:')#('port_tree.db')
|
209
209
|
@pt = PortTree.new(self,path)
|
210
210
|
@installed = @pt.installed
|
211
|
-
|
211
|
+
set_outdated(outdated)
|
212
212
|
@to_remove = nil
|
213
213
|
config_file = locate_config_file
|
214
214
|
unless config_file.nil?
|
@@ -217,6 +217,9 @@ module Ports
|
|
217
217
|
@config = {} if @config == false
|
218
218
|
rescue Errno::ENOENT
|
219
219
|
$stderr.puts("No configuration loaded.")
|
220
|
+
rescue ArgumentError
|
221
|
+
$stderr.puts("Badly formed config file.")
|
222
|
+
exit(-1)
|
220
223
|
end
|
221
224
|
else
|
222
225
|
$stderr.puts("No configuration loaded.")
|
@@ -280,7 +283,14 @@ module Ports
|
|
280
283
|
end
|
281
284
|
|
282
285
|
def set_outdated(out)
|
286
|
+
begin
|
287
|
+
out.each{|o| Port.new(o)} unless out.nil?
|
288
|
+
rescue RuntimeError => ex
|
289
|
+
$stderr.puts ex
|
290
|
+
exit(-1)
|
291
|
+
end
|
283
292
|
@outdated = out
|
293
|
+
@to_remove = nil
|
284
294
|
end
|
285
295
|
|
286
296
|
def outdated(reload = false)
|
@@ -315,8 +325,8 @@ module Ports
|
|
315
325
|
if File.exist?(portfile_path)
|
316
326
|
curver = Portfile.new(portfile_path).version
|
317
327
|
#puts "%-32s%s < %s" %[port,version.split('+').first,curver] if Ports::Utilities.cmp_vers(version.split('+').first,curver) < 0
|
318
|
-
$stderr.puts("#{port}: #{version.split('+').first}, #{curver}") if $DEBUG
|
319
328
|
cmp = Ports::Utilities.cmp_vers(version.split('+').first,curver)
|
329
|
+
$stderr.puts("#{port}: #{version.split('+').first} <=> #{curver} #{cmp}") if $DEBUG
|
320
330
|
if cmp.nil?
|
321
331
|
$stderr.puts "Unable to compare versions: #{[port]}"
|
322
332
|
else
|
@@ -334,6 +344,8 @@ module Ports
|
|
334
344
|
|
335
345
|
def upgrade(path='port_upgrade.sh')
|
336
346
|
final = []
|
347
|
+
uninstall_data = []
|
348
|
+
install_data = []
|
337
349
|
@pt.setup_remports(outdated) if @to_remove.nil?
|
338
350
|
remports = []
|
339
351
|
remvariants = Hash.new {|h,k| h[k] = Array.new}
|
@@ -341,7 +353,6 @@ module Ports
|
|
341
353
|
dotsh = File.new(path,'w')
|
342
354
|
dotsh.chmod(0700)
|
343
355
|
$stderr.puts "port_upgrade.sh open for write" if $DEBUG
|
344
|
-
dotsh.puts("#!/bin/sh")
|
345
356
|
while stmt.execute.to_a.first[0].to_i > 0
|
346
357
|
temp = get_leaves
|
347
358
|
break if temp.size == 0
|
@@ -350,12 +361,12 @@ module Ports
|
|
350
361
|
installed = rs.to_a
|
351
362
|
installed.each do |port|
|
352
363
|
bu = get_before_uninstall(port[0])
|
353
|
-
|
354
|
-
|
364
|
+
uninstall_data << bu unless bu.nil?
|
365
|
+
uninstall_data << "port uninstall #{port[0]} @#{port[1]}#{port[2]} || exit -1"
|
355
366
|
au = get_after_uninstall(port[0])
|
356
|
-
|
367
|
+
uninstall_data << au unless au.nil?
|
357
368
|
remports.push(port[0])
|
358
|
-
remvariants[port[0]].push(port[2])
|
369
|
+
remvariants[port[0]].push(port[2]) if remvariants[port[0]] and remvariants[port[0]].index(port[2]).nil?
|
359
370
|
end
|
360
371
|
end
|
361
372
|
end
|
@@ -370,15 +381,17 @@ module Ports
|
|
370
381
|
variantindex = 0
|
371
382
|
end
|
372
383
|
bi = get_before_install(port)
|
373
|
-
|
374
|
-
|
384
|
+
uninstall_data << bi unless bi.nil?
|
385
|
+
install_data << "port #{get_force(port)} -x install #{port} #{remvariants[port][variantindex]} || exit -1"
|
375
386
|
ai = get_after_install(port)
|
376
387
|
fi = get_final_install(port)
|
377
388
|
final << fi unless fi.nil?
|
378
|
-
|
389
|
+
install_data << ai unless ai.nil?
|
379
390
|
end
|
380
391
|
stmt.close
|
381
|
-
final
|
392
|
+
final_actions = final
|
393
|
+
template = ERB.new(File.read(SH_ERB_PATH))
|
394
|
+
dotsh.puts template.result(binding)
|
382
395
|
dotsh.close
|
383
396
|
true
|
384
397
|
end
|
@@ -418,8 +431,8 @@ module Ports
|
|
418
431
|
unless @config.nil?
|
419
432
|
if @config.has_key?(:actions)
|
420
433
|
if @config[:actions].has_key?(portname)
|
421
|
-
if @config[:actions][portname].has_key?(type)
|
422
|
-
@config[:actions][portname][type]
|
434
|
+
if @config[:actions][portname].is_a?(Hash) and @config[:actions][portname].has_key?(type)
|
435
|
+
@config[:actions][portname][type].to_s
|
423
436
|
else
|
424
437
|
nil
|
425
438
|
end
|
@@ -432,7 +445,7 @@ module Ports
|
|
432
445
|
answer=false
|
433
446
|
while(!answer)
|
434
447
|
$stderr.puts "Please choose from list:"
|
435
|
-
variants.each_with_index{|v,i| $stderr.puts "#{i}: #{v=="" ? "(none)" : v}"}
|
448
|
+
variants.sort.each_with_index{|v,i| $stderr.puts "#{i}: #{v=="" ? "(none)" : v}"}
|
436
449
|
$stderr.print "> "
|
437
450
|
reply = $stdin.gets
|
438
451
|
clean = (reply.strip =~ /-?[0-9]+/)
|
@@ -449,6 +462,7 @@ module Ports
|
|
449
462
|
|
450
463
|
class Portfile
|
451
464
|
def initialize(path)
|
465
|
+
raise Errno::ENOENT if (File.file?(path) == false or File.readable?(path) == false)
|
452
466
|
@path = path
|
453
467
|
end
|
454
468
|
|
@@ -467,6 +481,8 @@ module Ports
|
|
467
481
|
when /^set\s+(\S+)\s+(\S+)/
|
468
482
|
vars[$1] = $2
|
469
483
|
#$stderr.puts "Var: #{$1} Val: #{$2}"
|
484
|
+
when /^version\s+\[(.*)\]/
|
485
|
+
v = nil
|
470
486
|
when /^version\s+([^\s]+)/
|
471
487
|
v = $1
|
472
488
|
while(v =~ /(\$\{([^}]+)\})/) do
|
@@ -481,7 +497,7 @@ module Ports
|
|
481
497
|
when /^revision\s+([^\s]+)/
|
482
498
|
rev = $1
|
483
499
|
#$stderr.puts "revision found #{rev}"
|
484
|
-
when /(\w+\.setup\s+\{[^\}]+\}\s+([^\s]+)|^\w+\.setup\s+[^ ]+ (
|
500
|
+
when /(\w+\.setup\s+\{[^\}]+\}\s+([^\s]+)|^\w+\.setup\s+[^ ]+ (\S+))/
|
485
501
|
v = $2 || $3 if v.nil?
|
486
502
|
break
|
487
503
|
when /(\S+)\s+([^$]+)$/
|
@@ -489,7 +505,7 @@ module Ports
|
|
489
505
|
end
|
490
506
|
end
|
491
507
|
rev = "0" if rev.nil?
|
492
|
-
v = v +"_"+rev
|
508
|
+
v = v +"_"+rev unless v.nil?
|
493
509
|
return v
|
494
510
|
end
|
495
511
|
end
|
data/lib/port_upgrade/cli.rb
CHANGED
@@ -1,40 +1,62 @@
|
|
1
|
-
require '
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
|
-
module PortUpgrade
|
4
|
-
|
5
|
-
flag "output" do
|
6
|
-
description "Where to output the shell script that performs the upgrade."
|
7
|
-
end
|
8
|
-
|
9
|
-
optional_flag "outdated" do
|
10
|
-
description "Specify the list of outdated ports to upgrade."
|
11
|
-
end
|
12
|
-
|
13
|
-
optional_flag "receipts" do
|
14
|
-
end
|
15
|
-
|
16
|
-
optional_switch_flag "portoutdated" do
|
17
|
-
description "Call \"port outdated\" instead of using internal routine for determining out of date ports. Overides outdated flag."
|
18
|
-
end
|
19
|
-
|
20
|
-
optional_switch_flag "checkoutdated" do
|
21
|
-
description "Compare internal outdated routing with \"port outdated \""
|
22
|
-
end
|
23
|
-
|
24
|
-
optional_switch_flag "verbose" do
|
25
|
-
end
|
26
|
-
|
27
|
-
and_process!
|
4
|
+
module PortUpgrade
|
28
5
|
|
29
6
|
class CLI
|
30
7
|
def self.execute(stdout, arguments=[])
|
31
|
-
|
32
|
-
|
8
|
+
options = OpenStruct.new
|
9
|
+
options.output = nil
|
10
|
+
options.receipts = nil
|
11
|
+
options.outdated = nil
|
12
|
+
options.portoutdated = false
|
13
|
+
options.checkoutdated = false
|
14
|
+
options.verbose = false
|
15
|
+
|
16
|
+
opts = OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: port_upgrade.rb -oFILENAME [options]"
|
18
|
+
opts.on("-o", "--output FILE","FILE to output shell commands") do |output|
|
19
|
+
options.output = output
|
20
|
+
end
|
21
|
+
opts.on("--receipts PATH","PATH to receipts files") do |receipts|
|
22
|
+
options.receipts = receipts
|
23
|
+
end
|
24
|
+
opts.on("--outdated OUTDATED","Space seperated list of ports to mark as outdated") do |outdated|
|
25
|
+
options.outdated = outdated.split(" ")
|
26
|
+
end
|
27
|
+
opts.on("--portoutdated",'Use `port outdated`(slow) instead of internal version checking routine(fast)') do |po|
|
28
|
+
options.portoutdated = po
|
29
|
+
$stderr.puts "PORTOUTDATED: #{po}"
|
30
|
+
end
|
31
|
+
opts.on("--checkoutdated",'Check `port outdated` against internal routine for inconsistencies') do |co|
|
32
|
+
options.checkoutdated = co
|
33
|
+
$stderr.puts "CHECKOUTDATED: #{co}"
|
34
|
+
end
|
35
|
+
opts.on_tail("-V", "--version","Show version") do
|
36
|
+
$stderr.puts "port_upgrade #{Ports::VERSION}"
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
40
|
+
puts opts
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
44
|
+
$stderr.puts "VERBOSE: #{v}"
|
45
|
+
options.verbose = v
|
46
|
+
end
|
47
|
+
end
|
48
|
+
opts.parse!(arguments)
|
49
|
+
if !options.output
|
50
|
+
puts opts
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
$verbose = true# if options.verbose
|
54
|
+
if options.portoutdated
|
33
55
|
$stderr.print "Running port outdated..."
|
34
56
|
outdated = `port outdated`.find_all{|l| (l =~ /(The following|No installed ports are outdated)/).nil? }.collect{|l| l.split[0]}
|
35
57
|
$stderr.puts "done"
|
36
|
-
if
|
37
|
-
mypdb = Ports::PortsDB.new(
|
58
|
+
if options.checkoutdated
|
59
|
+
mypdb = Ports::PortsDB.new(options.receipts)
|
38
60
|
myoutdated = mypdb.outdated
|
39
61
|
diff = outdated-myoutdated
|
40
62
|
if diff.size > 0
|
@@ -43,15 +65,15 @@ module PortUpgrade extend OptiFlagSet
|
|
43
65
|
$stderr.puts "No Difference"
|
44
66
|
end
|
45
67
|
end
|
46
|
-
pdb = Ports::PortsDB.new(
|
68
|
+
pdb = Ports::PortsDB.new(options.receipts,outdated)
|
47
69
|
else
|
48
|
-
pdb = Ports::PortsDB.new(
|
49
|
-
pdb.set_outdated(
|
70
|
+
pdb = Ports::PortsDB.new(options.receipts)
|
71
|
+
pdb.set_outdated(options.outdated) if options.outdated
|
50
72
|
end
|
51
73
|
$stderr.puts("Outdated(#{pdb.outdated.size}): #{pdb.outdated.join(' ')}")
|
52
74
|
to_remove = pdb.to_remove
|
53
75
|
$stderr.puts "#{to_remove.size} ports to remove: #{to_remove.join(',')}"
|
54
|
-
pdb.upgrade(
|
76
|
+
pdb.upgrade(options.output)
|
55
77
|
pdb.close
|
56
78
|
end
|
57
79
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Ports
|
2
|
+
class Port
|
3
|
+
attr_reader :name,:versions,:portfile_path
|
4
|
+
|
5
|
+
def initialize(portname)
|
6
|
+
tmpp = File.join(RECEIPT_PATH,portname)
|
7
|
+
@name = portname
|
8
|
+
@versions = []
|
9
|
+
if File.exist?(tmpp) and File.readable?(tmpp)
|
10
|
+
@rp = tmpp
|
11
|
+
Find.find(@rp) do |d|
|
12
|
+
next unless File.directory?(d)
|
13
|
+
next if d == @rp
|
14
|
+
b = File.basename(d)
|
15
|
+
md = /([^+]+)((\+\w+)*)/.match(b)
|
16
|
+
@versions << md[1] unless md.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Dir.entries(MACPORTS_DB).each do |d|
|
21
|
+
if File.directory?(File.join(MACPORTS_DB,d)) && d != '.' && d != '..'
|
22
|
+
testpath = File.join(MACPORTS_DB,d,@name,'Portfile')
|
23
|
+
if File.exist?(testpath)
|
24
|
+
@portfile_path = testpath
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
raise "NoSuchPort: #{@name}" if @portfile_path.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def installed?
|
33
|
+
@rp.nil? ? false : true
|
34
|
+
end
|
35
|
+
|
36
|
+
def receipt_path=(path)
|
37
|
+
@rp = path
|
38
|
+
end
|
39
|
+
|
40
|
+
def receipt_path
|
41
|
+
@rp
|
42
|
+
end
|
43
|
+
|
44
|
+
def portfile
|
45
|
+
return nil if @portfile_path.nil?
|
46
|
+
@portfile ||= Ports::Portfile.new(@portfile_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def name=(n)
|
50
|
+
@name = n
|
51
|
+
end
|
52
|
+
|
53
|
+
def outdated?
|
54
|
+
result = false
|
55
|
+
@versions.each do |v|
|
56
|
+
if Ports::Utilities.cmp_vers(v,portfile.version) < 0
|
57
|
+
result = true
|
58
|
+
break
|
59
|
+
end
|
60
|
+
end
|
61
|
+
result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
<%if uninstall_data.size == 0 and install_data.size == 0 and final_actions.size == 0 %>
|
4
|
+
echo "Nothing to upgrade"
|
5
|
+
<% else %>
|
6
|
+
|
7
|
+
uninstall_ports() {
|
8
|
+
<%= uninstall_data.join("\n") %>
|
9
|
+
}
|
10
|
+
|
11
|
+
install_ports() {
|
12
|
+
<%= install_data.join("\n") %>
|
13
|
+
}
|
14
|
+
|
15
|
+
<% if final_actions.size > 0 %>
|
16
|
+
final_actions()
|
17
|
+
{
|
18
|
+
<%= final_actions.join("\n") %>
|
19
|
+
}
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
case $1 in
|
23
|
+
uninstall)
|
24
|
+
echo "uninstall"
|
25
|
+
uninstall_ports
|
26
|
+
;;
|
27
|
+
install)
|
28
|
+
echo "install"
|
29
|
+
install_ports
|
30
|
+
;;
|
31
|
+
final)
|
32
|
+
<%if final_actions.size > 0 %>
|
33
|
+
echo "final actions"
|
34
|
+
final_actions
|
35
|
+
<% else %>
|
36
|
+
echo "No final actions"
|
37
|
+
<% end %>
|
38
|
+
;;
|
39
|
+
'')
|
40
|
+
echo "full run"
|
41
|
+
uninstall_ports
|
42
|
+
install_ports
|
43
|
+
<%if final_actions.size > 0 %>
|
44
|
+
final_actions
|
45
|
+
<% end %>
|
46
|
+
;;
|
47
|
+
*)
|
48
|
+
echo $1: unknown option >&2
|
49
|
+
exit 1
|
50
|
+
;;
|
51
|
+
esac
|
52
|
+
<% end %>
|
data/lib/port_upgrade/version.rb
CHANGED
@@ -7,6 +7,7 @@ module Ports
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def <=>(other)
|
10
|
+
return 0 if @parts.nil? or other.parts.nil?
|
10
11
|
$stderr.puts("self: #{@parts.inspect}") if $DEBUG
|
11
12
|
$stderr.puts("other: #{other.parts.inspect}") if $DEBUG
|
12
13
|
cmp = 0
|
@@ -52,7 +53,7 @@ module Ports
|
|
52
53
|
#puts "State: #{state}"
|
53
54
|
parts = []
|
54
55
|
part = ""
|
55
|
-
s.
|
56
|
+
s.each_byte do |c|
|
56
57
|
newstate = get_state(c)
|
57
58
|
case newstate
|
58
59
|
when state
|
@@ -69,6 +70,7 @@ module Ports
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def breakup_version(v)
|
73
|
+
return nil if v.nil?
|
72
74
|
raise "Bad input to version; not String" unless v.is_a?(String)
|
73
75
|
if v =~ /\[[^\]]+\]/
|
74
76
|
$stderr.puts "code version: #{v}"
|
data/test/test_helper.rb
ADDED
data/test/test_port.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib','port_upgrade')
|
3
|
+
require 'shoulda'
|
4
|
+
include Ports
|
5
|
+
|
6
|
+
class TestPort < Test::Unit::TestCase
|
7
|
+
context "A Port instance" do
|
8
|
+
setup do
|
9
|
+
@port = Port.new('wget')
|
10
|
+
end
|
11
|
+
|
12
|
+
should "return not nil" do
|
13
|
+
assert_not_nil @port
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be installed" do
|
17
|
+
assert(@port.installed?)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "A NoSuchPort instance" do
|
22
|
+
setup do
|
23
|
+
end
|
24
|
+
|
25
|
+
should "raise NoSuchPort" do
|
26
|
+
assert_raise RuntimeError do
|
27
|
+
@port = Port.new('NOTwget')
|
28
|
+
end
|
29
|
+
assert_nil(@port)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'stringio'
|
4
|
+
require 'port_purge/cli'
|
5
|
+
|
6
|
+
class TestPortPurgeCli < Test::Unit::TestCase
|
7
|
+
#def setup
|
8
|
+
# PortPurge::CLI.execute(@stdout_io = StringIO.new, [])
|
9
|
+
# @stdout_io.rewind
|
10
|
+
# @stdout = @stdout_io.read
|
11
|
+
#end
|
12
|
+
|
13
|
+
def test_not_print_default_output
|
14
|
+
assert_no_match(/To update this executable/, @stdout)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'port_upgrade/cli'
|
4
|
+
require 'stringio'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
class TestPortUpgradeCli < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
#PortUpgrade::CLI.execute(@stdout_io = StringIO.new, [])
|
10
|
+
#@stdout_io.rewind
|
11
|
+
#@stdout = @stdout_io.read
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_not_print_default_output
|
15
|
+
#assert_no_match(/To update this executable/, @stdout)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_output_flag_requires_argument
|
19
|
+
assert_raise OptionParser::MissingArgument do
|
20
|
+
PortUpgrade::CLI.execute(stdout_io = StringIO.new, ["-o"])
|
21
|
+
stdout_io.rewind
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib','port_upgrade') #,'version')
|
3
|
+
|
4
|
+
include Ports
|
5
|
+
|
6
|
+
class TestPortfile < Test::Unit::TestCase
|
7
|
+
def test_portfile_bad_path
|
8
|
+
assert_raise Errno::ENOENT do
|
9
|
+
pf = Ports::Portfile.new('/tmp/not_a_path')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/test/test_version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
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-
|
12
|
+
date: 2009-03-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,16 +32,6 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0.2"
|
34
34
|
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: optiflag
|
37
|
-
type: :runtime
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.6.0
|
44
|
-
version:
|
45
35
|
- !ruby/object:Gem::Dependency
|
46
36
|
name: newgem
|
47
37
|
type: :development
|
@@ -67,6 +57,7 @@ email:
|
|
67
57
|
- tdoan@tdoan.com
|
68
58
|
executables:
|
69
59
|
- port_upgrade
|
60
|
+
- port_purge
|
70
61
|
extensions: []
|
71
62
|
|
72
63
|
extra_rdoc_files:
|
@@ -78,21 +69,18 @@ files:
|
|
78
69
|
- Manifest.txt
|
79
70
|
- README.txt
|
80
71
|
- Rakefile
|
72
|
+
- lib/port_purge/cli.rb
|
81
73
|
- lib/port_upgrade.rb
|
82
74
|
- lib/port_upgrade/cli.rb
|
75
|
+
- lib/port_upgrade/port.rb
|
76
|
+
- lib/port_upgrade/port_upgrade_sh.erb
|
83
77
|
- lib/port_upgrade/version.rb
|
84
78
|
- bin/port_upgrade
|
79
|
+
- bin/port_purge
|
85
80
|
- etc/port_upgrade.conf.sample
|
86
81
|
has_rdoc: true
|
87
82
|
homepage: http://portupgrade.rubyforge.org/
|
88
|
-
post_install_message:
|
89
|
-
|
90
|
-
|
91
|
-
A sample config file can be found in:
|
92
|
-
/opt/local/lib/ruby/gems/1.8/gems/port_upgrade-0.0.5/etc
|
93
|
-
To install copy it to ~/.port_upgrade.conf
|
94
|
-
|
95
|
-
|
83
|
+
post_install_message:
|
96
84
|
rdoc_options:
|
97
85
|
- --main
|
98
86
|
- README.txt
|
@@ -116,6 +104,11 @@ rubyforge_project: portupgrade
|
|
116
104
|
rubygems_version: 1.3.1
|
117
105
|
signing_key:
|
118
106
|
specification_version: 2
|
119
|
-
summary:
|
107
|
+
summary: Cleanly upgrade your MacPorts.
|
120
108
|
test_files:
|
109
|
+
- test/test_helper.rb
|
110
|
+
- test/test_port.rb
|
111
|
+
- test/test_port_purge_cli.rb
|
112
|
+
- test/test_port_upgrade_cli.rb
|
113
|
+
- test/test_portfile.rb
|
121
114
|
- test/test_version.rb
|