aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'utils/qa_check_herd.py')
-rw-r--r--utils/qa_check_herd.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/utils/qa_check_herd.py b/utils/qa_check_herd.py
index 21c5ead..7088d5a 100644
--- a/utils/qa_check_herd.py
+++ b/utils/qa_check_herd.py
@@ -1,8 +1,10 @@
#! /usr/bin/env python
import os, sys
+import urllib2
from datetime import datetime
-from lxml.etree import parse
+from lxml.etree import fromstring
+from optparse import OptionParser
path = os.path.join(os.path.dirname(__file__), os.path.pardir)
sys.path.insert(0, path)
@@ -11,6 +13,7 @@ del path
from grumpy import app
from grumpy.models import db, Herd, PkgIssue, Setting
+HERDS_URL = 'http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/xml/htdocs/proj/en/metastructure/herds/herds.xml'
PLUGIN_NAME='qa::valid_herd'
def gc_collect(timestamp):
@@ -45,26 +48,29 @@ def insert_issues(invalid):
'Herd %s is not listed in official herd list.' % herd))
db.session.commit()
-def parse_herds_xml(file):
+def download_and_parse_herds():
"""Return list of herd names from 'herds.xml'"""
+ data = urllib2.urlopen(HERDS_URL)
herds = []
- if not os.path.isfile(file):
- print ("File '%s' does not exist" % file)
- raise RuntimeError
- for child in parse(file).getroot().getchildren():
+ for child in fromstring(data.read()).getchildren():
for value in child.getchildren():
if value.tag == 'name':
herds.append(value.text)
return herds
if __name__ == '__main__':
- # TODO: Download latest herds file
- # Parse list of herds from file
- herds = parse_herds_xml('herds.xml')
+ parser = OptionParser(usage="usage: %prog [options] CONFFILE")
+ (opts, args) = parser.parse_args()
+ if len(args) != 1:
+ parser.error("provide path to configuration file as first argument")
+ sys.exit(1)
+ # Fetch data and parse it
+ herds = download_and_parse_herds()
b0rks = []
timestamp = datetime.now()
- # Setup database for application
with app.test_request_context():
+ # Load configuration
+ app.config.from_pyfile(args[0])
# Fetch list of herds from db
for herd in Herd.query.all():
if herd.name in herds: