From 80c1b44781ae4d006800cc0978c84a2204a976d5 Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 30 Dec 2017 00:09:51 -0500 Subject: [PATCH] Switching from pygit2 to gitpython --- Dockerfile | 4 +--- bazarr.py | 3 ++- check_update.py | 55 +++++++++-------------------------------------- requirements.txt | 2 +- update_modules.py | 6 ++++++ 5 files changed, 20 insertions(+), 50 deletions(-) create mode 100644 update_modules.py diff --git a/Dockerfile b/Dockerfile index 39c09994f..ffc2638b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,7 @@ EXPOSE 6767 VOLUME /tv RUN apt-get update && \ - apt-get install -y build-essential python-dev python-pip python-setuptools libjpeg-dev zlib1g-dev git libgit2-dev libffi-dev && \ - git clone -b master --single-branch https://github.com/morpheus65535/bazarr.git /bazarr && \ - git config --global user.name "Bazarr" && git config --global user.email "bazarr@fake.email" && \ + apt-get install -y python-dev python-pip python-setuptools libjpeg-dev zlib1g-dev git libffi-dev && \ pip install -r /bazarr/requirements.txt VOLUME /bazarr/data diff --git a/bazarr.py b/bazarr.py index c639e1438..d33d491d3 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.2.2' +bazarr_version = '0.2.3' from bottle import route, run, template, static_file, request, redirect, response import bottle @@ -24,6 +24,7 @@ import math from init_db import * import update_db +import update_modules conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = conn.cursor() diff --git a/check_update.py b/check_update.py index 123691dd6..1ab7299bf 100644 --- a/check_update.py +++ b/check_update.py @@ -1,56 +1,21 @@ from get_general_settings import * import os -import pygit2 import logging import sqlite3 -current_working_directory = os.path.dirname(__file__) -repository_path = pygit2.discover_repository(current_working_directory) -local_repo = pygit2.Repository(repository_path) - -def check_and_apply_update(repo=local_repo, remote_name='origin'): - repo.config['remote.origin.fetch'] = '+refs/heads/*:refs/remotes/origin/*' - repo.remotes[remote_name].fetch() - repo.config['user.name'] = 'Bazarr user' - repo.config['user.email'] ='bazarr@fakeuser.com' +import git - for remote in repo.remotes: - if remote.name == remote_name: - remote.fetch() - remote_id = repo.lookup_reference('refs/remotes/origin/' + str(branch)).target - merge_result, _ = repo.merge_analysis(remote_id) - # Up to date, do nothing - if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE: - logging.info('No new version of Bazarr available.') - pass - # 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/remotes/origin/' + str(branch)) - master_ref.set_target(remote_id) - repo.head.set_target(remote_id) - logging.info('Bazarr updated to latest version and need to be restarted.') - updated() - # We can just do it normally - elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: - repo.merge(remote_id) - print repo.index.conflicts +current_working_directory = os.path.dirname(__file__) - assert repo.index.conflicts is None, 'Conflicts, ahhhh!' - user = repo.default_signature - tree = repo.index.write_tree() - commit = repo.create_commit('HEAD', - user, - user, - 'Merge!', - tree, - [repo.head.target, remote_id]) - repo.state_cleanup() - logging.error('Conflict detected when trying to update.') - # We can't do it - else: - logging.error('Bazarr cannot be updated: Unknown merge analysis result') +def check_and_apply_update(): + g = git.cmd.Git(current_working_directory) + result = g.pull('origin', branch) + if result != 'Already up-to-date.': + logging.info('Bazarr updated to latest version and need to be restarted.') + updated() + else: + logging.info('No new version of Bazarr available.') def updated(): conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) diff --git a/requirements.txt b/requirements.txt index 4147c9e29..dc15cd1e0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,10 @@ bottle bottle-fdsend dogpile.cache enzyme +gitpython Pillow py-pretty pycountry -pygit2 requests subliminal urllib3 diff --git a/update_modules.py b/update_modules.py new file mode 100644 index 000000000..1d507e179 --- /dev/null +++ b/update_modules.py @@ -0,0 +1,6 @@ +import pip + +try: + pip.main(['install', '--user', 'gitpython']) +except SystemExit as e: + pass \ No newline at end of file