/[soft]/mga-gnome/trunk/mga-gnome
ViewVC logotype

Contents of /mga-gnome/trunk/mga-gnome

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2936 - (show annotations) (download)
Sun Feb 12 12:23:46 2012 UTC (8 years, 8 months ago) by ovitters
File size: 6506 byte(s)
read dep3 meta-data from patches
1 #!/usr/bin/python
2
3 import os
4 import os.path
5 import sys
6 import re
7 import subprocess
8 import urllib2
9 import urlparse
10 import argparse
11 import errno
12 from sgmllib import SGMLParser
13
14 MEDIA="Core Release Source"
15 URL="http://download.gnome.org/sources/"
16 PKGROOT='~/pkgs'
17
18 def line_input (file):
19 for line in file:
20 if line[-1] == '\n':
21 yield line[:-1]
22 else:
23 yield line
24
25 class urllister(SGMLParser):
26 def reset(self):
27 SGMLParser.reset(self)
28 self.urls = []
29
30 def start_a(self, attrs):
31 href = [v for k, v in attrs if k=='href']
32 if href:
33 self.urls.extend(href)
34
35 class Patch(object):
36 """Do things with patches"""
37
38 re_dep3 = re.compile(r'^(?:#\s*)?(?P<header>[-A-Za-z0-9]+?):\s*(?P<data>.*)$')
39 re_dep3_cont = re.compile(r'^#?\s+(?P<data>.*)$')
40
41 def __init__(self, path, show_path=False):
42 """Path: path to patch (might not exist)"""
43 self.path = path
44 self.show_path = show_path
45
46 def __str__(self):
47 return self.path if self.show_path else os.path.basename(self.path)
48
49 def add_dep3(self):
50 pass
51 #Author: fwang
52 #Subject: Build fix: Fix glib header inclusion
53 #Applied-Upstream: commit:30602
54 #Forwarded: yes
55 #Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247
56
57 def _read_dep3(self):
58 """This will also parse git headers"""
59 dep3 = {}
60
61 last_header = None
62 try:
63 with open(self.path, "r") as f:
64 for line in line_input(f):
65 # Check for start of real patch
66 if line == '---':
67 break
68
69 r = self.re_dep3.match(line)
70 if r:
71 info = r.groupdict()
72 dep3[info['header']] = info['data']
73 last_header = info['header']
74 continue
75
76 r = self.re_dep3_cont.match(line)
77 if r:
78 info = r.groupdict()
79 if last_header:
80 dep3[last_header] = " ".join((dep3[last_header], info['data']))
81 continue
82
83 last_header = None
84 except IOError:
85 pass
86 self._dep3 = dep3
87
88 @property
89 def dep3(self):
90 if not hasattr(self, '_dep3'):
91 self._read_dep3()
92
93 return self._dep3
94
95
96 def get_upstream_names():
97 urlopen = urllib2.build_opener()
98
99 good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')
100
101 # Get the files
102 usock = urlopen.open(URL)
103 parser = urllister()
104 parser.feed(usock.read())
105 usock.close()
106 parser.close()
107 files = parser.urls
108
109 tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)])
110
111 return tarballs
112
113 def get_downstream_names():
114 re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$')
115
116 p = subprocess.Popen(['urpmf', '--files', '.', "--media", MEDIA], stdout=subprocess.PIPE, close_fds=True)
117 contents = p.stdout.read().strip("\n").splitlines()
118 ecode = p.wait()
119 if ecode != 0:
120 sys.exit(1)
121
122 FILES = {}
123 TARBALLS = {}
124
125 for line in contents:
126 try:
127 srpm, filename = line.split(":")
128 except ValueError:
129 print >>sys.stderr, line
130 continue
131
132 if '.tar' in filename:
133 r = re_file.match(filename)
134 if r:
135 fileinfo = r.groupdict()
136 module = fileinfo['module']
137
138 if module not in TARBALLS:
139 TARBALLS[module] = set()
140 TARBALLS[module].add(srpm)
141
142 if srpm not in FILES:
143 FILES[srpm] = set()
144 FILES[srpm].add(filename)
145
146 return TARBALLS, FILES
147
148 def cmd_co(options, parser):
149 upstream = get_upstream_names()
150 downstream, downstream_files = get_downstream_names()
151
152 cwd = os.path.expanduser(PKGROOT)
153
154 matches = upstream & set(downstream.keys())
155 for module in matches:
156 print module, "\t".join(downstream[module])
157 for package in downstream[module]:
158 subprocess.call(['mgarepo', 'co', package], cwd=cwd)
159
160 def cmd_ls(options, parser):
161 upstream = get_upstream_names()
162 downstream, downstream_files = get_downstream_names()
163
164 matches = upstream & set(downstream.keys())
165 for module in matches:
166 print "\n".join(downstream[module])
167
168 def cmd_patches(options, parser):
169 upstream = get_upstream_names()
170 downstream, downstream_files = get_downstream_names()
171
172 path = os.path.expanduser(PKGROOT)
173
174 import pprint
175
176 matches = upstream & set(downstream.keys())
177 for module in sorted(matches):
178 for srpm in downstream[module]:
179 for filename in downstream_files[srpm]:
180 if '.patch' in filename or '.diff' in filename:
181 p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)
182 print "\t".join((module, srpm, str(p)))
183 if p.dep3:
184 pprint.pprint(p.dep3)
185
186 def main():
187 description = """Mageia GNOME commands."""
188 epilog="""Report bugs to Olav Vitters"""
189 parser = argparse.ArgumentParser(description=description,epilog=epilog)
190
191 # SUBPARSERS
192 subparsers = parser.add_subparsers(title='subcommands')
193 # install
194 subparser = subparsers.add_parser('co', help='checkout all GNOME modules')
195 subparser.set_defaults(
196 func=cmd_co
197 )
198
199 subparser = subparsers.add_parser('packages', help='list all GNOME packages')
200 subparser.set_defaults(
201 func=cmd_ls
202 )
203
204 subparser = subparsers.add_parser('patches', help='list all GNOME patches')
205 subparser.add_argument("-p", "--path", action="store_true", dest="path",
206 help="Full path to patch")
207 subparser.set_defaults(
208 func=cmd_patches, path=False
209 )
210
211
212 if len(sys.argv) == 1:
213 parser.print_help()
214 sys.exit(2)
215
216 options = parser.parse_args()
217
218 try:
219 options.func(options, parser)
220 except KeyboardInterrupt:
221 print('Interrupted')
222 sys.exit(1)
223 except EOFError:
224 print('EOF')
225 sys.exit(1)
226 except IOError, e:
227 if e.errno != errno.EPIPE:
228 raise
229 sys.exit(0)
230
231 if __name__ == "__main__":
232 main()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.28