Projects
New Ticket     Wiki     Browse Source     Timeline     Roadmap     Bug Reports     Search

root/trunk/base/src/upgrade_sources_conf_default.tcl

Revision 43153, 2.9 KB (checked in by blb@…, 5 weeks ago)

src/upgrade_sources_conf_default.tcl - de-anthropomorphize, as suggested
by Ryan

  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env tclsh
2#
3# $Id$
4#
5# Upgrade sources.conf for a given prefix (passed as the first and only
6# argument).
7#
8# For an rsync: repository, if it is the standard MacPorts one and not
9# already tagged, then make it default, if another wasn't already default.
10# For a file:// respository, if it is an svn checkout from the MacPorts
11# server, then make it default if another hasn't already been tagged.
12#
13
14if {[llength $::argv] == 0} {
15   puts "Usage: ${::argv0} <prefix>"
16   exit 1
17}
18
19set prefix [lindex $::argv 0]
20set sourcesConf ${prefix}/etc/macports/sources.conf
21if {[catch {set sourcesConfChannel [open $sourcesConf r]}]} {
22   exit 0
23}
24
25
26set mktempChannel [open "|/usr/bin/mktemp -t macports_sources_upgrade" r]
27set tempfile [read -nonewline $mktempChannel]
28close $mktempChannel
29
30set tempfileChannel [open $tempfile w]
31set defaultSeen false
32set defaultWritten false
33
34while {[gets $sourcesConfChannel line] >= 0} {
35   set addDefault false
36   if {!$defaultSeen && ![regexp {^\s*#|^$} $line]} {
37      if {[regexp {^([\w-]+://\S+)(?:\s+\[(\w+(?:,\w+)*)\])?$} $line -> url flags]} {
38         set flags [split $flags ,]
39         if {[lsearch $flags default] >= 0} {
40            set defaultSeen true
41         } elseif {[regexp {rsync://rsync\.(macports|darwinports)\.org/(release|dpupdate)/d?ports} $url]} {
42            set addDefault true
43         } elseif {[regexp {file://(/.+)} $url -> filepath]} {
44            if {[file exists [file join ${filepath} .svn]]} {
45               set svnChannel [open "|svn info ${filepath}" r]
46               set svnURL {}
47               while {[gets $svnChannel svnLine] >= 0} {
48                  regexp {^URL: (.*)} $svnLine -> svnURL
49               }
50               close $svnChannel
51               if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} {
52                  set addDefault true
53               }
54            }
55         }
56         if {$addDefault} {
57            lappend flags default
58            set line "$url \[[join $flags ,]\]"
59            set defaultSeen true
60            set defaultWritten true
61         }
62      }
63   }
64   puts $tempfileChannel $line
65}
66close $tempfileChannel
67close $sourcesConfChannel
68
69if {$defaultWritten} {
70   set attributes [file attributes ${sourcesConf}]
71   if {[catch {file rename ${sourcesConf} "${sourcesConf}.mpsaved"}]} {
72      file rename -force ${sourcesConf} "${sourcesConf}.mpsaved_[clock seconds]"
73   }
74   file rename ${tempfile} ${sourcesConf}
75   eval file attributes ${sourcesConf} $attributes
76} else {
77   file delete ${tempfile}
78   if {!$defaultSeen} {
79      puts "[string repeat - 72]
80Warning, your source config file at:
81
82   $sourcesConf
83
84needs to have a \[default\] tag added to the primary MacPorts repository,
85however the proper entry could not be determined.  Please add the tag
86manually by either appending \[default\] to the end of the correct line,
87or if there are already tags, adding it to the list, eg,
88\[nosync,default\].
89[string repeat - 72]"
90   }
91}
92
93exit 0
Note: See TracBrowser for help on using the browser.