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