source: branches/gsoc09-logging/base/src/upgrade_sources_conf_default.tcl @ 140300

Last change on this file since 140300 was 59527, checked in by blb@…, 11 years ago

Merge from trunk (may be a few missed bits to be picked up later)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1#!/usr/bin/env tclsh
2#
3# $Id: upgrade_sources_conf_default.tcl 59527 2009-10-16 05:29:39Z blb@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
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               if {![catch {set svnChannel [open "|svn info ${filepath}" r]} err]} {
46                  set svnURL {}
47                  while {[gets $svnChannel svnLine] >= 0} {
48                     regexp {^URL: (.*)} $svnLine -> svnURL
49                  }
50                  if {[catch {close $svnChannel} err]} {
51                     if {![string match "*This client is too old to work with working copy*" $err]} {
52                        return -code error $err
53                     } else {
54                        puts $err
55                        puts "WARNING: Unable to check svn URL for '$filepath' as it has been checked out with a newer Subversion client; please manually verify $sourcesConf!"
56                     }
57                  }
58                  if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} {
59                     set addDefault true
60                  }
61               } else {
62                  return -code error $err
63               }
64            }
65         }
66         if {$addDefault} {
67            lappend flags default
68            set line "$url \[[join $flags ,]\]"
69            set defaultSeen true
70            set defaultWritten true
71         }
72      }
73   }
74   puts $tempfileChannel $line
75}
76close $tempfileChannel
77close $sourcesConfChannel
78
79if {$defaultWritten} {
80   set attributes [file attributes ${sourcesConf}]
81   if {[catch {file rename ${sourcesConf} "${sourcesConf}.mpsaved"}]} {
82      file rename -force ${sourcesConf} "${sourcesConf}.mpsaved_[clock seconds]"
83   }
84   file rename ${tempfile} ${sourcesConf}
85   eval file attributes ${sourcesConf} $attributes
86} else {
87   file delete ${tempfile}
88   if {!$defaultSeen} {
89      puts "[string repeat - 72]
90Warning, your source config file at:
91
92   $sourcesConf
93
94needs to have a \[default\] tag added to the primary MacPorts repository,
95however the proper entry could not be determined.  Please add the tag
96manually by either appending \[default\] to the end of the correct line,
97or if there are already tags, adding it to the list, e.g.
98\[nosync,default\].
99[string repeat - 72]"
100   }
101}
102
103exit 0
104
Note: See TracBrowser for help on using the repository browser.