/[qa]/trunk/pts/www/bin/update_watch.py
ViewVC logotype

Contents of /trunk/pts/www/bin/update_watch.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1154 - (show annotations) (download) (as text)
Sun Nov 20 14:55:09 2005 UTC (7 years, 6 months ago) by jeroen
File MIME type: text/x-python
File size: 6056 byte(s)
- Fix encoding to utf8: non-ascii without encoding not allowed by Sarge's
  python
- Use default python (instead of 2.2) everywhere in the web part of the PTS
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3 import os, re, cPickle
4
5 from config import dir, odir
6 from shutil import copyfile
7
8 debug = 0
9
10 # Read watch file for upstream updates [FG]
11 watch = {}
12 if os.path.exists(dir + "/watch.txt"):
13 f = open(dir + "/watch.txt")
14 while 1:
15 line = f.readline()
16 if not line: break #eof
17 line = line.strip()
18 try:
19 (package, version) = line.split(' ',2)
20 watch[package] = {'version': version, 'new': 0, 'warning': "", 'url': ""}
21 except ValueError:
22 pass
23 f.close()
24
25 f = open(odir + "/sources_done", "r")
26 sources = cPickle.load(f)
27 for key in sources.keys():
28 (package, version, dist) = key.split('_')
29 if dist != "unstable" and dist != "experimental": continue
30 if not watch.has_key(package): continue
31 # print "doing " + package + " " + version
32 g = os.popen("/usr/bin/dpkg --compare-versions %s gt %s" % (version, watch[package]['version']))
33 if g.close() == None:
34 watch[package]['version'] = version
35 f.close()
36
37 # now try to run uscan in a tmp dir with a bogus changelog
38 sorted = watch.keys()
39 sorted.sort()
40 for pkg in sorted:
41 has_warning = 0
42
43 tmpdir = os.tempnam('/tmp', 'PTS_') #ok, insecure blahblah
44 tmpdir = tmpdir + '/'
45
46 os.mkdir(tmpdir)
47 os.mkdir(tmpdir + 'debian') #our faked debian/ dir
48
49 hash = pkg[0]
50 if pkg[0:3] == "lib":
51 hash = pkg[0:4]
52 if debug: print "%s/%s/%s/watch" % (odir, hash, pkg)
53 copyfile("%s/%s/%s/watch" % (odir, hash, pkg), tmpdir + 'debian/watch')
54
55
56
57 fch = open(tmpdir + 'debian/changelog', 'w+')
58 fch.write(
59 """%s (%s) unstable; urgency=low
60
61 * this is a fake entry
62
63 -- PTS watch update <pts@qa.debian.org> Sat, 11 Jan 2003 17:56:41 +0100
64 """ % (pkg, watch[pkg]['version']) )
65 fch.close()
66
67 curdir = os.getcwd()
68 os.chdir(tmpdir)
69
70 uscan = os.popen("/usr/bin/uscan --no-download 2>&1")
71 for line in uscan.readlines():
72 if debug: print line
73 r = re.search("Warning: (.*)", line)
74 if r:
75 has_warning = 1
76 watch[pkg]['warning'] = watch[pkg]['warning'] + r.group(1)
77
78 if has_warning and line.startswith(" "): # warning lines seem to be 2space-indented
79 watch[pkg]['warning'] = watch[pkg]['warning'] + line
80
81 m = re.search("Newer version \((\S+)\) available", line)
82 if m and not has_warning:
83 if m.group(1) > 0: watch[pkg]['new'] = m.group(1)
84 uscan.close()
85
86 if watch[pkg]['new'] > 0:
87 # extract url from debian/watch file
88 url = ''
89 # TODO: handle continued lines
90 for line in file(tmpdir + 'debian/watch', 'r').readlines():
91
92 if line.startswith('#'): continue
93 if line.startswith('http:') or line.startswith('ftp') or line.count('.') >= 1:
94 if debug: print "ORIGINAL LINE: " + line
95 line = line.strip()
96 fields = re.split('\s+', line)
97
98 if os.path.basename(fields[0]).count('.') == 1: # this is a page like download.html
99 url = os.path.dirname(fields[0]) + '/'
100 else: url = fields[0]
101
102 for field in fields[1:]:
103 if field.count('/') >= 1:
104 if not field.endswith('/'): field = field + '/'
105 if not field.startswith('/'): field = '/' + field
106 url = url + field
107 elif field.count('(') == 1:
108 url = url + field
109
110 # experimental code, maybe better
111 # if line.startswith('#') or line.startswith('version'): continue
112 #
113 # fields = re.split('\s+', line)
114 # for i in range(len(fields)):
115 # if fields[i].startswith('opts='): continue
116 # print "SCANSIONO: " + fields[i]
117 #
118 # if i == 0: # initial URL
119 # url = url + fields[i]
120 # if os.path.basename(url).count('.') == 1: break # this is a page like download.html
121 # elif fields[i].count('(') or fields[i].count(')'):
122 # if url.endswith('/'): url = url + fields[i]
123 # else: url = url + '/' + fields[i]
124 # elif os.path.basename(fields[i]).count('.') == 1: # this is a page like download.html
125 # url = url + fields[i]
126 # break
127 # elif fields[i].count('/') >= 1:
128 # if not fields[i].endswith('/'): fields[i] = fields[i]+ '/'
129 # if not fields[i].startswith('/'): fields[i] = '/' + fields[i]
130 # url = url + fields[i]
131
132 url = url.replace('\\', '')
133 url = url.replace('.*', '')
134 url = url.replace('///', '/')
135
136 if url.startswith('ftp.'): url = 'ftp://' + url
137 elif not url.startswith('http://') and not url.startswith('ftp://'): url = 'http://' + url
138
139 watch[pkg]['url'] = re.sub('\(.*\)', watch[pkg]['new'], url)
140 if debug: print "UPSTREAM PAGE: " + watch[pkg]['url']
141
142 if has_warning:
143 print "WARNING: " + watch[pkg]['warning'].replace('\n', ' ')
144 else:
145 print "new version %s for package %s" % (watch[pkg]['new'], pkg)
146
147 os.chdir(curdir)
148 os.remove(tmpdir + 'debian/watch')
149 os.remove(tmpdir + 'debian/changelog')
150 os.removedirs(tmpdir + 'debian')
151
152 f = open(odir + "/watch_done", "w")
153 cPickle.dump(watch, f, 0)
154 f.close()

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5