mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-07 05:31:11 -07:00
Python 3: Convert except ExceptClass, Target: to except ExceptClass as Target:
This commit is contained in:
parent
5903538ae5
commit
ec71e7806d
7 changed files with 28 additions and 28 deletions
|
@ -118,7 +118,7 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
if not os.path.isfile(core.CONFIG_FILE):
|
if not os.path.isfile(core.CONFIG_FILE):
|
||||||
shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE)
|
shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE)
|
||||||
CFG_OLD = config(core.CONFIG_FILE)
|
CFG_OLD = config(core.CONFIG_FILE)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug("Error %s when copying to .cfg" % (e))
|
logger.debug("Error %s when copying to .cfg" % (e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -126,7 +126,7 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
if not os.path.isfile(core.CONFIG_SPEC_FILE):
|
if not os.path.isfile(core.CONFIG_SPEC_FILE):
|
||||||
shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE)
|
shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE)
|
||||||
CFG_NEW = config(core.CONFIG_SPEC_FILE)
|
CFG_NEW = config(core.CONFIG_SPEC_FILE)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug("Error %s when copying to .spec" % (e))
|
logger.debug("Error %s when copying to .spec" % (e))
|
||||||
|
|
||||||
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
||||||
|
@ -462,14 +462,14 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
CFG_NEW[section][os.environ[envCatKey]][option] = value
|
CFG_NEW[section][os.environ[envCatKey]][option] = value
|
||||||
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
|
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug("Error %s when applying NZBGet config" % (e))
|
logger.debug("Error %s when applying NZBGet config" % (e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# write our new config to autoProcessMedia.cfg
|
# write our new config to autoProcessMedia.cfg
|
||||||
CFG_NEW.filename = core.CONFIG_FILE
|
CFG_NEW.filename = core.CONFIG_FILE
|
||||||
CFG_NEW.write()
|
CFG_NEW.write()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug("Error %s when writing changes to .cfg" % (e))
|
logger.debug("Error %s when writing changes to .cfg" % (e))
|
||||||
|
|
||||||
return CFG_NEW
|
return CFG_NEW
|
||||||
|
|
|
@ -37,7 +37,7 @@ class DBConnection:
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
result = self.select("SELECT db_version FROM db_version")
|
result = self.select("SELECT db_version FROM db_version")
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError as e:
|
||||||
if "no such table: db_version" in e.args[0]:
|
if "no such table: db_version" in e.args[0]:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class DBConnection:
|
||||||
|
|
||||||
# get out of the connection attempt loop since we were successful
|
# get out of the connection attempt loop since we were successful
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError as e:
|
||||||
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
|
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
|
||||||
logger.log(u"DB error: " + str(e), logger.WARNING)
|
logger.log(u"DB error: " + str(e), logger.WARNING)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
@ -76,7 +76,7 @@ class DBConnection:
|
||||||
else:
|
else:
|
||||||
logger.log(u"DB error: " + str(e), logger.ERROR)
|
logger.log(u"DB error: " + str(e), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError, e:
|
except sqlite3.DatabaseError as e:
|
||||||
logger.log(u"Fatal error executing query: " + str(e), logger.ERROR)
|
logger.log(u"Fatal error executing query: " + str(e), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class DBConnection:
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
logger.log(u"Transaction with " + str(len(querylist)) + u" query's executed", logger.DEBUG)
|
logger.log(u"Transaction with " + str(len(querylist)) + u" query's executed", logger.DEBUG)
|
||||||
return sqlResult
|
return sqlResult
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError as e:
|
||||||
sqlResult = []
|
sqlResult = []
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.connection.rollback()
|
self.connection.rollback()
|
||||||
|
@ -114,7 +114,7 @@ class DBConnection:
|
||||||
else:
|
else:
|
||||||
logger.log(u"DB error: " + str(e), logger.ERROR)
|
logger.log(u"DB error: " + str(e), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError, e:
|
except sqlite3.DatabaseError as e:
|
||||||
sqlResult = []
|
sqlResult = []
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.connection.rollback()
|
self.connection.rollback()
|
||||||
|
@ -141,7 +141,7 @@ class DBConnection:
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
# get out of the connection attempt loop since we were successful
|
# get out of the connection attempt loop since we were successful
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError as e:
|
||||||
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
|
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
|
||||||
logger.log(u"DB error: " + str(e), logger.WARNING)
|
logger.log(u"DB error: " + str(e), logger.WARNING)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
@ -149,7 +149,7 @@ class DBConnection:
|
||||||
else:
|
else:
|
||||||
logger.log(u"DB error: " + str(e), logger.ERROR)
|
logger.log(u"DB error: " + str(e), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError, e:
|
except sqlite3.DatabaseError as e:
|
||||||
logger.log(u"Fatal error executing query: " + str(e), logger.ERROR)
|
logger.log(u"Fatal error executing query: " + str(e), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ def _processUpgrade(connection, upgradeClass):
|
||||||
logger.log(u"Database upgrade required: " + prettyName(upgradeClass.__name__), logger.MESSAGE)
|
logger.log(u"Database upgrade required: " + prettyName(upgradeClass.__name__), logger.MESSAGE)
|
||||||
try:
|
try:
|
||||||
instance.execute()
|
instance.execute()
|
||||||
except sqlite3.DatabaseError, e:
|
except sqlite3.DatabaseError as e:
|
||||||
print("Error in " + str(upgradeClass.__name__) + ": " + str(e))
|
print("Error in " + str(upgradeClass.__name__) + ": " + str(e))
|
||||||
raise
|
raise
|
||||||
logger.log(upgradeClass.__name__ + " upgrade completed", logger.DEBUG)
|
logger.log(upgradeClass.__name__ + " upgrade completed", logger.DEBUG)
|
||||||
|
|
|
@ -64,7 +64,7 @@ def rename_file(filename, newfilePath):
|
||||||
logger.debug("Replacing file name %s with download name %s" % (filename, newfilePath), "EXCEPTION")
|
logger.debug("Replacing file name %s with download name %s" % (filename, newfilePath), "EXCEPTION")
|
||||||
try:
|
try:
|
||||||
os.rename(filename, newfilePath)
|
os.rename(filename, newfilePath)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ def rename_script(dirname):
|
||||||
logger.debug("Renaming file %s to %s" % (orig, dest), "EXCEPTION")
|
logger.debug("Renaming file %s to %s" % (orig, dest), "EXCEPTION")
|
||||||
try:
|
try:
|
||||||
os.rename(orig, dest)
|
os.rename(orig, dest)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
||||||
|
|
||||||
# dict for custom groups
|
# dict for custom groups
|
||||||
|
|
|
@ -74,7 +74,7 @@ def makeDir(path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ def copy_link(src, targetLink, useLink):
|
||||||
logger.info("Moving SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
logger.info("Moving SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
||||||
shutil.move(src, targetLink)
|
shutil.move(src, targetLink)
|
||||||
return True
|
return True
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK')
|
logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK')
|
||||||
|
|
||||||
logger.info("Copying SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
logger.info("Copying SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
||||||
|
@ -1104,7 +1104,7 @@ def extractFiles(src, dst=None, keep_archive=None):
|
||||||
if extractor.extract(inputFile, dst or dirPath):
|
if extractor.extract(inputFile, dst or dirPath):
|
||||||
extracted_folder.append(dst or dirPath)
|
extracted_folder.append(dst or dirPath)
|
||||||
extracted_archive.append(archiveName)
|
extracted_archive.append(archiveName)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
logger.error("Extraction failed for: %s" % (fullFileName))
|
logger.error("Extraction failed for: %s" % (fullFileName))
|
||||||
|
|
||||||
for folder in extracted_folder:
|
for folder in extracted_folder:
|
||||||
|
@ -1197,7 +1197,7 @@ def backupVersionedFile(old_file, version):
|
||||||
shutil.copy(old_file, new_file)
|
shutil.copy(old_file, new_file)
|
||||||
logger.log(u"Backup done", logger.DEBUG)
|
logger.log(u"Backup done", logger.DEBUG)
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.log(u"Error while trying to back up " + old_file + " to " + new_file + " : " + str(e),
|
logger.log(u"Error while trying to back up " + old_file + " to " + new_file + " : " + str(e),
|
||||||
logger.WARNING)
|
logger.WARNING)
|
||||||
numTries += 1
|
numTries += 1
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DelugeClient(object):
|
||||||
from xdg.BaseDirectory import save_config_path
|
from xdg.BaseDirectory import save_config_path
|
||||||
try:
|
try:
|
||||||
auth_file = os.path.join(save_config_path("deluge"), "auth")
|
auth_file = os.path.join(save_config_path("deluge"), "auth")
|
||||||
except OSError, e:
|
except OSError:
|
||||||
return username, password
|
return username, password
|
||||||
|
|
||||||
if os.path.exists(auth_file):
|
if os.path.exists(auth_file):
|
||||||
|
@ -51,7 +51,7 @@ class DelugeClient(object):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
try:
|
try:
|
||||||
lsplit = line.split(":")
|
lsplit = line.split(":")
|
||||||
except Exception, e:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if len(lsplit) == 2:
|
if len(lsplit) == 2:
|
||||||
|
|
|
@ -763,10 +763,10 @@ def Transcode_directory(dirName):
|
||||||
|
|
||||||
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
|
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
|
||||||
os.remove(newfilePath)
|
os.remove(newfilePath)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
logger.debug("Error when removing transcoding target: %s" % (e))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
logger.debug("Error when removing transcoding target: %s" % (e))
|
||||||
|
|
||||||
logger.info("Transcoding video: %s" % (newfilePath))
|
logger.info("Transcoding video: %s" % (newfilePath))
|
||||||
|
|
|
@ -312,7 +312,7 @@ class GitUpdateManager(UpdateManager):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._check_github_for_update()
|
self._check_github_for_update()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.log(u"Unable to contact github, can't check for update: " + repr(e), logger.ERROR)
|
logger.log(u"Unable to contact github, can't check for update: " + repr(e), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -356,7 +356,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
try:
|
try:
|
||||||
with open(version_file, 'r') as fp:
|
with open(version_file, 'r') as fp:
|
||||||
self._cur_commit_hash = fp.read().strip(' \n\r')
|
self._cur_commit_hash = fp.read().strip(' \n\r')
|
||||||
except EnvironmentError, e:
|
except EnvironmentError as e:
|
||||||
logger.log(u"Unable to open 'version.txt': " + str(e), logger.DEBUG)
|
logger.log(u"Unable to open 'version.txt': " + str(e), logger.DEBUG)
|
||||||
|
|
||||||
if not self._cur_commit_hash:
|
if not self._cur_commit_hash:
|
||||||
|
@ -370,7 +370,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._check_github_for_update()
|
self._check_github_for_update()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.log(u"Unable to contact github, can't check for update: " + repr(e), logger.ERROR)
|
logger.log(u"Unable to contact github, can't check for update: " + repr(e), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
os.chmod(new_path, stat.S_IWRITE)
|
os.chmod(new_path, stat.S_IWRITE)
|
||||||
os.remove(new_path)
|
os.remove(new_path)
|
||||||
os.renames(old_path, new_path)
|
os.renames(old_path, new_path)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.log(u"Unable to update " + new_path + ': ' + str(e), logger.DEBUG)
|
logger.log(u"Unable to update " + new_path + ': ' + str(e), logger.DEBUG)
|
||||||
os.remove(old_path) # Trash the updated file without moving in new path
|
os.remove(old_path) # Trash the updated file without moving in new path
|
||||||
continue
|
continue
|
||||||
|
@ -517,11 +517,11 @@ class SourceUpdateManager(UpdateManager):
|
||||||
try:
|
try:
|
||||||
with open(version_path, 'w') as ver_file:
|
with open(version_path, 'w') as ver_file:
|
||||||
ver_file.write(self._newest_commit_hash)
|
ver_file.write(self._newest_commit_hash)
|
||||||
except EnvironmentError, e:
|
except EnvironmentError as e:
|
||||||
logger.log(u"Unable to write version file, update not complete: " + str(e), logger.ERROR)
|
logger.log(u"Unable to write version file, update not complete: " + str(e), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.log(u"Error while trying to update: " + str(e), logger.ERROR)
|
logger.log(u"Error while trying to update: " + str(e), logger.ERROR)
|
||||||
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue