annotate Tools/versioncheck/pyversioncheck.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents c3a096bfbd6b
children 6b18a095c2e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """pyversioncheck - Module to help with checking versions"""
7016
dc85ad1ba0e1 Fix bug detected by AMK: Types should be types.
Guido van Rossum <guido@python.org>
parents: 6935
diff changeset
2 import types
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 import rfc822
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 import urllib
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 import sys
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # Verbose options
30772
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 25219
diff changeset
8 VERBOSE_SILENT=0 # Single-line reports per package
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 25219
diff changeset
9 VERBOSE_NORMAL=1 # Single-line reports per package, more info if outdated
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 25219
diff changeset
10 VERBOSE_EACHFILE=2 # Report on each URL checked
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 25219
diff changeset
11 VERBOSE_CHECKALL=3 # Check each URL for each package
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # Test directory
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 ## urllib bug: _TESTDIR="ftp://ftp.cwi.nl/pub/jack/python/versiontestdir/"
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 _TESTDIR="http://www.cwi.nl/~jack/versiontestdir/"
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 def versioncheck(package, url, version, verbose=0):
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 ok, newversion, fp = checkonly(package, url, version, verbose)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 if verbose > VERBOSE_NORMAL:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
20 return ok
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 if ok < 0:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
22 print '%s: No correctly formatted current version file found'%(package)
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 elif ok == 1:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
24 print '%s: up-to-date (version %s)'%(package, version)
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 else:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
26 print '%s: version %s installed, version %s found:' % \
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
27 (package, version, newversion)
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
28 if verbose > VERBOSE_SILENT:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
29 while 1:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
30 line = fp.readline()
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
31 if not line: break
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
32 sys.stdout.write('\t'+line)
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 return ok
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
34
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 def checkonly(package, url, version, verbose=0):
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 if verbose >= VERBOSE_EACHFILE:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
37 print '%s:'%package
7016
dc85ad1ba0e1 Fix bug detected by AMK: Types should be types.
Guido van Rossum <guido@python.org>
parents: 6935
diff changeset
38 if type(url) == types.StringType:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
39 ok, newversion, fp = _check1version(package, url, version, verbose)
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 else:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
41 for u in url:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
42 ok, newversion, fp = _check1version(package, u, version, verbose)
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
43 if ok >= 0 and verbose < VERBOSE_CHECKALL:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
44 break
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 return ok, newversion, fp
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
46
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 def _check1version(package, url, version, verbose=0):
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 if verbose >= VERBOSE_EACHFILE:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
49 print ' Checking %s'%url
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 try:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
51 fp = urllib.urlopen(url)
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 except IOError, arg:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
53 if verbose >= VERBOSE_EACHFILE:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
54 print ' Cannot open:', arg
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
55 return -1, None, None
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 msg = rfc822.Message(fp, seekable=0)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 newversion = msg.getheader('current-version')
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if not newversion:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
59 if verbose >= VERBOSE_EACHFILE:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
60 print ' No "Current-Version:" header in URL or URL not found'
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
61 return -1, None, None
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 7884
diff changeset
62 version = version.lower().strip()
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 7884
diff changeset
63 newversion = newversion.lower().strip()
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 if version == newversion:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
65 if verbose >= VERBOSE_EACHFILE:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
66 print ' Version identical (%s)'%newversion
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
67 return 1, version, fp
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 else:
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
69 if verbose >= VERBOSE_EACHFILE:
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
70 print ' Versions different (installed: %s, new: %s)'% \
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
71 (version, newversion)
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
72 return 0, newversion, fp
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
73
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
74
6935
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 def _test():
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 print '--- TEST VERBOSE=1'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 print '--- Testing existing and identical version file'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 versioncheck('VersionTestPackage', _TESTDIR+'Version10.txt', '1.0', verbose=1)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 print '--- Testing existing package with new version'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 versioncheck('VersionTestPackage', _TESTDIR+'Version11.txt', '1.0', verbose=1)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 print '--- Testing package with non-existing version file'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 versioncheck('VersionTestPackage', _TESTDIR+'nonexistent.txt', '1.0', verbose=1)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 print '--- Test package with 2 locations, first non-existing second ok'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 versfiles = [_TESTDIR+'nonexistent.txt', _TESTDIR+'Version10.txt']
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 versioncheck('VersionTestPackage', versfiles, '1.0', verbose=1)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 print '--- TEST VERBOSE=2'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 print '--- Testing existing and identical version file'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 versioncheck('VersionTestPackage', _TESTDIR+'Version10.txt', '1.0', verbose=2)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 print '--- Testing existing package with new version'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 versioncheck('VersionTestPackage', _TESTDIR+'Version11.txt', '1.0', verbose=2)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 print '--- Testing package with non-existing version file'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 versioncheck('VersionTestPackage', _TESTDIR+'nonexistent.txt', '1.0', verbose=2)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 print '--- Test package with 2 locations, first non-existing second ok'
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 versfiles = [_TESTDIR+'nonexistent.txt', _TESTDIR+'Version10.txt']
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 versioncheck('VersionTestPackage', versfiles, '1.0', verbose=2)
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
6b6ef909238e Adding Jack Jansen's version checking utility.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 if __name__ == '__main__':
7884
dfc8de8f1ec3 Reindented without tabs and with uniform 4 space indent.
Guido van Rossum <guido@python.org>
parents: 7016
diff changeset
98 _test()