def run(self):
tmp_dir = mkdtemp()
griffith_list = open(os.path.join(tmp_dir,"movies"),"w")
t = []
def checkForNoneAndEncode(val):
if val is None:
return ''
return val.encode('utf-8')
movies = self.get_query().execute().fetchall()
for movie in movies:
t.append("%s | %s | %s | %s" % (movie['number'], \
checkForNoneAndEncode(movie['o_title']),
checkForNoneAndEncode(movie['title']),
checkForNoneAndEncode(movie['director'])))
griffith_list.write("<title>%s</title><br><br>" % _("My Movies List"))
for movie in t:
griffith_list.write(movie)
griffith_list.write("<br>")
griffith_list.close()
# this is a mac, lets export to iPod's notes folder
# TODO: windows and linux iPod autodetection
if platform.system() == 'Darwin':
thisPod=Path2iPod()
thisPath=thisPod.returnPath()
if thisPath:
commands.getoutput('mv '+os.path.join(tmp_dir,"movies")+' "'+thisPath+'/Notes/"') # FIXME: WTF?
gutils.info(_("List successfully exported to iPod."), self.parent_window)
else:
gutils.info(_("iPod is not connected."), self.parent_window)
# this is not a mac, lets save the file
else:
filename = gutils.file_chooser(_("Export a %s document")%"iPod", action=gtk.FILE_CHOOSER_ACTION_SAVE, \
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK),name='ipod_griffith_list')
if filename and filename[0]:
overwrite = None
if os.path.isfile(filename[0]):
if gutils.question(_("File exists. Do you want to overwrite it?"), self.parent_window):
overwrite = True
else:
overwrite = False
if overwrite == True or overwrite is None:
shutil.copyfile(os.path.join(tmp_dir,"movies"), filename[0])
gutils.info(_("The list was successfully exported. Now you should move it to the 'Notes' folder on your iPod."), self.parent_window)
评论列表
文章目录