source: branches/gsoc13-tests/src/upgrade_sources_conf_default.tcl

Last change on this file was 79442, checked in by jmr@…, 9 years ago

keep going in upgrade_sources_conf_default.tcl even if svn appears to fail (#27799)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1#!/usr/bin/env tclsh
2#
3# $Id: upgrade_sources_conf_default.tcl 79442 2011-06-13 13:55:44Z jmr@macports.org $
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
25if {[file executable /usr/bin/mktemp]} {
26    set mktemp /usr/bin/mktemp
27} elseif {[file executable /bin/mktemp]} {
28    set mktemp /bin/mktemp
29} else {
30    set mktemp mktemp
31}
32
33set mktempChannel [open "|$mktemp -t macports_sources_upgrade.XXXXXXXXXX" r]
34set tempfile [read -nonewline $mktempChannel]
35close $mktempChannel
36
37set tempfileChannel [open $tempfile w]
38set defaultSeen false
39set defaultWritten false
40
41while {[gets $sourcesConfChannel line] >= 0} {
42   set addDefault false
43   if {!$defaultSeen && ![regexp {^\s*#|^$} $line]} {
44      if {[regexp {^([\w-]+://\S+)(?:\s+\[(\w+(?:,\w+)*)\])?$} $line -> url flags]} {
45         set flags [split $flags ,]
46         if {[lsearch $flags default] >= 0} {
47            set defaultSeen true
48         } elseif {[regexp {rsync://rsync\.(macports|darwinports)\.org/(release|dpupdate)/d?ports} $url]} {
49            set addDefault true
50         } elseif {[regexp {file://(/.+)} $url -> filepath]} {
51            if {[file exists [file join ${filepath} .svn]]} {
52               if {![info exists svnCmd]} {
53                  set svnCmd ""
54                  foreach path [concat [list ${prefix}/bin] [split $env(PATH) :]] {
55                     if {[file executable ${path}/svn]} {
56                        set svnCmd ${path}/svn
57                        break
58                     }
59                  }
60               }
61               if {$svnCmd == ""} {
62                  puts "WARNING: Unable to check svn URL for '$filepath' because no svn command could be found; please manually verify $sourcesConf!"
63                  continue
64               }
65               if {![catch {set svnChannel [open "|$svnCmd info ${filepath}" r]} err]} {
66                  set svnURL {}
67                  while {[gets $svnChannel svnLine] >= 0} {
68                     regexp {^URL: (.*)} $svnLine -> svnURL
69                  }
70                  if {[catch {close $svnChannel} err]} {
71                     puts $err
72                     puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
73                  }
74                  if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} {
75                     set addDefault true
76                  }
77               } else {
78                  puts $err
79                  puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
80               }
81            }
82         }
83         if {$addDefault} {
84            lappend flags default
85            set line "$url \[[join $flags ,]\]"
86            set defaultSeen true
87            set defaultWritten true
88         }
89      }
90   }
91   puts $tempfileChannel $line
92}
93close $tempfileChannel
94close $sourcesConfChannel
95
96if {$defaultWritten} {
97   set attributes [file attributes ${sourcesConf}]
98   if {[catch {file rename ${sourcesConf} "${sourcesConf}.mpsaved"}]} {
99      file rename -force ${sourcesConf} "${sourcesConf}.mpsaved_[clock seconds]"
100   }
101   file rename ${tempfile} ${sourcesConf}
102   eval file attributes ${sourcesConf} $attributes
103} else {
104   file delete ${tempfile}
105   if {!$defaultSeen} {
106      puts "[string repeat - 72]
107Warning, your source config file at:
108
109   $sourcesConf
110
111needs to have a \[default\] tag added to the primary MacPorts repository,
112however the proper entry could not be determined.  Please add the tag
113manually by either appending \[default\] to the end of the correct line,
114or if there are already tags, adding it to the list, e.g.
115\[nosync,default\].
116[string repeat - 72]"
117   }
118}
119
120exit 0
121
Note: See TracBrowser for help on using the repository browser.