summaryrefslogtreecommitdiff
path: root/isotests
diff options
context:
space:
mode:
authorTom Willemsen <tom.willemsen@archlinux.us>2011-03-31 22:39:40 +0200
committerDan McGee <dan@archlinux.org>2011-04-28 13:18:35 -0500
commitdb137d4db607461dd32c46e40bee9084eb508da9 (patch)
tree4802584bf708c96b3299200c440657d15e228558 /isotests
parent00e096ddf0654d32e67ac8bc47f3de01ed7e740b (diff)
isotests: add syncisos command
* Installtype fixture places 'interactive' at the top now. * Added a syncisos command to isotests to get new iso names from http://releng.archlinux.org/isos/ and add them to the database. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'isotests')
-rw-r--r--isotests/fixtures/installtype.json8
-rw-r--r--isotests/management/__init__.py0
-rw-r--r--isotests/management/commands/__init__.py0
-rw-r--r--isotests/management/commands/syncisos.py51
4 files changed, 55 insertions, 4 deletions
diff --git a/isotests/fixtures/installtype.json b/isotests/fixtures/installtype.json
index d23bd4b2..cc5c62a0 100644
--- a/isotests/fixtures/installtype.json
+++ b/isotests/fixtures/installtype.json
@@ -3,28 +3,28 @@
"pk": 1,
"model": "isotests.installtype",
"fields": {
- "name": "automatic install generic example"
+ "name": "interactive install"
}
},
{
"pk": 2,
"model": "isotests.installtype",
"fields": {
- "name": "automatic install fancy example"
+ "name": "automatic install generic example"
}
},
{
"pk": 3,
"model": "isotests.installtype",
"fields": {
- "name": "automatic install custom config (specify in comments)"
+ "name": "automatic install fancy example"
}
},
{
"pk": 4,
"model": "isotests.installtype",
"fields": {
- "name": "interactive install"
+ "name": "automatic install custom config (specify in comments)"
}
}
]
diff --git a/isotests/management/__init__.py b/isotests/management/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/isotests/management/__init__.py
diff --git a/isotests/management/commands/__init__.py b/isotests/management/commands/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/isotests/management/commands/__init__.py
diff --git a/isotests/management/commands/syncisos.py b/isotests/management/commands/syncisos.py
new file mode 100644
index 00000000..975104d9
--- /dev/null
+++ b/isotests/management/commands/syncisos.py
@@ -0,0 +1,51 @@
+import re
+import urllib
+from HTMLParser import HTMLParser, HTMLParseError
+
+from django.core.management.base import BaseCommand, CommandError
+
+from isotests.models import Iso
+from settings import ISOLISTURL
+
+class IsoListParser(HTMLParser):
+ def __init__(self):
+ HTMLParser.__init__(self)
+
+ self.hyperlinks = []
+ self.url_re = re.compile('(?!\.{2})/$')
+
+ def handle_starttag(self, tag, attrs):
+ if tag == 'a':
+ for name, value in attrs:
+ if name == "href":
+ if value != '../' and self.url_re.search(value) != None:
+ self.hyperlinks.append(value[:len(value)-1])
+
+ def parse(self, url):
+ try:
+ f = urllib.urlopen(url)
+
+ s = f.read()
+ f.close()
+
+ self.feed(s)
+ self.close()
+
+ return self.hyperlinks
+ except HTMLParseError:
+ raise CommandError('Couldn\'t parse "%s"' % url)
+
+class Command(BaseCommand):
+ help = 'Gets new isos from http://releng.archlinux.org/isos/'
+
+ def handle(self, *args, **options):
+ parser = IsoListParser()
+ isonames = Iso.objects.values_list('name', flat=True)
+ new_isos = parser.parse(ISOLISTURL)
+
+ for iso in new_isos:
+ if iso not in isonames:
+ new = Iso(name=iso)
+ new.save()
+
+# vim: set ts=4 sw=4 et: