import osso
import cairo
import datetime
+import shutil
supports_alpha = False
# comiccache is the location of the images
APP_VERSION = "0.2.5"
+basedbdir = "/opt/comic-widget/db/"
imagedir = "/opt/comic-widget/images/"
-dbdir = "/opt/comic-widget/db/"
+dbdir = "/home/user/.comic-widget/"
comiccache = "/home/user/MyDocs/.comics/"
comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
"sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
if os.path.isfile(self.dbfile) == True:
dbf = open(self.dbfile, 'r')
# if not, create it.
- else:
- dbf = open(self.dbfile, 'w')
- dbf.write('comic,id,link,url,filename,title\n')
- dbf.close()
- dbf = open(self.dbfile, 'r')
- self.fetch_latest_std(self.comic, self.start)
-
- if not os.path.exists(comiccache + self.comic + "/"):
- try:
- os.makedirs(comiccache + self.comic + "/")
- except:
- print "comic cache creation failed"
- exit()
+ dbf = self.get_dbfile()
dbr = csv.DictReader(dbf)
self.db = []
for row in dbr:
dbf.close()
self.currentcomic = 0
+
+
+ def get_dbfile(self):
+ #if db file exist, read it
+ if os.path.isfile(self.dbfile) == True:
+ dbf = open(self.dbfile, 'r')
+ return dbf
+ # if not, copy it.
+ else:
+ if not os.path.exists(dbdir):
+ try:
+ os.makedirs(dbdir)
+ except:
+ print "comic db creation failed on mkdir"
+ exit()
+ try:
+ shutil.copyfile(basedbdir + "comicdb." + self.comic + ".csv", dbdir + "comicdb." + self.comic + ".csv")
+ except:
+ print "comic db creation failed on copy"
+ exit()
+ if os.path.isfile(self.dbfile) == True:
+ dbf = open(self.dbfile, 'r')
+ return dbf
+ else:
+ print "comic db creation failed after copy"
+ exit()
+
+
def get_comic(self):
print str(self.currentcomic)
if self.currentcomic < 0: