FIX: Bunch of fixes for using the Reading List - Send to option now available for specific issues on reading list, transfer or issues to tablet will now work, location of issues on reading list will now be stored based on series directory, and other small code fixes

This commit is contained in:
evilhero 2015-03-28 17:53:18 -04:00
parent 640fafc3d3
commit 2680f66b7a
3 changed files with 79 additions and 63 deletions

View File

@ -68,6 +68,7 @@ def putfile(localpath,file): #localpath=full path to .torrent (including file
return "pass" return "pass"
def sendfiles(filelist): def sendfiles(filelist):
try: try:
import paramiko import paramiko
except ImportError: except ImportError:
@ -97,10 +98,7 @@ def sendfiles(filelist):
if len(filelist) > 0: if len(filelist) > 0:
logger.info('Initiating send for ' + str(len(filelist)) + ' files...') logger.info('Initiating send for ' + str(len(filelist)) + ' files...')
logger.info(sftp) return sendtohome(sftp, remotepath, filelist, transport)
logger.info(filelist)
logger.info(transport)
sendtohome(sftp, remotepath, filelist, transport)
def sendtohome(sftp, remotepath, filelist, transport): def sendtohome(sftp, remotepath, filelist, transport):
@ -109,6 +107,7 @@ def sendtohome(sftp, remotepath, filelist, transport):
port = int(mylar.TAB_HOST[fhost+1:]) port = int(mylar.TAB_HOST[fhost+1:])
successlist = [] successlist = []
filestotal = len(filelist)
for files in filelist: for files in filelist:
tempfile = files['filename'] tempfile = files['filename']
@ -131,18 +130,26 @@ def sendtohome(sftp, remotepath, filelist, transport):
remdir = remotepath remdir = remotepath
localsend = os.path.join(files['filepath'], files['filename']) localsend = files['filepath']
logger.info('Sending : ' + localsend) logger.info('Sending : ' + localsend)
remotesend = os.path.join(remdir,filename) remotesend = os.path.join(remdir,filename)
logger.info('To : ' + remotesend) logger.info('To : ' + remotesend)
try:
sftp.stat(remotesend)
except IOError, e:
if e[0] == 2:
filechk = False
else:
filechk = True
if not filechk: if not filechk:
sendcheck = False sendcheck = False
count = 1 count = 1
while sendcheck == False: while sendcheck == False:
try: try:
sftp.put(localsend, remotesend) sftp.put(localsend, remotesend)#, callback=printTotals)
sendcheck = True sendcheck = True
except Exception, e: except Exception, e:
logger.info('Attempt #' + str(count) + ': ERROR Sending issue to seedbox *** Caught exception: %s: %s' % (e.__class__,e)) logger.info('Attempt #' + str(count) + ': ERROR Sending issue to seedbox *** Caught exception: %s: %s' % (e.__class__,e))
@ -164,7 +171,7 @@ def sendtohome(sftp, remotepath, filelist, transport):
else: else:
logger.info('file already exists - checking if complete or not.') logger.info('file already exists - checking if complete or not.')
filesize = sftp.stat(remotesend).st_size filesize = sftp.stat(remotesend).st_size
if not filesize == files['filesize']: if not filesize == os.path.getsize(files['filepath']):
logger.info('file not complete - attempting to resend') logger.info('file not complete - attempting to resend')
sendcheck = False sendcheck = False
count = 1 count = 1
@ -198,7 +205,11 @@ def sendtohome(sftp, remotepath, filelist, transport):
sftp.close() sftp.close()
transport.close() transport.close()
logger.fdebug('Upload of readlist complete.') logger.fdebug('Upload of readlist complete.')
return return successlist
#def printTotals(transferred, toBeTransferred):
# percent = transferred / toBeTransferred
# logger.info("Transferred: " + str(transferred) + " Out of " + str(toBeTransferred))
#if __name__ == '__main__': #if __name__ == '__main__':
# putfile(sys.argv[1]) # putfile(sys.argv[1])

View File

