bazarr/check_update.py

32 lines
1.3 KiB
Python
Raw Normal View History

2017-10-28 02:18:16 +00:00
from get_general_settings import *
2017-11-07 04:53:31 +00:00
import os
2017-11-11 05:54:19 +00:00
import pygit2
2017-11-07 04:53:31 +00:00
2017-11-14 14:38:34 +00:00
current_working_directory = os.path.dirname(__file__)
2017-11-11 05:54:19 +00:00
repository_path = pygit2.discover_repository(current_working_directory)
local_repo = pygit2.Repository(repository_path)
2017-11-07 05:11:42 +00:00
2017-11-11 05:54:19 +00:00
def check_and_apply_update(repo=local_repo, remote_name='origin'):
for remote in repo.remotes:
if remote.name == remote_name:
remote.fetch()
remote_id = repo.lookup_reference('refs/remotes/origin/' + branch).target
merge_result, _ = repo.merge_analysis(remote_id)
# Up to date, do nothing
if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE:
2017-11-15 01:20:44 +00:00
result = 'No new version of Bazarr available.'
pass
2017-11-11 05:54:19 +00:00
# We can just fastforward
elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD:
repo.checkout_tree(repo.get(remote_id))
master_ref = repo.lookup_reference('refs/heads/master')
master_ref.set_target(remote_id)
repo.head.set_target(remote_id)
2017-11-15 01:20:44 +00:00
result = 'Bazarr updated to latest version.'
os.execlp('python', 'python', os.path.join(os.path.dirname(__file__), 'bazarr.py'))
2017-11-11 05:54:19 +00:00
else:
raise AssertionError('Unknown merge analysis result')
2017-11-15 01:20:44 +00:00
return result