From bfe6afcd7ac5ae7b6f07caa7b02a33fec710ebda Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 28 Apr 2011 17:58:13 -0500 Subject: Rename isotests to releng Signed-off-by: Dan McGee --- releng/management/__init__.py | 0 releng/management/commands/__init__.py | 0 releng/management/commands/syncisos.py | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 releng/management/__init__.py create mode 100644 releng/management/commands/__init__.py create mode 100644 releng/management/commands/syncisos.py (limited to 'releng/management') diff --git a/releng/management/__init__.py b/releng/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/releng/management/commands/__init__.py b/releng/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/releng/management/commands/syncisos.py b/releng/management/commands/syncisos.py new file mode 100644 index 00000000..247b01cd --- /dev/null +++ b/releng/management/commands/syncisos.py @@ -0,0 +1,48 @@ +import re +import urllib +from HTMLParser import HTMLParser, HTMLParseError + +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError + +from releng.models import Iso + +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: + remote_file = urllib.urlopen(url) + data = remote_file.read() + remote_file.close() + self.feed(data) + self.close() + return self.hyperlinks + except HTMLParseError: + raise CommandError('Couldn\'t parse "%s"' % url) + +class Command(BaseCommand): + help = 'Gets new isos from %s' % settings.ISO_LIST_URL + + def handle(self, *args, **options): + parser = IsoListParser() + isonames = Iso.objects.values_list('name', flat=True) + new_isos = parser.parse(settings.ISO_LIST_URL) + + for iso in new_isos: + if iso not in isonames: + new = Iso(name=iso) + new.save() + +# vim: set ts=4 sw=4 et: -- cgit v1.2.3-54-g00ecf From 23cda53f812f1b907def8a9dcac95167b8c7c395 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 29 Apr 2011 10:16:17 -0500 Subject: releng: auto-deactivate old ISO names Signed-off-by: Dan McGee --- releng/admin.py | 3 ++- releng/management/commands/syncisos.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'releng/management') diff --git a/releng/admin.py b/releng/admin.py index 3d3e7c0b..be5e211f 100644 --- a/releng/admin.py +++ b/releng/admin.py @@ -9,7 +9,8 @@ class IsoAdmin(admin.ModelAdmin): list_filter = ('active',) class TestAdmin(admin.ModelAdmin): - list_display = ('user_name', 'user_email', 'created', 'ip_address', 'iso', 'success') + list_display = ('user_name', 'user_email', 'created', 'ip_address', + 'iso', 'success') list_filter = ('success', 'iso') diff --git a/releng/management/commands/syncisos.py b/releng/management/commands/syncisos.py index 247b01cd..ba174131 100644 --- a/releng/management/commands/syncisos.py +++ b/releng/management/commands/syncisos.py @@ -19,7 +19,7 @@ def handle_starttag(self, tag, attrs): for name, value in attrs: if name == "href": if value != '../' and self.url_re.search(value) != None: - self.hyperlinks.append(value[:len(value)-1]) + self.hyperlinks.append(value[:-1]) def parse(self, url): try: @@ -38,11 +38,14 @@ class Command(BaseCommand): def handle(self, *args, **options): parser = IsoListParser() isonames = Iso.objects.values_list('name', flat=True) - new_isos = parser.parse(settings.ISO_LIST_URL) + active_isos = parser.parse(settings.ISO_LIST_URL) - for iso in new_isos: + # create any names that don't already exist + for iso in active_isos: if iso not in isonames: - new = Iso(name=iso) + new = Iso(name=iso, active=True) new.save() + # and then mark all other names as no longer active + Iso.objects.exclude(name__in=active_isos).update(active=False) # vim: set ts=4 sw=4 et: -- cgit v1.2.3-54-g00ecf