bugfixes
[comic-widget] / src / usr / lib / hildon-desktop / comic-widget.py
index 6c3ae6e..0965909 100644 (file)
@@ -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