|
|
@ -48,7 +48,7 @@ def run_git(args):
|
|
|
|
cmd = cur_git + ' ' + args
|
|
|
|
cmd = cur_git + ' ' + args
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
logging.debug('Trying to execute: "' + cmd + '"')
|
|
|
|
logging.debug('BAZZAR Trying to execute: "' + cmd + '"')
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
|
output, err = p.communicate()
|
|
|
|
output, err = p.communicate()
|
|
|
|
output = output.strip()
|
|
|
|
output = output.strip()
|
|
|
@ -72,8 +72,9 @@ def run_git(args):
|
|
|
|
|
|
|
|
|
|
|
|
def check_updates():
|
|
|
|
def check_updates():
|
|
|
|
commits_behind = 0
|
|
|
|
commits_behind = 0
|
|
|
|
current_version = get_version()
|
|
|
|
current_version, source = get_version()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if source == 'git':
|
|
|
|
# Get the latest version available from github
|
|
|
|
# Get the latest version available from github
|
|
|
|
logging.info('BAZZAR Retrieving latest version information from GitHub')
|
|
|
|
logging.info('BAZZAR Retrieving latest version information from GitHub')
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/commits/%s' % settings.general.branch
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/commits/%s' % settings.general.branch
|
|
|
@ -81,20 +82,22 @@ def check_updates():
|
|
|
|
|
|
|
|
|
|
|
|
if version is None:
|
|
|
|
if version is None:
|
|
|
|
logging.warn(
|
|
|
|
logging.warn(
|
|
|
|
'BAZZAR Could not get the latest version from GitHub. Are you running a local development version?')
|
|
|
|
'BAZZAR Could not get the latest version from GitHub.')
|
|
|
|
return current_version
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
latest_version = version['sha']
|
|
|
|
latest_version = version['sha']
|
|
|
|
logging.debug("BAZZAR Latest version is %s", latest_version)
|
|
|
|
logging.debug("BAZZAR Latest version is %s", latest_version)
|
|
|
|
|
|
|
|
|
|
|
|
# See how many commits behind we are
|
|
|
|
# See how many commits behind we are
|
|
|
|
if not current_version:
|
|
|
|
if not current_version:
|
|
|
|
logging.info('BAZARR You are running an unknown version of Bazarr. Run the updater to identify your version')
|
|
|
|
logging.info(
|
|
|
|
return latest_version
|
|
|
|
'BAZARR You are running an unknown version of Bazarr. Run the updater to identify your version')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if latest_version == current_version:
|
|
|
|
if latest_version == current_version:
|
|
|
|
|
|
|
|
notifications.write(msg='BAZARR is up to date', queue='check_update')
|
|
|
|
logging.info('BAZARR is up to date')
|
|
|
|
logging.info('BAZARR is up to date')
|
|
|
|
return latest_version
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
logging.info('Comparing currently installed version with latest GitHub version')
|
|
|
|
logging.info('Comparing currently installed version with latest GitHub version')
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/compare/%s...%s' % (latest_version,
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/compare/%s...%s' % (latest_version,
|
|
|
@ -103,43 +106,44 @@ def check_updates():
|
|
|
|
|
|
|
|
|
|
|
|
if commits is None:
|
|
|
|
if commits is None:
|
|
|
|
logging.warn('BAZARR Could not get commits behind from GitHub.')
|
|
|
|
logging.warn('BAZARR Could not get commits behind from GitHub.')
|
|
|
|
return latest_version
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
commits_behind = int(commits['behind_by'])
|
|
|
|
commits_behind = int(commits['behind_by'])
|
|
|
|
logging.debug("In total, %d commits behind", commits_behind)
|
|
|
|
logging.debug("BAZARR In total, %d commits behind", commits_behind)
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
|
logging.info('BAZARR Cannot compare versions. Are you running a local development version?')
|
|
|
|
logging.info('BAZARR Cannot compare versions. Are you running a local development version?')
|
|
|
|
commits_behind = 0
|
|
|
|
commits_behind = 0
|
|
|
|
|
|
|
|
|
|
|
|
if commits_behind > 0:
|
|
|
|
if commits_behind > 0:
|
|
|
|
logging.info('BAZARR New version is available. You are %s commits behind' % commits_behind)
|
|
|
|
logging.info('BAZARR New version is available. You are %s commits behind' % commits_behind)
|
|
|
|
if settings.general.auto_update:
|
|
|
|
notifications.write(msg='BAZARR New version is available. You are %s commits behind' % commits_behind,
|
|
|
|
update()
|
|
|
|
queue='check_update')
|
|
|
|
else:
|
|
|
|
update(source, restart=True if settings.general.getboolean('update_restart') else False)
|
|
|
|
updated(restart=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/releases'
|
|
|
|
url = 'https://api.github.com/repos/morpheus65535/bazarr/releases'
|
|
|
|
releases = request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == list)
|
|
|
|
releases = request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == list)
|
|
|
|
|
|
|
|
|
|
|
|
if releases is None:
|
|
|
|
if releases is None:
|
|
|
|
logging.warn('BAZARR Could not get releases from GitHub.')
|
|
|
|
logging.warn('BAZARR Could not get releases from GitHub.')
|
|
|
|
return latest_version
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
release = releases[0]
|
|
|
|
release = releases[0]
|
|
|
|
latest_release = release['tag_name']
|
|
|
|
latest_release = release['tag_name']
|
|
|
|
|
|
|
|
|
|
|
|
if ('v' + current_version) != latest_release and args.release_update and settings.general.branch == 'master':
|
|
|
|
if ('v' + current_version) != latest_release and settings.general.branch == 'master':
|
|
|
|
update()
|
|
|
|
update(source, restart=True if settings.general.getboolean('update_restart') else False)
|
|
|
|
|
|
|
|
elif settings.general.branch != 'master':
|
|
|
|
elif commits_behind == 0:
|
|
|
|
notifications.write(msg="BAZZAR Can't update development branch from source", queue='check_update') # fixme
|
|
|
|
|
|
|
|
logging.info("BAZZAR Can't update development branch from source") # fixme
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
notifications.write(msg='BAZZAR is up to date', queue='check_update')
|
|
|
|
logging.info('BAZZAR is up to date')
|
|
|
|
logging.info('BAZZAR is up to date')
|
|
|
|
|
|
|
|
|
|
|
|
return latest_version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_version():
|
|
|
|
def get_version():
|
|
|
|
if os.path.isdir(os.path.join(os.path.dirname(__file__), '..', '.git')):
|
|
|
|
if os.path.isdir(os.path.join(os.path.dirname(__file__), '..', '.git')) and not args.release_update:
|
|
|
|
|
|
|
|
|
|
|
|
output, err = run_git('rev-parse HEAD')
|
|
|
|
output, err = run_git('rev-parse HEAD')
|
|
|
|
|
|
|
|
|
|
|
@ -153,14 +157,14 @@ def get_version():
|
|
|
|
logging.error('BAZZAR Output does not look like a hash, not using it.')
|
|
|
|
logging.error('BAZZAR Output does not look like a hash, not using it.')
|
|
|
|
cur_commit_hash = None
|
|
|
|
cur_commit_hash = None
|
|
|
|
|
|
|
|
|
|
|
|
return cur_commit_hash
|
|
|
|
return cur_commit_hash, 'git'
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return os.environ["BAZARR_VERSION"]
|
|
|
|
return os.environ["BAZARR_VERSION"], 'source'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update():
|
|
|
|
def update(source, restart=True):
|
|
|
|
if not args.release_update:
|
|
|
|
if source == 'git':
|
|
|
|
output, err = run_git('pull ' + 'origin' + ' ' + settings.general.branch)
|
|
|
|
output, err = run_git('pull ' + 'origin' + ' ' + settings.general.branch)
|
|
|
|
|
|
|
|
|
|
|
|
if not output:
|
|
|
|
if not output:
|
|
|
@ -175,16 +179,19 @@ def update():
|
|
|
|
elif line.endswith(('Aborting', 'Aborting.')):
|
|
|
|
elif line.endswith(('Aborting', 'Aborting.')):
|
|
|
|
logging.error('BAZZAR Unable to update from git: ' + line)
|
|
|
|
logging.error('BAZZAR Unable to update from git: ' + line)
|
|
|
|
logging.info('BAZZAR Output: ' + str(output))
|
|
|
|
logging.info('BAZZAR Output: ' + str(output))
|
|
|
|
updated(restart=True)
|
|
|
|
updated(restart)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
tar_download_url = 'https://github.com/morpheus65535/bazarr/tarball/{}'.format(settings.general.branch)
|
|
|
|
tar_download_url = 'https://github.com/morpheus65535/bazarr/tarball/{}'.format(settings.general.branch)
|
|
|
|
update_dir = os.path.join(os.path.dirname(__file__), '..', 'update')
|
|
|
|
update_dir = os.path.join(os.path.dirname(__file__), '..', 'update')
|
|
|
|
|
|
|
|
|
|
|
|
logging.info('BAZZAR Downloading update from: ' + tar_download_url)
|
|
|
|
logging.info('BAZZAR Downloading update from: ' + tar_download_url)
|
|
|
|
|
|
|
|
notifications.write(msg='BAZZAR Downloading update from: ' + tar_download_url)
|
|
|
|
data = request_content(tar_download_url)
|
|
|
|
data = request_content(tar_download_url)
|
|
|
|
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
if not data:
|
|
|
|
logging.error("BAZZAR Unable to retrieve new version from '%s', can't update", tar_download_url)
|
|
|
|
logging.error("BAZZAR Unable to retrieve new version from '%s', can't update", tar_download_url)
|
|
|
|
|
|
|
|
notifications.write(msg=("BAZZAR Unable to retrieve new version from '%s', can't update", tar_download_url),
|
|
|
|
|
|
|
|
type='error')
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
download_name = settings.general.branch + '-github'
|
|
|
|
download_name = settings.general.branch + '-github'
|
|
|
@ -196,19 +203,24 @@ def update():
|
|
|
|
|
|
|
|
|
|
|
|
# Extract the tar to update folder
|
|
|
|
# Extract the tar to update folder
|
|
|
|
logging.info('BAZZAR Extracting file: ' + tar_download_path)
|
|
|
|
logging.info('BAZZAR Extracting file: ' + tar_download_path)
|
|
|
|
|
|
|
|
notifications.write(msg='BAZZAR Extracting file: ' + tar_download_path)
|
|
|
|
tar = tarfile.open(tar_download_path)
|
|
|
|
tar = tarfile.open(tar_download_path)
|
|
|
|
tar.extractall(update_dir)
|
|
|
|
tar.extractall(update_dir)
|
|
|
|
tar.close()
|
|
|
|
tar.close()
|
|
|
|
|
|
|
|
|
|
|
|
# Delete the tar.gz
|
|
|
|
# Delete the tar.gz
|
|
|
|
logging.info('BAZZAR Deleting file: ' + tar_download_path)
|
|
|
|
logging.info('BAZZAR Deleting file: ' + tar_download_path)
|
|
|
|
|
|
|
|
notifications.write(msg='BAZZAR Deleting file: ' + 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(update_dir) if os.path.isdir(os.path.join(update_dir, x))]
|
|
|
|
update_dir_contents = [x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x))]
|
|
|
|
if len(update_dir_contents) != 1:
|
|
|
|
if len(update_dir_contents) != 1:
|
|
|
|
logging.error("BAZZAR Invalid update data, update failed: " + str(update_dir_contents))
|
|
|
|
logging.error("BAZZAR Invalid update data, update failed: " + str(update_dir_contents))
|
|
|
|
|
|
|
|
notifications.write(msg="BAZZAR Invalid update data, update failed: " + str(update_dir_contents),
|
|
|
|
|
|
|
|
type='error')
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
content_dir = os.path.join(update_dir, update_dir_contents[0])
|
|
|
|
content_dir = os.path.join(update_dir, update_dir_contents[0])
|
|
|
|
|
|
|
|
|
|
|
|
# walk temp folder and move files to main folder
|
|
|
|
# walk temp folder and move files to main folder
|
|
|
@ -221,7 +233,7 @@ def update():
|
|
|
|
if os.path.isfile(new_path):
|
|
|
|
if os.path.isfile(new_path):
|
|
|
|
os.remove(new_path)
|
|
|
|
os.remove(new_path)
|
|
|
|
os.renames(old_path, new_path)
|
|
|
|
os.renames(old_path, new_path)
|
|
|
|
updated(restart=True)
|
|
|
|
updated(restart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FakeLock(object):
|
|
|
|
class FakeLock(object):
|
|
|
|