source: branches/images-and-archives/base/src/port1.0/portdistcheck.tcl @ 53051

Last change on this file since 53051 was 53051, checked in by blb@…, 8 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 53051 2009-06-28 21:26:50Z blb@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        set fetch_urls {}
68        portfetch::checkfiles fetch_urls
69        set totalsize 0
70
71        # Check all the files.
72        foreach {url_var distfile} $fetch_urls {
73            global portfetch::urlmap
74            if {![info exists urlmap($url_var)]} {
75                ui_error [format [msgcat::mc "No defined site for tag: %s, using master_sites"] $url_var]
76                set urlmap($url_var) $master_sites
77            }
78            if {${distcheck.check} == "moddate"} {
79                set count 0
80                foreach site $urlmap($url_var) {
81                    ui_debug [format [msgcat::mc "Checking %s from %s"] $distfile $site]
82                    set file_url [portfetch::assemble_url $site $distfile]
83                    if {[catch {set urlnewer [curl isnewer $file_url $port_moddate]} error]} {
84                        ui_warn "couldn't fetch $file_url for $name ($error)"
85                    } else {
86                        if {$urlnewer} {
87                            ui_warn "port $name: $file_url is newer than portfile"
88                        }
89                        incr count
90                    }
91                }
92                if {$count == 0} {
93                    ui_error "no mirror had $distfile for $name"
94                }
95            } elseif {${distcheck.check} == "filesize"} {
96                set count 0
97                foreach site $urlmap($url_var) {
98                    ui_debug [format [msgcat::mc "Checking %s from %s"] $distfile $site]
99                    set file_url [portfetch::assemble_url $site $distfile]
100                    if {[catch {set urlsize [curl getsize $file_url]} error]} {
101                        ui_warn "couldn't fetch $file_url for $name ($error)"
102                    } else {
103                        incr count
104                        if {$urlsize > 0} {
105                            ui_info "port $name: $distfile $urlsize bytes"
106                            incr totalsize $urlsize
107                            break
108                        }
109                    }
110                }
111                if {$count == 0} {
112                    ui_error "no mirror had $distfile for $name"
113                }
114            } else {
115                ui_error "unknown distcheck.check ${distcheck.check}"
116                break
117            }
118        }
119
120        if {${distcheck.check} == "filesize" && $totalsize > 0} {
121            if {$totalsize < 1024} {
122                set size $totalsize
123                set humansize "${size}"
124            } elseif {$totalsize < 1024*1024} {
125                set size [expr $totalsize / 1024.0]
126                set humansize [format "%.1fK" $size]
127            } elseif {$totalsize < 1024*1024*1024} {
128                set size [expr $totalsize / (1024.0*1024.0)]
129                set humansize [format "%.1fM" $size]
130            } else {
131                set size [expr $totalsize / (1024.0*1024.0*1024.0)]
132                set humansize [format "%.1fG" $size]
133            }
134            ui_msg "$name: $humansize"
135        }
136    }
137}
Note: See TracBrowser for help on using the repository browser.