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