From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E8B0E13800E for ; Mon, 30 Jul 2012 13:00:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8A9EDE01C5; Mon, 30 Jul 2012 12:59:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 4483EE01C5 for ; Mon, 30 Jul 2012 12:59:24 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 387C21B400C for ; Mon, 30 Jul 2012 12:59:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id F2D4FE5437 for ; Mon, 30 Jul 2012 12:59:22 +0000 (UTC) From: "Slava Bacherikov" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Slava Bacherikov" Message-ID: <1343329733.87abd35a016bf1058748d4f775b37a1c0d0f2cb7.bacher09@gentoo> Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/package_info/generic_metadata/ X-VCS-Repository: proj/gentoo-packages X-VCS-Files: gpackages/libs/package_info/generic_metadata/glsa.py X-VCS-Directories: gpackages/libs/package_info/generic_metadata/ X-VCS-Committer: bacher09 X-VCS-Committer-Name: Slava Bacherikov X-VCS-Revision: 87abd35a016bf1058748d4f775b37a1c0d0f2cb7 X-VCS-Branch: master Date: Mon, 30 Jul 2012 12:59:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: dab24ac8-efd6-41fe-9e0a-f5329d2bf8fd X-Archives-Hash: 840f337cf9258ed809108800e8961d37 commit: 87abd35a016bf1058748d4f775b37a1c0d0f2cb7 Author: Slava Bacherikov bacher09 org> AuthorDate: Thu Jul 26 19:08:53 2012 +0000 Commit: Slava Bacherikov bacherikov org ua> CommitDate: Thu Jul 26 19:08:53 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=87abd35a Add base glsa parser --- .../libs/package_info/generic_metadata/glsa.py | 71 ++++++++++++++++++++ 1 files changed, 71 insertions(+), 0 deletions(-) diff --git a/gpackages/libs/package_info/generic_metadata/glsa.py b/gpackages/libs/package_info/generic_metadata/glsa.py new file mode 100644 index 0000000..a3cb06d --- /dev/null +++ b/gpackages/libs/package_info/generic_metadata/glsa.py @@ -0,0 +1,71 @@ +import os +import os.path +import re +from .my_etree import etree +from ..generic import ToStrMixin + +GLSA_FILE_RE = r'^glsa-\d{6}-\d{2}\.xml$' +glsa_re = re.compile(GLSA_FILE_RE) + +def children_text(node): + parts = ([node.text] + + [etree.tostring(c) for c in node.getchildren()] + ) + return ''.join(filter(None, parts)) + + +class GLSAs(ToStrMixin): + + def __init__(self, repo_path = '/usr/portage'): + self.glsa_path = os.path.join(repo_path, 'metadata', 'glsa') + if not os.path.isdir(self.glsa_path): + raise ValueError + # For repr + self.repo_path = repo_path + + def iter_glsa(self): + for name in os.listdir(self.glsa_path): + try: + i = GLSA(os.path.join(self.glsa_path, name)) + except ValueError: + pass + else: + yield i + + def __unicode__(self): + return self.repo_path + +class GLSA(ToStrMixin): + + simple_attrs = ('synopsis', 'background', 'description', + 'workaround', 'resolution') + + def __init__(self, file_name): + if not os.path.isfile(file_name): + raise ValueError + + dir, name = os.path.split(file_name) + m = glsa_re.match(name) + if m is None: + raise ValueError + + xml = etree.parse(file_name) + + root = xml.getroot() + id = root.attrib.get('id') + self.glsa_id = id + self.title = root.find('title').text + for attr in self.simple_attrs: + node = root.find(attr) + if node is not None: + setattr(self, attr, children_text(node)) + else: + setattr(self, attr, None) + + impact_xml = root.find('impact') + self.impact_type = impact_xml.attrib.get('type') + self.impact = children_text(impact_xml) + + + def __unicode__(self): + return unicode(self.glsa_id)