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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1431 - (show annotations) (download) (as text)
Fri Oct 6 10:16:30 2006 UTC (6 years, 7 months ago) by hertzog
File MIME type: text/x-python
File size: 4638 byte(s)
Add more known VCS (patch from zack)
1 # -*- coding: utf8 -*-
2 # vim: expandtab
3
4 # Copyright 2002 Raphaƫl Hertzog
5 # Copyright 2006 Jeroen van Wolffelaar
6 # This file is distributed under the terms of the General Public License
7 # version 2 or (at your option) any later version.
8
9 import os, os.path, re, rfc822, time, email
10 from email import Utils, Header
11
12 from config import root
13
14 def save_msg_in_dir(msg, dir):
15 """Add the message in the directory."""
16 if not os.path.isdir(dir):
17 os.makedirs(dir)
18 info = extract_info(msg)
19
20 targetfile = "%s/%s.txt" % (dir, info['timestamp'])
21 if os.path.isfile(targetfile):
22 raise("Aiee, already such message %s" % targetfile)
23 f = open(targetfile, "w")
24 f.write(msg.as_string())
25 f.close()
26 os.chmod(targetfile, 0664)
27
28 re_katie_install = re.compile(r"^\S+ \S+ (\S+)")
29 re_distribution = re.compile(r"^Distribution:\s*(\S+)", re.M)
30 re_urgency = re.compile(r"^Urgency:\s*(\S+)", re.M)
31
32 def extract_info(msg):
33 """Extract pseudo-header informations in a dictionnary"""
34 info = {}
35 if msg.is_multipart():
36 for part in msg.walk():
37 if part.get_type("text/plain") == "text/plain":
38 body = part.get_payload(None, 1)
39 break
40 else:
41 body = msg.get_payload(None, 1)
42 lines = body.split("\n", 3)
43 for i in range(3):
44 res = re.match(r"^(\w+): (\S+)(.*)", lines[i])
45 if res:
46 field = res.group(1).lower()
47 info[field] = res.group(2)
48 if field == "subject":
49 info[field] = info[field] + res.group(3)
50 else:
51 break
52
53 if not info.has_key("subject"):
54 subject = unicode(Header.make_header(Header.decode_header(msg.get("subject"))))
55 if subject.split()[0] in ['Accepted', 'Installed']:
56 # katie install mail
57 version = re_katie_install.search(subject).group(1)
58 distribution = re_distribution.search(body)
59 if distribution:
60 distribution = " in %s" % distribution.group(1)
61 else:
62 distribution = ""
63 urgency = re_urgency.search(body)
64 if urgency:
65 urgency = " (%s)" % urgency.group(1)
66 else:
67 urgency = ""
68 subject = "Accepted %s%s%s" % (version, distribution, urgency)
69 info["subject"] = subject
70 if msg.has_key("X-PTS-Subject"):
71 info["subject"] = msg.get("X-PTS-Subject")
72 if msg.has_key("X-PTS-Url"):
73 info["url"] = msg.get("X-PTS-Url")
74 if msg.has_key("X-PTS-Package"):
75 info["package"] = msg.get("X-PTS-Package")
76 if msg.has_key("date"):
77 date = email.Utils.mktime_tz(email.Utils.parsedate_tz(msg.get("date")))
78 info["timestamp"] = time.strftime("%Y%m%dT%H%M%SZ", time.gmtime(date))
79 info["date"] = time.strftime("%Y-%m-%d", time.gmtime(date))
80 if msg.has_key("From"):
81 frm = msg.get("From")
82 if msg.has_key("X-PTS-From"): frm = msg.get("X-PTS-From")
83 (realname, address) = rfc822.parseaddr(frm)
84 if realname:
85 frm = realname
86 else:
87 frm = address
88 frm = ensure_utf8(frm)
89 try:
90 frm = unicode(Header.make_header(Header.decode_header(frm)))
91 except UnicodeError:
92 pass
93 info["from_name"] = frm
94 return info
95
96 def store_news(pkg, msg):
97 hash = pkg[0]
98 if pkg[:3] == "lib":
99 hash = pkg[:4]
100 basedir = "%s/base/%s/%s" % (root, hash, pkg)
101 save_msg_in_dir(msg, basedir+"/news")
102 # Synchronize the XML document
103 f = os.popen("%s/bin/update_news.py" % root, "w")
104 f.write(pkg+"\n")
105 f.close()
106 # Regenerate the HTML page
107 f = os.popen("%s/bin/generate_html.sh" % root, "w")
108 f.write(pkg+"\n")
109 f.close()
110
111
112 def ensure_utf8(str):
113 try:
114 str.decode("utf8")
115 except UnicodeError:
116 str = str.decode("latin1")
117 return str
118
119 # Version Control Systems table
120 # Fields:
121 # 'tag' is as it would appear in a vcs-XXX field, e.g. 'svn' for Vcs-Svn
122 # tag common name upstream URL
123 vcs_table = {
124 'arch': ('Arch', 'http://www.gnuarch.org/arch/'),
125 'bzr': ('Bazaar', 'http://bazaar-vcs.org/'),
126 'cvs': ('CVS', 'http://www.nongnu.org/cvs/'),
127 'darcs': ('Darcs', 'http://abridgegame.org/darcs/'),
128 'git': ('Git', 'http://git.or.cz/'),
129 'hg': ('Mercurial', 'http://www.selenic.com/mercurial/'),
130 'mtn': ('Monotone', 'http://venge.net/monotone/'),
131 'svn': ('Subversion', 'http://subversion.tigris.org/'),
132 }
133

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5