From 6516220b17d7987900961863a0b6dec23ac14855 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 28 Apr 2011 13:59:53 -0500 Subject: isotests: update some syntax and ways of doing things To be more Django-like, Pythonic, or to fit better in the existing archweb project. Also add some created fields to the models, as storing dates for anything is almost always a good idea. Signed-off-by: Dan McGee --- isotests/management/commands/syncisos.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'isotests/management/commands/syncisos.py') diff --git a/isotests/management/commands/syncisos.py b/isotests/management/commands/syncisos.py index 4cc6908..9c76ccd 100644 --- a/isotests/management/commands/syncisos.py +++ b/isotests/management/commands/syncisos.py @@ -2,10 +2,10 @@ import re import urllib from HTMLParser import HTMLParser, HTMLParseError +from django.conf import settings from django.core.management.base import BaseCommand, CommandError from isotests.models import Iso -from settings import ISOLISTURL class IsoListParser(HTMLParser): def __init__(self): @@ -23,25 +23,22 @@ class IsoListParser(HTMLParser): def parse(self, url): try: - f = urllib.urlopen(url) - - s = f.read() - f.close() - - self.feed(s) + 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' % ISOLISTURL + 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(ISOLISTURL) + new_isos = parser.parse(settings.ISO_LIST_URL) for iso in new_isos: if iso not in isonames: -- cgit v1.2.3-24-g4f1b