@ -143,7 +143,7 @@ class Readinglist(object):
return return
for rlist in rl: for rlist in rl:
readlist.append({"filename": rlist['Location'], readlist.append({"filepath": rlist['Location'],
"issueid": rlist['IssueID'], "issueid": rlist['IssueID'],
"comicid": rlist['ComicID']}) "comicid": rlist['ComicID']})
@ -153,77 +153,82 @@ class Readinglist(object):
if len(readlist) > 0: if len(readlist) > 0:
for clist in readlist: for clist in readlist:
if clist['filename'] == 'None' or clist['filename'] is None: if clist['filepath'] == 'None' or clist['filepath'] is None:
logger.warn(module + ' There was a problem with ComicID/IssueID: [' + clist['comicid'] + '/' + clist['issueid'] + ']. I cannot locate the file in the given location (try re-adding to your readlist)') logger.warn(module + ' There was a problem with ComicID/IssueID: [' + clist['comicid'] + '/' + clist['issueid'] + ']. I cannot locate the file in the given location (try re-adding to your readlist)[' + clist['filepath'] + ']')
continue continue
else: else:
multiplecid = False # multiplecid = False
for x in cidlist: # for x in cidlist:
if clist['comicid'] == x['comicid']: # if clist['comicid'] == x['comicid']:
comicid = x['comicid'] # comicid = x['comicid']
comiclocation = x['location'] # comiclocation = x['location']
multiplecid = True # multiplecid = True
if multiplecid == False: # if multiplecid == False:
cid = myDB.selectone("SELECT * FROM comics WHERE ComicID=?", [clist['comicid']]).fetchone() # cid = myDB.selectone("SELECT * FROM comics WHERE ComicID=?", [clist['comicid']]).fetchone()
if cid is None: # if cid is None:
continue # continue
else: # else:
comiclocation = cid['ComicLocation'] # comiclocation = cid['ComicLocation']
comicid = cid['ComicID'] # comicid = cid['ComicID']
if mylar.MULTIPLE_DEST_DIRS is not None and mylar.MULTIPLE_DEST_DIRS != 'None' and os.path.join(mylar.MULTIPLE_DEST_DIRS, os.path.basename(comiclocation)) != comiclocation: # if mylar.MULTIPLE_DEST_DIRS is not None and mylar.MULTIPLE_DEST_DIRS != 'None' and os.path.join(mylar.MULTIPLE_DEST_DIRS, os.path.basename(comiclocation)) != comiclocation:
logger.fdebug(module + ' Multiple_dest_dirs:' + mylar.MULTIPLE_DEST_DIRS) # logger.fdebug(module + ' Multiple_dest_dirs:' + mylar.MULTIPLE_DEST_DIRS)
logger.fdebug(module + ' Dir: ' + comiclocation) # logger.fdebug(module + ' Dir: ' + comiclocation)
logger.fdebug(module + ' Os.path.basename: ' + os.path.basename(comiclocation)) # logger.fdebug(module + ' Os.path.basename: ' + os.path.basename(comiclocation))
pathdir = os.path.join(mylar.MULTIPLE_DEST_DIRS, os.path.basename(comiclocation)) # pathdir = os.path.join(mylar.MULTIPLE_DEST_DIRS, os.path.basename(comiclocation))
if os.path.exists(os.path.join(pathdir, clist['filename'])): if os.path.exists(clist['filepath']):
sendlist.append({"issueid": clist['issueid'], sendlist.append({"issueid": clist['issueid'],
"filepath": pathdir, "filepath": clist['filepath'],
"filename": clist['filename']}) "filename": os.path.split(clist['filepath'])[1]})
else: # else:
if os.path.exists(os.path.join(comiclocation, clist['filename'])): # if os.path.exists(os.path.join(comiclocation, clist['filename'])):
sendlist.append({"issueid": clist['issueid'], # sendlist.append({"issueid": clist['issueid'],
"filepath": comiclocation, # "filepath": comiclocation,
"filename": clist['filename']}) # "filename": clist['filename']})
else: # else:
if os.path.exists(os.path.join(comiclocation, clist['filename'])): # if os.path.exists(os.path.join(comiclocation, clist['filename'])):
sendlist.append({"issueid": clist['issueid'], # sendlist.append({"issueid": clist['issueid'],
"filepath": comiclocation, # "filepath": comiclocation,
"filename": clist['filename']}) # "filename": clist['filename']})
else: else:
logger.warn(module + ' ' + clist['filename'] + ' does not exist in the location I expect [' + comiclocation + ']. Remove from the Reading List and Re-add and/or confirm the file exists in the specified location') logger.warn(module + ' ' + clist['filepath'] + ' does not exist in the given location. Remove from the Reading List and Re-add and/or confirm the file exists in the specified location')
continue continue
#cidlist is just for this reference loop to not make unnecessary db calls if the comicid has already been processed. # #cidlist is just for this reference loop to not make unnecessary db calls if the comicid has already been processed.
cidlist.append({"comicid": clist['comicid'], # cidlist.append({"comicid": clist['comicid'],
"issueid": clist['issueid'], # "issueid": clist['issueid'],
"location": comiclocation}) #store the comicid so we don't make multiple sql requests # "location": comiclocation}) #store the comicid so we don't make multiple sql requests
if len(sendlist) == 0: if len(sendlist) == 0:
logger.info(module + ' Nothing to send from your readlist') logger.info(module + ' Nothing to send from your readlist')
return return
logger.info(module + ' Preparing to send ' + str(len(sendlist)) + ' issues to your reading device.') logger.info(module + ' ' + str(len(sendlist)) + ' issues will be sent to your reading device.')
# test if IP is up. # test if IP is up.
# import shlex import shlex
# import subprocess import subprocess
# cmdstring = str('ping -c1 ' + str(mylar.TAB_HOST)) #fhost = mylar.TAB_HOST.find(':')
# cmd = shlex.split(cmdstring) host = mylar.TAB_HOST[:mylar.TAB_HOST.find(':')]
# try:
# output = subprocess.check_output(cmd) cmdstring = str('ping -c1 ' + str(host))
# except subprocess.CalledProcessError,e: cmd = shlex.split(cmdstring)
# logger.info('The host {0} is not Reachable at this time.'.format(cmd[-1])) try:
# return output = subprocess.check_output(cmd)
# else: except subprocess.CalledProcessError,e:
# logger.info('The host {0} is Reachable. Preparing to send files.'.format(cmd[-1])) logger.info(module + ' The host {0} is not Reachable at this time.'.format(cmd[-1]))
return
else:
logger.info(module + ' The host {0} is Reachable. Preparing to send files.'.format(cmd[-1]))
success = mylar.ftpsshup.sendfiles(sendlist) success = mylar.ftpsshup.sendfiles(sendlist)
if len(success) > 0: if len(success) > 0:
for succ in success: for succ in success:
newCTRL = {"issueid": succ['issueid']} newCTRL = {"issueid": succ['issueid']}
newVAL = {"Status": 'Downloaded'} newVAL = {"Status": 'Downloaded',
"StatusChange": helpers.today()}
myDB.upsert("readlist", newVAL, newCTRL) myDB.upsert("readlist", newVAL, newCTRL)

View File

@ -2079,7 +2079,7 @@ class WebInterface(object):
myDB.action('DELETE from readlist WHERE IssueID=?', [IssueID]) myDB.action('DELETE from readlist WHERE IssueID=?', [IssueID])
elif action == 'Send': elif action == 'Send':
logger.fdebug('Queuing ' + mi['Location'] + ' to send to tablet.') logger.fdebug('Queuing ' + mi['Location'] + ' to send to tablet.')
sendtablet_queue.append({"filename": mi['Location'], sendtablet_queue.append({"filepath": mi['Location'],
"issueid": IssueID, "issueid": IssueID,
"comicid": mi['ComicID']}) "comicid": mi['ComicID']})
if len(sendtablet_queue) > 0: if len(sendtablet_queue) > 0: