1 |
commit: 87abd35a016bf1058748d4f775b37a1c0d0f2cb7 |
2 |
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org> |
3 |
AuthorDate: Thu Jul 26 19:08:53 2012 +0000 |
4 |
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua> |
5 |
CommitDate: Thu Jul 26 19:08:53 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=87abd35a |
7 |
|
8 |
Add base glsa parser |
9 |
|
10 |
--- |
11 |
.../libs/package_info/generic_metadata/glsa.py | 71 ++++++++++++++++++++ |
12 |
1 files changed, 71 insertions(+), 0 deletions(-) |
13 |
|
14 |
diff --git a/gpackages/libs/package_info/generic_metadata/glsa.py b/gpackages/libs/package_info/generic_metadata/glsa.py |
15 |
new file mode 100644 |
16 |
index 0000000..a3cb06d |
17 |
--- /dev/null |
18 |
+++ b/gpackages/libs/package_info/generic_metadata/glsa.py |
19 |
@@ -0,0 +1,71 @@ |
20 |
+import os |
21 |
+import os.path |
22 |
+import re |
23 |
+from .my_etree import etree |
24 |
+from ..generic import ToStrMixin |
25 |
+ |
26 |
+GLSA_FILE_RE = r'^glsa-\d{6}-\d{2}\.xml$' |
27 |
+glsa_re = re.compile(GLSA_FILE_RE) |
28 |
+ |
29 |
+def children_text(node): |
30 |
+ parts = ([node.text] + |
31 |
+ [etree.tostring(c) for c in node.getchildren()] |
32 |
+ ) |
33 |
+ return ''.join(filter(None, parts)) |
34 |
+ |
35 |
+ |
36 |
+class GLSAs(ToStrMixin): |
37 |
+ |
38 |
+ def __init__(self, repo_path = '/usr/portage'): |
39 |
+ self.glsa_path = os.path.join(repo_path, 'metadata', 'glsa') |
40 |
+ if not os.path.isdir(self.glsa_path): |
41 |
+ raise ValueError |
42 |
+ # For repr |
43 |
+ self.repo_path = repo_path |
44 |
+ |
45 |
+ def iter_glsa(self): |
46 |
+ for name in os.listdir(self.glsa_path): |
47 |
+ try: |
48 |
+ i = GLSA(os.path.join(self.glsa_path, name)) |
49 |
+ except ValueError: |
50 |
+ pass |
51 |
+ else: |
52 |
+ yield i |
53 |
+ |
54 |
+ def __unicode__(self): |
55 |
+ return self.repo_path |
56 |
+ |
57 |
+class GLSA(ToStrMixin): |
58 |
+ |
59 |
+ simple_attrs = ('synopsis', 'background', 'description', |
60 |
+ 'workaround', 'resolution') |
61 |
+ |
62 |
+ def __init__(self, file_name): |
63 |
+ if not os.path.isfile(file_name): |
64 |
+ raise ValueError |
65 |
+ |
66 |
+ dir, name = os.path.split(file_name) |
67 |
+ m = glsa_re.match(name) |
68 |
+ if m is None: |
69 |
+ raise ValueError |
70 |
+ |
71 |
+ xml = etree.parse(file_name) |
72 |
+ |
73 |
+ root = xml.getroot() |
74 |
+ id = root.attrib.get('id') |
75 |
+ self.glsa_id = id |
76 |
+ self.title = root.find('title').text |
77 |
+ for attr in self.simple_attrs: |
78 |
+ node = root.find(attr) |
79 |
+ if node is not None: |
80 |
+ setattr(self, attr, children_text(node)) |
81 |
+ else: |
82 |
+ setattr(self, attr, None) |
83 |
+ |
84 |
+ impact_xml = root.find('impact') |
85 |
+ self.impact_type = impact_xml.attrib.get('type') |
86 |
+ self.impact = children_text(impact_xml) |
87 |
+ |
88 |
+ |
89 |
+ def __unicode__(self): |
90 |
+ return unicode(self.glsa_id) |