From ef79c9991b55975157607c6d7b0cca52a6929023 Mon Sep 17 00:00:00 2001 From: ryuslash Date: Thu, 22 Apr 2010 22:24:38 +0200 Subject: [PATCH] Nasty bug where it didn't actually save anything --- backend.py | 4 +++- download.py | 8 ++++++++ sorter.py | 10 +++++++++- util.py | 3 +-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend.py b/backend.py index 8dffb3e..f2f2a1b 100644 --- a/backend.py +++ b/backend.py @@ -34,7 +34,9 @@ class _Backend(object): return False def save(self): - os.remove(self.table) + if os.path.exists(self.table): + os.remove(self.table) + self.create_store_if_needed() for f in self.__new_collection: self.store.insert(self.table, [f]) diff --git a/download.py b/download.py index 42fcd52..eeec200 100644 --- a/download.py +++ b/download.py @@ -23,6 +23,7 @@ import htmlparser import config import sys import backend +import util def get_savedir(): conf = config.Configuration() @@ -125,6 +126,8 @@ class Downloader(object): progress.show_progress(i) filename = os.path.join(get_savedir(), os.path.split(link)[1]) if not check_archive(filename): + util.log(util.LogType.Msg, "%s is not in archive" % filename, None) + tries = 10 while tries > 0: try: @@ -135,10 +138,15 @@ class Downloader(object): if tries == 0: failed += 1 else: + util.log(util.LogType.Msg, "succsesfully downloaded %s" % filename, None) downloaded += 1 if self.on_downloaded is not None: + util.log(util.LogType.Msg, "", self.on_downloaded) + if not self.on_downloaded(filename): failed += 1 + else: + util.log(util.LogType.Warn, "on_downloaded is None", None) else: skipped += 1 i += 1 diff --git a/sorter.py b/sorter.py index 5cb35e9..7df5487 100644 --- a/sorter.py +++ b/sorter.py @@ -24,6 +24,8 @@ import os import datetime import backend +import util + def dummy_option_creator(value1, value2): pass config._optioncreator = dummy_option_creator @@ -34,10 +36,12 @@ class Sorter: self.resolutions = self.conf.get_resolutions() def act(self, filename): + util.log(util.LogType.Msg, "sorter is acting", filename) + download_base = self.conf.get_download_location() retval = True - if not self.check_filename(filename): + if self.check_filename(filename): image = None try: image = Image.open(os.path.join(download_base, @@ -46,6 +50,8 @@ class Sorter: retval = False if not image == None and self.archive_check(filename): + util.log(util.LogType.Msg, "Checking resolution", {"filename":filename, "resolution":image.size}) + for resolution in self.resolutions: resolution = resolution.split('x') foldername = "%s-%s" % (resolution[0], @@ -72,6 +78,8 @@ class Sorter: today = datetime.date.today() dest = os.path.join(destpath, "%d-%d-%d" % (today.year, today.month, today.day)) + util.log(util.LogType.Msg, "going to copy %s to %s" % (source, dest), None) + if not os.path.exists(dest): os.makedirs(dest) diff --git a/util.py b/util.py index d7cce7f..1e932cb 100644 --- a/util.py +++ b/util.py @@ -28,11 +28,10 @@ def raw_input_with_default(default, prompt): def log(logtype, message, data = None): global loglevel - print logtype, loglevel, loglevel >= logtype if loglevel >= logtype: print message if not data is None: - print data + print "data:\n\tdata" homedir = os.getenv("HOME") if homedir is None: