From 7d0daec82c7a76f6f62c87ad1190d82a0cc92f47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcus=20Wikstr=F6m?= Date: Sun, 31 Jan 2010 19:22:22 +0200 Subject: [PATCH] bugfixes --- src/usr/lib/hildon-desktop/comic-widget.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/usr/lib/hildon-desktop/comic-widget.py b/src/usr/lib/hildon-desktop/comic-widget.py index 6c3ae6e..0965909 100644 --- a/src/usr/lib/hildon-desktop/comic-widget.py +++ b/src/usr/lib/hildon-desktop/comic-widget.py @@ -28,14 +28,13 @@ comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":d # handling of the comics class ComicDb(): def __init__(self, comic): - #if no db, start from this comic id. self.comic = comic self.start = comics[self.comic]["start"] self.dbfile = comics[self.comic]["dbfile"] #if db file exist, read it - if os.path.isfile(self.dbfile) == True: - dbf = open(self.dbfile, 'r') + # if os.path.isfile(self.dbfile) == True: + # dbf = open(self.dbfile, 'r') # if not, create it. dbf = self.get_dbfile() dbr = csv.DictReader(dbf) @@ -49,17 +48,21 @@ class ComicDb(): def get_dbfile(self): #if db file exist, read it + print "fetching " + self.dbfile if os.path.isfile(self.dbfile) == True: + print "found " + self.dbfile dbf = open(self.dbfile, 'r') return dbf # if not, copy it. else: - if not os.path.exists(dbdir): + print "file " + self.dbfile + " not found" + if not os.path.exists(dbdir + self.comic + "/"): + print "path not found: " + dbdir + self.comic + "/" try: - os.makedirs(dbdir) + os.makedirs(dbdir + self.comic + "/") except: print "comic db creation failed on mkdir" - exit() + exit() try: shutil.copyfile(basedbdir + "comicdb." + self.comic + ".csv", dbdir + "comicdb." + self.comic + ".csv") except: @@ -93,6 +96,13 @@ class ComicDb(): else: #fetch file print filename + " not found\nretrieving " + dbrow['url'] + "\n" + if not os.path.exists(comiccache + self.comic + "/"): + print "create dir " + comiccache + self.comic + "/" + try: + os.makedirs(comiccache + self.comic + "/") + print "created dir" + except: + print "comic db creation failed on mkdir" urllib.urlretrieve(dbrow['url'], filename) print "success\n" return filename -- 1.7.9.5