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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 658 - (show annotations) (download) (as text)
Tue Oct 28 16:35:37 2003 UTC (9 years, 6 months ago) by hertzog
File MIME type: text/x-python
File size: 5262 byte(s)
- Check against the version in unstable/experimental...
1 #!/usr/bin/python2.2
2 import os, re, cPickle, Queue
3
4 import threading
5 from config import dir, odir
6 from shutil import copyfile
7
8 num_threads = 5
9 debug = 0
10
11 # now try to run uscan in a tmp dir with a bogus changelog
12 class find_update(threading.Thread):
13 def __init__(self):
14 self.has_warning = 0
15 sem.acquire()
16 self.tmpdir = os.tempnam('/tmp', 'PTS_') #ok, insecure blahblah
17 self.tmpdir = self.tmpdir + '/'
18
19 os.mkdir(self.tmpdir)
20 os.mkdir(self.tmpdir + 'debian') #our faked debian/ dir
21
22 self.pkg = q.get()
23 self.hash = self.pkg[0]
24 if self.pkg[0:3] == "lib":
25 self.hash = self.pkg[0:4]
26 threading.Thread.__init__(self)
27
28 def run(self):
29 print "%s/%s/%s/watch" % (odir, self.hash, self.pkg)
30 copyfile("%s/%s/%s/%s/watch" % (curdir, odir, self.hash, self.pkg), self.tmpdir + 'debian/watch')
31 fch = open(self.tmpdir + 'debian/changelog', 'w+')
32
33 fch.write(
34 """%s (%s) unstable; urgency=low
35 * this is a fake entry
36 -- PTS watch update <pts@qa.debian.org> Sat, 11 Jan 2003 17:56:41 +0100
37 """ % (self.pkg, watch[self.pkg]['version']) )
38 fch.close()
39
40 os.chdir(self.tmpdir)
41
42 uscan = os.popen("/usr/bin/uscan --no-download 2>&1")
43 for line in uscan.readlines():
44 if debug: print line
45 r = re.search("Warning: (.*)", line)
46 if r:
47 self.has_warning = 1
48 watch[self.pkg]['warning'] = watch[self.pkg]['warning'] + r.group(1)
49
50 if self.has_warning and line.startswith(" "): # warning line *seems* to be 2space-indented
51 watch[self.pkg]['warning'] = watch[self.pkg]['warning'] + line
52
53 m = re.search("Newer version \((\S+)\) available", line)
54 if m and not self.has_warning:
55 if m.group(1) > 0: watch[self.pkg]['new'] = m.group(1)
56 uscan.close()
57
58 if watch[self.pkg]['new'] > 0:
59 # extract url from debian/watch file
60 url = ''
61 for line in file(self.tmpdir + 'debian/watch', 'r').readlines():
62 if line.startswith('#'): continue
63 if line.startswith('http:') or line.startswith('ftp') or line.count('.') >= 1:
64 if debug: print "ORIGINAL LINE: " + line
65 line = line.strip()
66 fields = re.split('\s+', line)
67
68 if os.path.basename(fields[0]).count('.') == 1: # this is a page like download.html
69 url = os.path.dirname(fields[0]) + '/'
70 else: url = fields[0]
71
72 for field in fields[1:]:
73 if field.count('/') >= 1:
74 if not field.endswith('/'): field = field + '/'
75 if not field.startswith('/'): field = '/' + field
76 url = url + field
77 elif field.count('(') == 1:
78 url = url + field
79
80 url = url.replace('\\', '')
81 url = url.replace('.*', '')
82 url = url.replace('///', '/')
83
84 if url.startswith('ftp.'): url = 'ftp://' + url
85 elif not url.startswith('http://') and not url.startswith('ftp://'): url = 'http://' + url
86
87 watch[self.pkg]['url'] = re.sub('\(.*\)', watch[self.pkg]['new'], url)
88 if debug: print "UPSTREAM PAGE: " + watch[self.pkg]['url']
89
90 if self.has_warning:
91 print "WARNING: " + watch[self.pkg]['warning'].replace('\n', ' ')
92 else:
93 print "new version %s for package %s" % (watch[self.pkg]['new'], self.pkg)
94
95 os.remove(self.tmpdir + 'debian/watch')
96 os.remove(self.tmpdir + 'debian/changelog')
97 os.removedirs(self.tmpdir + 'debian')
98 os.chdir(curdir)
99 sem.release()
100
101
102
103 # Read watch file for upstream updates [FG]
104 watch = {}
105 if os.path.exists(dir + "/watch.txt"):
106 f = open(dir + "/watch.txt")
107 while 1:
108 line = f.readline()
109 if not line: break #eof
110 line = line.strip()
111 try:
112 (package, version) = line.split(' ',2)
113 watch[package] = {'version': version, 'new': 0, 'warning': "", 'url': ""}
114 except ValueError:
115 pass
116 f.close()
117
118 f = open(odir + "/sources_done", "r")
119 sources = cPickle.load(f)
120 for key in sources.keys():
121 (package, version, dist) = key.split('_')
122 if dist != "unstable" and dist != "experimental": continue
123 if not watch.has_key(package): continue
124 # print "doing " + package + " " + version
125 g = os.popen("/usr/bin/dpkg --compare-versions %s gt %s" % (version, watch[package]['version']))
126 if g.close() == None:
127 watch[package]['version'] = version
128 f.close()
129
130 q = Queue.Queue() # we need a thread-safe queue
131 for pkg in watch.keys():
132 q.put(pkg)
133
134 curdir = os.getcwd()
135 sem = threading.Semaphore(num_threads)
136 while not q.empty():
137 thread = find_update()
138 thread.start()
139
140 f = open(odir + "/watch_done", "w")
141 cPickle.dump(watch, f, 0)
142 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