source: branches/gsoc09-logging/base/src/port1.0/portdistcheck.tcl @ 52218

Last change on this file since 52218 was 52218, checked in by enl@…, 11 years ago

Merge from trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1# et:ts=4
2# portdistcheck.tcl
3#
4# $Id: portdistcheck.tcl 52218 2009-06-12 08:57:53Z enl@macports.org $
5#
6# Copyright (c) 2005-2006 Paul Guyot <pguyot@kallisys.net>,
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are
11# met:
12#
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Computer, Inc. nor the names of its
19#    contributors may be used to endorse or promote products derived from
20#    this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34
35package provide portdistcheck 1.0
36package require portutil 1.0
37package require portfetch 1.0
38
39set org.macports.distcheck [target_new org.macports.distcheck portdistcheck::distcheck_main]
40target_runtype ${org.macports.distcheck} always
41target_state ${org.macports.distcheck} no
42target_provides ${org.macports.distcheck} distcheck
43target_requires ${org.macports.distcheck} main
44
45namespace eval portdistcheck {
46}
47
48# define options
49options distcheck.check
50
51# defaults
52default distcheck.check moddate
53
54proc portdistcheck::distcheck_main {args} {
55    global distcheck.check
56    global fetch.type
57    global name portpath
58
59    set port_moddate [file mtime ${portpath}/Portfile]
60
61    ui_debug "Portfile modification date is [clock format $port_moddate]"
62
63    # Check the distfiles if it's a regular fetch phase.
64    if {"${distcheck.check}" != "none"
65        && "${fetch.type}" == "standard"} {
66        # portfetch 1.0::checkfiles sets fetch_urls list.
67        global fetch_urls
68        checkfiles
69        set totalsize 0
70
71        # Check all the files.
72        foreach {url_var distfile} $fetch_urls {
73            global portfetch::$url_var
74            if {![info exists $url_var]} {
75                ui_error [format [msgcat::mc "No defined site for tag: %s, using master_sites"] $url_var]
76                set url_var master_sites
77                global portfetch::$url_var
78            }
79            if {${distcheck.check} == "moddate"} {
80                set count 0
81                foreach site [set $url_var] {
82                    ui_debug [format [msgcat::mc "Checking %s from %s"] $distfile $site]
83                    set file_url [portfetch::assemble_url $site $distfile]
84                    if {[catch {set urlnewer [curl isnewer $file_url $port_moddate]} error]} {
85                        ui_warn "couldn't fetch $file_url for $name ($error)"
86                    } else {
87                        if {$urlnewer} {
88                            ui_warn "port $name: $file_url is newer than portfile"
89                        }
90                        incr count
91                    }
92                }
93                if {$count == 0} {
94                    ui_error "no mirror had $distfile for $name"
95                }
96            } elseif {${distcheck.check} == "filesize"} {
97                set count 0
98                foreach site [set $url_var] {
99                    ui_debug [format [msgcat::mc "Checking %s from %s"] $distfile $site]
100                    set file_url [portfetch::assemble_url $site $distfile]
101                    if {[catch {set urlsize [curl getsize $file_url]} error]} {
102                        ui_warn "couldn't fetch $file_url for $name ($error)"
103                    } else {
104                        incr count
105                        if {$urlsize > 0} {
106                            ui_info "port $name: $distfile $urlsize bytes"
107                            incr totalsize $urlsize
108                            break
109                        }
110                    }
111                }
112                if {$count == 0} {
113                    ui_error "no mirror had $distfile for $name"
114                }
115            } else {
116                ui_error "unknown distcheck.check ${distcheck.check}"
117                break
118            }
119        }
120
121        if {${distcheck.check} == "filesize" && $totalsize > 0} {
122            if {$totalsize < 1024} {
123                set size $totalsize
124                set humansize "${size}"
125            } elseif {$totalsize < 1024*1024} {
126                set size [expr $totalsize / 1024.0]
127                set humansize [format "%.1fK" $size]
128            } elseif {$totalsize < 1024*1024*1024} {
129                set size [expr $totalsize / (1024.0*1024.0)]
130                set humansize [format "%.1fM" $size]
131            } else {
132                set size [expr $totalsize / (1024.0*1024.0*1024.0)]
133                set humansize [format "%.1fG" $size]
134            }
135            ui_msg "$name: $humansize"
136        }
137    }
138}
Note: See TracBrowser for help on using the repository browser.