mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
Remove u
prefixed strings as all strings are unicode in Python 3.
This commit is contained in:
parent
55e751c9a3
commit
405f7f6af3
6 changed files with 93 additions and 93 deletions
|
@ -40,16 +40,16 @@ class InitialSchema(main_db.SchemaUpgrade):
|
||||||
cur_db_version = self.check_db_version()
|
cur_db_version = self.check_db_version()
|
||||||
|
|
||||||
if cur_db_version < MIN_DB_VERSION:
|
if cur_db_version < MIN_DB_VERSION:
|
||||||
logger.log_error_and_exit(u'Your database version ({current}) is too old to migrate '
|
logger.log_error_and_exit('Your database version ({current}) is too old to migrate '
|
||||||
u'from what this version of nzbToMedia supports ({min}).'
|
'from what this version of nzbToMedia supports ({min}).'
|
||||||
u'\nPlease remove nzbtomedia.db file to begin fresh.'.format
|
'\nPlease remove nzbtomedia.db file to begin fresh.'.format
|
||||||
(current=cur_db_version, min=MIN_DB_VERSION))
|
(current=cur_db_version, min=MIN_DB_VERSION))
|
||||||
|
|
||||||
if cur_db_version > MAX_DB_VERSION:
|
if cur_db_version > MAX_DB_VERSION:
|
||||||
logger.log_error_and_exit(u'Your database version ({current}) has been incremented '
|
logger.log_error_and_exit('Your database version ({current}) has been incremented '
|
||||||
u'past what this version of nzbToMedia supports ({max}).'
|
'past what this version of nzbToMedia supports ({max}).'
|
||||||
u'\nIf you have used other forks of nzbToMedia, your database '
|
'\nIf you have used other forks of nzbToMedia, your database '
|
||||||
u'may be unusable due to their modifications.'.format
|
'may be unusable due to their modifications.'.format
|
||||||
(current=cur_db_version, max=MAX_DB_VERSION))
|
(current=cur_db_version, max=MAX_DB_VERSION))
|
||||||
if cur_db_version < MAX_DB_VERSION: # We need to upgrade.
|
if cur_db_version < MAX_DB_VERSION: # We need to upgrade.
|
||||||
queries = [
|
queries = [
|
||||||
|
|
|
@ -19,12 +19,12 @@ DEBUG = logging.DEBUG
|
||||||
POSTPROCESS = 21
|
POSTPROCESS = 21
|
||||||
DB = 5
|
DB = 5
|
||||||
|
|
||||||
reverseNames = {u'ERROR': ERROR,
|
reverseNames = {'ERROR': ERROR,
|
||||||
u'WARNING': WARNING,
|
'WARNING': WARNING,
|
||||||
u'INFO': MESSAGE,
|
'INFO': MESSAGE,
|
||||||
u'DEBUG': DEBUG,
|
'DEBUG': DEBUG,
|
||||||
u'POSTPROCESS': POSTPROCESS,
|
'POSTPROCESS': POSTPROCESS,
|
||||||
u'DB': DB}
|
'DB': DB}
|
||||||
|
|
||||||
|
|
||||||
class NTMRotatingLogHandler:
|
class NTMRotatingLogHandler:
|
||||||
|
@ -189,9 +189,9 @@ class NTMRotatingLogHandler:
|
||||||
self.writes_since_check += 1
|
self.writes_since_check += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = u'{0}: {1}'.format(section.upper(), to_log)
|
message = '{0}: {1}'.format(section.upper(), to_log)
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
message = u'{0}: Message contains non-utf-8 string'.format(section.upper())
|
message = '{0}: Message contains non-utf-8 string'.format(section.upper())
|
||||||
|
|
||||||
out_line = message
|
out_line = message
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,14 @@ class DBConnection:
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError as error:
|
except sqlite3.OperationalError as error:
|
||||||
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.WARNING)
|
logger.log('DB error: {msg}'.format(msg=error), logger.WARNING)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('DB error: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError as error:
|
except sqlite3.DatabaseError as error:
|
||||||
logger.log(u'Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return sql_result
|
return sql_result
|
||||||
|
@ -94,26 +94,26 @@ class DBConnection:
|
||||||
sql_result.append(self.connection.execute(qu[0]))
|
sql_result.append(self.connection.execute(qu[0]))
|
||||||
elif len(qu) > 1:
|
elif len(qu) > 1:
|
||||||
if log_transaction:
|
if log_transaction:
|
||||||
logger.log(u'{query} with args {args}'.format(query=qu[0], args=qu[1]), logger.DEBUG)
|
logger.log('{query} with args {args}'.format(query=qu[0], args=qu[1]), logger.DEBUG)
|
||||||
sql_result.append(self.connection.execute(qu[0], qu[1]))
|
sql_result.append(self.connection.execute(qu[0], qu[1]))
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
logger.log(u'Transaction with {x} query\'s executed'.format(x=len(querylist)), logger.DEBUG)
|
logger.log('Transaction with {x} query\'s executed'.format(x=len(querylist)), logger.DEBUG)
|
||||||
return sql_result
|
return sql_result
|
||||||
except sqlite3.OperationalError as error:
|
except sqlite3.OperationalError as error:
|
||||||
sql_result = []
|
sql_result = []
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.connection.rollback()
|
self.connection.rollback()
|
||||||
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.WARNING)
|
logger.log('DB error: {msg}'.format(msg=error), logger.WARNING)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('DB error: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError as error:
|
except sqlite3.DatabaseError as error:
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.connection.rollback()
|
self.connection.rollback()
|
||||||
logger.log(u'Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return sql_result
|
return sql_result
|
||||||
|
@ -128,10 +128,10 @@ class DBConnection:
|
||||||
while attempt < 5:
|
while attempt < 5:
|
||||||
try:
|
try:
|
||||||
if args is None:
|
if args is None:
|
||||||
logger.log(u'{name}: {query}'.format(name=self.filename, query=query), logger.DB)
|
logger.log('{name}: {query}'.format(name=self.filename, query=query), logger.DB)
|
||||||
sql_result = self.connection.execute(query)
|
sql_result = self.connection.execute(query)
|
||||||
else:
|
else:
|
||||||
logger.log(u'{name}: {query} with args {args}'.format
|
logger.log('{name}: {query} with args {args}'.format
|
||||||
(name=self.filename, query=query, args=args), logger.DB)
|
(name=self.filename, query=query, args=args), logger.DB)
|
||||||
sql_result = self.connection.execute(query, args)
|
sql_result = self.connection.execute(query, args)
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
|
@ -139,14 +139,14 @@ class DBConnection:
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError as error:
|
except sqlite3.OperationalError as error:
|
||||||
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
if 'unable to open database file' in error.args[0] or 'database is locked' in error.args[0]:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.WARNING)
|
logger.log('DB error: {msg}'.format(msg=error), logger.WARNING)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
logger.log(u'DB error: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('DB error: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
except sqlite3.DatabaseError as error:
|
except sqlite3.DatabaseError as error:
|
||||||
logger.log(u'Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
logger.log('Fatal error executing query: {msg}'.format(msg=error), logger.ERROR)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return sql_result
|
return sql_result
|
||||||
|
@ -218,7 +218,7 @@ class DBSanityCheck:
|
||||||
# ===============
|
# ===============
|
||||||
|
|
||||||
def upgrade_database(connection, schema):
|
def upgrade_database(connection, schema):
|
||||||
logger.log(u'Checking database structure...', logger.MESSAGE)
|
logger.log('Checking database structure...', logger.MESSAGE)
|
||||||
_process_upgrade(connection, schema)
|
_process_upgrade(connection, schema)
|
||||||
|
|
||||||
|
|
||||||
|
@ -228,21 +228,21 @@ def pretty_name(class_name):
|
||||||
|
|
||||||
def _process_upgrade(connection, upgrade_class):
|
def _process_upgrade(connection, upgrade_class):
|
||||||
instance = upgrade_class(connection)
|
instance = upgrade_class(connection)
|
||||||
logger.log(u'Checking {name} database upgrade'.format
|
logger.log('Checking {name} database upgrade'.format
|
||||||
(name=pretty_name(upgrade_class.__name__)), logger.DEBUG)
|
(name=pretty_name(upgrade_class.__name__)), logger.DEBUG)
|
||||||
if not instance.test():
|
if not instance.test():
|
||||||
logger.log(u'Database upgrade required: {name}'.format
|
logger.log('Database upgrade required: {name}'.format
|
||||||
(name=pretty_name(upgrade_class.__name__)), logger.MESSAGE)
|
(name=pretty_name(upgrade_class.__name__)), logger.MESSAGE)
|
||||||
try:
|
try:
|
||||||
instance.execute()
|
instance.execute()
|
||||||
except sqlite3.DatabaseError as error:
|
except sqlite3.DatabaseError as error:
|
||||||
print(u'Error in {name}: {msg}'.format
|
print('Error in {name}: {msg}'.format
|
||||||
(name=upgrade_class.__name__, msg=error))
|
(name=upgrade_class.__name__, msg=error))
|
||||||
raise
|
raise
|
||||||
logger.log(u'{name} upgrade completed'.format
|
logger.log('{name} upgrade completed'.format
|
||||||
(name=upgrade_class.__name__), logger.DEBUG)
|
(name=upgrade_class.__name__), logger.DEBUG)
|
||||||
else:
|
else:
|
||||||
logger.log(u'{name} upgrade not required'.format
|
logger.log('{name} upgrade not required'.format
|
||||||
(name=upgrade_class.__name__), logger.DEBUG)
|
(name=upgrade_class.__name__), logger.DEBUG)
|
||||||
|
|
||||||
for upgradeSubClass in upgrade_class.__subclasses__():
|
for upgradeSubClass in upgrade_class.__subclasses__():
|
||||||
|
|
|
@ -208,23 +208,23 @@ def backup_versioned_file(old_file, version):
|
||||||
|
|
||||||
while not os.path.isfile(new_file):
|
while not os.path.isfile(new_file):
|
||||||
if not os.path.isfile(old_file):
|
if not os.path.isfile(old_file):
|
||||||
logger.log(u'Not creating backup, {file} doesn\'t exist'.format(file=old_file), logger.DEBUG)
|
logger.log('Not creating backup, {file} doesn\'t exist'.format(file=old_file), logger.DEBUG)
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.log(u'Trying to back up {old} to {new]'.format(old=old_file, new=new_file), logger.DEBUG)
|
logger.log('Trying to back up {old} to {new]'.format(old=old_file, new=new_file), logger.DEBUG)
|
||||||
shutil.copy(old_file, new_file)
|
shutil.copy(old_file, new_file)
|
||||||
logger.log(u'Backup done', logger.DEBUG)
|
logger.log('Backup done', logger.DEBUG)
|
||||||
break
|
break
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.log(u'Error while trying to back up {old} to {new} : {msg}'.format
|
logger.log('Error while trying to back up {old} to {new} : {msg}'.format
|
||||||
(old=old_file, new=new_file, msg=error), logger.WARNING)
|
(old=old_file, new=new_file, msg=error), logger.WARNING)
|
||||||
num_tries += 1
|
num_tries += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
logger.log(u'Trying again.', logger.DEBUG)
|
logger.log('Trying again.', logger.DEBUG)
|
||||||
|
|
||||||
if num_tries >= 10:
|
if num_tries >= 10:
|
||||||
logger.log(u'Unable to back up {old} to {new} please do it manually.'.format(old=old_file, new=new_file), logger.ERROR)
|
logger.log('Unable to back up {old} to {new} please do it manually.'.format(old=old_file, new=new_file), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -107,7 +107,7 @@ def restart():
|
||||||
|
|
||||||
if popen_list:
|
if popen_list:
|
||||||
popen_list += SYS_ARGV
|
popen_list += SYS_ARGV
|
||||||
logger.log(u'Restarting nzbToMedia with {args}'.format(args=popen_list))
|
logger.log('Restarting nzbToMedia with {args}'.format(args=popen_list))
|
||||||
logger.close()
|
logger.close()
|
||||||
p = subprocess.Popen(popen_list, cwd=os.getcwd())
|
p = subprocess.Popen(popen_list, cwd=os.getcwd())
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
|
@ -45,7 +45,7 @@ class CheckVersion:
|
||||||
'source': running from source without git
|
'source': running from source without git
|
||||||
"""
|
"""
|
||||||
# check if we're a windows build
|
# check if we're a windows build
|
||||||
if os.path.exists(os.path.join(core.APP_ROOT, u'.git')):
|
if os.path.exists(os.path.join(core.APP_ROOT, '.git')):
|
||||||
install_type = 'git'
|
install_type = 'git'
|
||||||
else:
|
else:
|
||||||
install_type = 'source'
|
install_type = 'source'
|
||||||
|
@ -61,13 +61,13 @@ class CheckVersion:
|
||||||
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
|
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
|
||||||
"""
|
"""
|
||||||
if not core.VERSION_NOTIFY and not force:
|
if not core.VERSION_NOTIFY and not force:
|
||||||
logger.log(u'Version checking is disabled, not checking for the newest version')
|
logger.log('Version checking is disabled, not checking for the newest version')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.log(u'Checking if {install} needs an update'.format(install=self.install_type))
|
logger.log('Checking if {install} needs an update'.format(install=self.install_type))
|
||||||
if not self.updater.need_update():
|
if not self.updater.need_update():
|
||||||
core.NEWEST_VERSION_STRING = None
|
core.NEWEST_VERSION_STRING = None
|
||||||
logger.log(u'No update needed')
|
logger.log('No update needed')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.updater.set_newest_text()
|
self.updater.set_newest_text()
|
||||||
|
@ -115,15 +115,15 @@ class GitUpdateManager(UpdateManager):
|
||||||
else:
|
else:
|
||||||
main_git = 'git'
|
main_git = 'git'
|
||||||
|
|
||||||
logger.log(u'Checking if we can use git commands: {git} {cmd}'.format
|
logger.log('Checking if we can use git commands: {git} {cmd}'.format
|
||||||
(git=main_git, cmd=test_cmd), logger.DEBUG)
|
(git=main_git, cmd=test_cmd), logger.DEBUG)
|
||||||
output, err, exit_status = self._run_git(main_git, test_cmd)
|
output, err, exit_status = self._run_git(main_git, test_cmd)
|
||||||
|
|
||||||
if exit_status == 0:
|
if exit_status == 0:
|
||||||
logger.log(u'Using: {git}'.format(git=main_git), logger.DEBUG)
|
logger.log('Using: {git}'.format(git=main_git), logger.DEBUG)
|
||||||
return main_git
|
return main_git
|
||||||
else:
|
else:
|
||||||
logger.log(u'Not using: {git}'.format(git=main_git), logger.DEBUG)
|
logger.log('Not using: {git}'.format(git=main_git), logger.DEBUG)
|
||||||
|
|
||||||
# trying alternatives
|
# trying alternatives
|
||||||
|
|
||||||
|
@ -138,18 +138,18 @@ class GitUpdateManager(UpdateManager):
|
||||||
alternative_git.append(main_git.lower())
|
alternative_git.append(main_git.lower())
|
||||||
|
|
||||||
if alternative_git:
|
if alternative_git:
|
||||||
logger.log(u'Trying known alternative git locations', logger.DEBUG)
|
logger.log('Trying known alternative git locations', logger.DEBUG)
|
||||||
|
|
||||||
for cur_git in alternative_git:
|
for cur_git in alternative_git:
|
||||||
logger.log(u'Checking if we can use git commands: {git} {cmd}'.format
|
logger.log('Checking if we can use git commands: {git} {cmd}'.format
|
||||||
(git=cur_git, cmd=test_cmd), logger.DEBUG)
|
(git=cur_git, cmd=test_cmd), logger.DEBUG)
|
||||||
output, err, exit_status = self._run_git(cur_git, test_cmd)
|
output, err, exit_status = self._run_git(cur_git, test_cmd)
|
||||||
|
|
||||||
if exit_status == 0:
|
if exit_status == 0:
|
||||||
logger.log(u'Using: {git}'.format(git=cur_git), logger.DEBUG)
|
logger.log('Using: {git}'.format(git=cur_git), logger.DEBUG)
|
||||||
return cur_git
|
return cur_git
|
||||||
else:
|
else:
|
||||||
logger.log(u'Not using: {git}'.format(git=cur_git), logger.DEBUG)
|
logger.log('Not using: {git}'.format(git=cur_git), logger.DEBUG)
|
||||||
|
|
||||||
# Still haven't found a working git
|
# Still haven't found a working git
|
||||||
logger.debug('Unable to find your git executable - '
|
logger.debug('Unable to find your git executable - '
|
||||||
|
@ -164,14 +164,14 @@ class GitUpdateManager(UpdateManager):
|
||||||
err = None
|
err = None
|
||||||
|
|
||||||
if not git_path:
|
if not git_path:
|
||||||
logger.log(u'No git specified, can\'t use git commands', logger.DEBUG)
|
logger.log('No git specified, can\'t use git commands', logger.DEBUG)
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
return output, err, exit_status
|
return output, err, exit_status
|
||||||
|
|
||||||
cmd = '{git} {args}'.format(git=git_path, args=args)
|
cmd = '{git} {args}'.format(git=git_path, args=args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.log(u'Executing {cmd} with your shell in {directory}'.format
|
logger.log('Executing {cmd} with your shell in {directory}'.format
|
||||||
(cmd=cmd, directory=core.APP_ROOT), logger.DEBUG)
|
(cmd=cmd, directory=core.APP_ROOT), logger.DEBUG)
|
||||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
shell=True, cwd=core.APP_ROOT)
|
shell=True, cwd=core.APP_ROOT)
|
||||||
|
@ -183,22 +183,22 @@ class GitUpdateManager(UpdateManager):
|
||||||
if output:
|
if output:
|
||||||
output = output.strip()
|
output = output.strip()
|
||||||
if core.LOG_GIT:
|
if core.LOG_GIT:
|
||||||
logger.log(u'git output: {output}'.format(output=output), logger.DEBUG)
|
logger.log('git output: {output}'.format(output=output), logger.DEBUG)
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.log(u'Command {cmd} didn\'t work'.format(cmd=cmd))
|
logger.log('Command {cmd} didn\'t work'.format(cmd=cmd))
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
|
|
||||||
exit_status = 128 if ('fatal:' in output) or err else exit_status
|
exit_status = 128 if ('fatal:' in output) or err else exit_status
|
||||||
if exit_status == 0:
|
if exit_status == 0:
|
||||||
logger.log(u'{cmd} : returned successful'.format(cmd=cmd), logger.DEBUG)
|
logger.log('{cmd} : returned successful'.format(cmd=cmd), logger.DEBUG)
|
||||||
exit_status = 0
|
exit_status = 0
|
||||||
elif core.LOG_GIT and exit_status in (1, 128):
|
elif core.LOG_GIT and exit_status in (1, 128):
|
||||||
logger.log(u'{cmd} returned : {output}'.format
|
logger.log('{cmd} returned : {output}'.format
|
||||||
(cmd=cmd, output=output), logger.DEBUG)
|
(cmd=cmd, output=output), logger.DEBUG)
|
||||||
else:
|
else:
|
||||||
if core.LOG_GIT:
|
if core.LOG_GIT:
|
||||||
logger.log(u'{cmd} returned : {output}, treat as error for now'.format
|
logger.log('{cmd} returned : {output}, treat as error for now'.format
|
||||||
(cmd=cmd, output=output), logger.DEBUG)
|
(cmd=cmd, output=output), logger.DEBUG)
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class GitUpdateManager(UpdateManager):
|
||||||
if exit_status == 0 and output:
|
if exit_status == 0 and output:
|
||||||
cur_commit_hash = output.strip()
|
cur_commit_hash = output.strip()
|
||||||
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
||||||
logger.log(u'Output doesn\'t look like a hash, not using it', logger.ERROR)
|
logger.log('Output doesn\'t look like a hash, not using it', logger.ERROR)
|
||||||
return False
|
return False
|
||||||
self._cur_commit_hash = cur_commit_hash
|
self._cur_commit_hash = cur_commit_hash
|
||||||
if self._cur_commit_hash:
|
if self._cur_commit_hash:
|
||||||
|
@ -252,7 +252,7 @@ class GitUpdateManager(UpdateManager):
|
||||||
output, err, exit_status = self._run_git(self._git_path, 'fetch origin')
|
output, err, exit_status = self._run_git(self._git_path, 'fetch origin')
|
||||||
|
|
||||||
if not exit_status == 0:
|
if not exit_status == 0:
|
||||||
logger.log(u'Unable to contact github, can\'t check for update', logger.ERROR)
|
logger.log('Unable to contact github, can\'t check for update', logger.ERROR)
|
||||||
return
|
return
|
||||||
|
|
||||||
# get latest commit_hash from remote
|
# get latest commit_hash from remote
|
||||||
|
@ -262,13 +262,13 @@ class GitUpdateManager(UpdateManager):
|
||||||
cur_commit_hash = output.strip()
|
cur_commit_hash = output.strip()
|
||||||
|
|
||||||
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
||||||
logger.log(u'Output doesn\'t look like a hash, not using it', logger.DEBUG)
|
logger.log('Output doesn\'t look like a hash, not using it', logger.DEBUG)
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._newest_commit_hash = cur_commit_hash
|
self._newest_commit_hash = cur_commit_hash
|
||||||
else:
|
else:
|
||||||
logger.log(u'git didn\'t return newest commit hash', logger.DEBUG)
|
logger.log('git didn\'t return newest commit hash', logger.DEBUG)
|
||||||
return
|
return
|
||||||
|
|
||||||
# get number of commits behind and ahead (option --count not supported git < 1.7.2)
|
# get number of commits behind and ahead (option --count not supported git < 1.7.2)
|
||||||
|
@ -281,21 +281,21 @@ class GitUpdateManager(UpdateManager):
|
||||||
self._num_commits_ahead = int(output.count('>'))
|
self._num_commits_ahead = int(output.count('>'))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(u'git didn\'t return numbers for behind and ahead, not using it', logger.DEBUG)
|
logger.log('git didn\'t return numbers for behind and ahead, not using it', logger.DEBUG)
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.log(u'cur_commit = {current} % (newest_commit)= {new}, '
|
logger.log('cur_commit = {current} % (newest_commit)= {new}, '
|
||||||
u'num_commits_behind = {x}, num_commits_ahead = {y}'.format
|
'num_commits_behind = {x}, num_commits_ahead = {y}'.format
|
||||||
(current=self._cur_commit_hash, new=self._newest_commit_hash,
|
(current=self._cur_commit_hash, new=self._newest_commit_hash,
|
||||||
x=self._num_commits_behind, y=self._num_commits_ahead), logger.DEBUG)
|
x=self._num_commits_behind, y=self._num_commits_ahead), logger.DEBUG)
|
||||||
|
|
||||||
def set_newest_text(self):
|
def set_newest_text(self):
|
||||||
if self._num_commits_ahead:
|
if self._num_commits_ahead:
|
||||||
logger.log(u'Local branch is ahead of {branch}. Automatic update not possible.'.format
|
logger.log('Local branch is ahead of {branch}. Automatic update not possible.'.format
|
||||||
(branch=self.branch), logger.ERROR)
|
(branch=self.branch), logger.ERROR)
|
||||||
elif self._num_commits_behind:
|
elif self._num_commits_behind:
|
||||||
logger.log(u'There is a newer version available (you\'re {x} commit{s} behind)'.format
|
logger.log('There is a newer version available (you\'re {x} commit{s} behind)'.format
|
||||||
(x=self._num_commits_behind, s=u's' if self._num_commits_behind > 1 else u''), logger.MESSAGE)
|
(x=self._num_commits_behind, s='s' if self._num_commits_behind > 1 else ''), logger.MESSAGE)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ class GitUpdateManager(UpdateManager):
|
||||||
try:
|
try:
|
||||||
self._check_github_for_update()
|
self._check_github_for_update()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.log(u'Unable to contact github, can\'t check for update: {msg!r}'.format(msg=error), logger.ERROR)
|
logger.log('Unable to contact github, can\'t check for update: {msg!r}'.format(msg=error), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self._num_commits_behind > 0:
|
if self._num_commits_behind > 0:
|
||||||
|
@ -345,7 +345,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
|
|
||||||
def _find_installed_version(self):
|
def _find_installed_version(self):
|
||||||
|
|
||||||
version_file = os.path.join(core.APP_ROOT, u'version.txt')
|
version_file = os.path.join(core.APP_ROOT, 'version.txt')
|
||||||
|
|
||||||
if not os.path.isfile(version_file):
|
if not os.path.isfile(version_file):
|
||||||
self._cur_commit_hash = None
|
self._cur_commit_hash = None
|
||||||
|
@ -355,7 +355,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
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 as error:
|
except EnvironmentError as error:
|
||||||
logger.log(u'Unable to open \'version.txt\': {msg}'.format(msg=error), logger.DEBUG)
|
logger.log('Unable to open \'version.txt\': {msg}'.format(msg=error), logger.DEBUG)
|
||||||
|
|
||||||
if not self._cur_commit_hash:
|
if not self._cur_commit_hash:
|
||||||
self._cur_commit_hash = None
|
self._cur_commit_hash = None
|
||||||
|
@ -369,7 +369,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
try:
|
try:
|
||||||
self._check_github_for_update()
|
self._check_github_for_update()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.log(u'Unable to contact github, can\'t check for update: {msg!r}'.format(msg=error), logger.ERROR)
|
logger.log('Unable to contact github, can\'t check for update: {msg!r}'.format(msg=error), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not self._cur_commit_hash or self._num_commits_behind > 0:
|
if not self._cur_commit_hash or self._num_commits_behind > 0:
|
||||||
|
@ -417,7 +417,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
# when _cur_commit_hash doesn't match anything _num_commits_behind == 100
|
# when _cur_commit_hash doesn't match anything _num_commits_behind == 100
|
||||||
self._num_commits_behind += 1
|
self._num_commits_behind += 1
|
||||||
|
|
||||||
logger.log(u'cur_commit = {current} % (newest_commit)= {new}, num_commits_behind = {x}'.format
|
logger.log('cur_commit = {current} % (newest_commit)= {new}, num_commits_behind = {x}'.format
|
||||||
(current=self._cur_commit_hash, new=self._newest_commit_hash, x=self._num_commits_behind), logger.DEBUG)
|
(current=self._cur_commit_hash, new=self._newest_commit_hash, x=self._num_commits_behind), logger.DEBUG)
|
||||||
|
|
||||||
def set_newest_text(self):
|
def set_newest_text(self):
|
||||||
|
@ -426,10 +426,10 @@ class SourceUpdateManager(UpdateManager):
|
||||||
core.NEWEST_VERSION_STRING = None
|
core.NEWEST_VERSION_STRING = None
|
||||||
|
|
||||||
if not self._cur_commit_hash:
|
if not self._cur_commit_hash:
|
||||||
logger.log(u'Unknown current version number, don\'t know if we should update or not', logger.ERROR)
|
logger.log('Unknown current version number, don\'t know if we should update or not', logger.ERROR)
|
||||||
elif self._num_commits_behind > 0:
|
elif self._num_commits_behind > 0:
|
||||||
logger.log(u'There is a newer version available (you\'re {x} commit{s} behind)'.format
|
logger.log('There is a newer version available (you\'re {x} commit{s} behind)'.format
|
||||||
(x=self._num_commits_behind, s=u's' if self._num_commits_behind > 1 else u''), logger.MESSAGE)
|
(x=self._num_commits_behind, s='s' if self._num_commits_behind > 1 else ''), logger.MESSAGE)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -437,54 +437,54 @@ class SourceUpdateManager(UpdateManager):
|
||||||
"""Download and install latest source tarball from github."""
|
"""Download and install latest source tarball from github."""
|
||||||
tar_download_url = 'https://github.com/{org}/{repo}/tarball/{branch}'.format(
|
tar_download_url = 'https://github.com/{org}/{repo}/tarball/{branch}'.format(
|
||||||
org=self.github_repo_user, repo=self.github_repo, branch=self.branch)
|
org=self.github_repo_user, repo=self.github_repo, branch=self.branch)
|
||||||
version_path = os.path.join(core.APP_ROOT, u'version.txt')
|
version_path = os.path.join(core.APP_ROOT, 'version.txt')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# prepare the update dir
|
# prepare the update dir
|
||||||
sb_update_dir = os.path.join(core.APP_ROOT, u'sb-update')
|
sb_update_dir = os.path.join(core.APP_ROOT, 'sb-update')
|
||||||
|
|
||||||
if os.path.isdir(sb_update_dir):
|
if os.path.isdir(sb_update_dir):
|
||||||
logger.log(u'Clearing out update folder {dir} before extracting'.format(dir=sb_update_dir))
|
logger.log('Clearing out update folder {dir} before extracting'.format(dir=sb_update_dir))
|
||||||
shutil.rmtree(sb_update_dir)
|
shutil.rmtree(sb_update_dir)
|
||||||
|
|
||||||
logger.log(u'Creating update folder {dir} before extracting'.format(dir=sb_update_dir))
|
logger.log('Creating update folder {dir} before extracting'.format(dir=sb_update_dir))
|
||||||
os.makedirs(sb_update_dir)
|
os.makedirs(sb_update_dir)
|
||||||
|
|
||||||
# retrieve file
|
# retrieve file
|
||||||
logger.log(u'Downloading update from {url!r}'.format(url=tar_download_url))
|
logger.log('Downloading update from {url!r}'.format(url=tar_download_url))
|
||||||
tar_download_path = os.path.join(sb_update_dir, u'nzbtomedia-update.tar')
|
tar_download_path = os.path.join(sb_update_dir, 'nzbtomedia-update.tar')
|
||||||
urlretrieve(tar_download_url, tar_download_path)
|
urlretrieve(tar_download_url, tar_download_path)
|
||||||
|
|
||||||
if not os.path.isfile(tar_download_path):
|
if not os.path.isfile(tar_download_path):
|
||||||
logger.log(u'Unable to retrieve new version from {url}, can\'t update'.format
|
logger.log('Unable to retrieve new version from {url}, can\'t update'.format
|
||||||
(url=tar_download_url), logger.ERROR)
|
(url=tar_download_url), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not tarfile.is_tarfile(tar_download_path):
|
if not tarfile.is_tarfile(tar_download_path):
|
||||||
logger.log(u'Retrieved version from {url} is corrupt, can\'t update'.format
|
logger.log('Retrieved version from {url} is corrupt, can\'t update'.format
|
||||||
(url=tar_download_url), logger.ERROR)
|
(url=tar_download_url), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# extract to sb-update dir
|
# extract to sb-update dir
|
||||||
logger.log(u'Extracting file {path}'.format(path=tar_download_path))
|
logger.log('Extracting file {path}'.format(path=tar_download_path))
|
||||||
tar = tarfile.open(tar_download_path)
|
tar = tarfile.open(tar_download_path)
|
||||||
tar.extractall(sb_update_dir)
|
tar.extractall(sb_update_dir)
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
# delete .tar.gz
|
# delete .tar.gz
|
||||||
logger.log(u'Deleting file {path}'.format(path=tar_download_path))
|
logger.log('Deleting file {path}'.format(path=tar_download_path))
|
||||||
os.remove(tar_download_path)
|
os.remove(tar_download_path)
|
||||||
|
|
||||||
# find update dir name
|
# find update dir name
|
||||||
update_dir_contents = [x for x in os.listdir(sb_update_dir) if
|
update_dir_contents = [x for x in os.listdir(sb_update_dir) if
|
||||||
os.path.isdir(os.path.join(sb_update_dir, x))]
|
os.path.isdir(os.path.join(sb_update_dir, x))]
|
||||||
if len(update_dir_contents) != 1:
|
if len(update_dir_contents) != 1:
|
||||||
logger.log(u'Invalid update data, update failed: {0}'.format(update_dir_contents), logger.ERROR)
|
logger.log('Invalid update data, update failed: {0}'.format(update_dir_contents), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
content_dir = os.path.join(sb_update_dir, update_dir_contents[0])
|
content_dir = os.path.join(sb_update_dir, update_dir_contents[0])
|
||||||
|
|
||||||
# walk temp folder and move files to main folder
|
# walk temp folder and move files to main folder
|
||||||
logger.log(u'Moving files from {source} to {destination}'.format
|
logger.log('Moving files from {source} to {destination}'.format
|
||||||
(source=content_dir, destination=core.APP_ROOT))
|
(source=content_dir, destination=core.APP_ROOT))
|
||||||
for dirname, _, filenames in os.walk(content_dir): # @UnusedVariable
|
for dirname, _, filenames in os.walk(content_dir): # @UnusedVariable
|
||||||
dirname = dirname[len(content_dir) + 1:]
|
dirname = dirname[len(content_dir) + 1:]
|
||||||
|
@ -501,7 +501,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
os.remove(new_path)
|
os.remove(new_path)
|
||||||
os.renames(old_path, new_path)
|
os.renames(old_path, new_path)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.log(u'Unable to update {path}: {msg}'.format
|
logger.log('Unable to update {path}: {msg}'.format
|
||||||
(path=new_path, msg=error), logger.DEBUG)
|
(path=new_path, msg=error), 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
|
||||||
|
@ -515,14 +515,14 @@ class SourceUpdateManager(UpdateManager):
|
||||||
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 as error:
|
except EnvironmentError as error:
|
||||||
logger.log(u'Unable to write version file, update not complete: {msg}'.format
|
logger.log('Unable to write version file, update not complete: {msg}'.format
|
||||||
(msg=error), logger.ERROR)
|
(msg=error), logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.log(u'Error while trying to update: {msg}'.format
|
logger.log('Error while trying to update: {msg}'.format
|
||||||
(msg=error), logger.ERROR)
|
(msg=error), logger.ERROR)
|
||||||
logger.log(u'Traceback: {error}'.format(error=traceback.format_exc()), logger.DEBUG)
|
logger.log('Traceback: {error}'.format(error=traceback.format_exc()), logger.DEBUG)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue