Switching from pygit2 to gitpython

This commit is contained in:
morpheus65535 2017-12-30 00:09:51 -05:00
parent ee3e064d8d
commit 80c1b44781
5 changed files with 20 additions and 50 deletions

View File

@ -8,9 +8,7 @@ EXPOSE 6767
VOLUME /tv VOLUME /tv
RUN apt-get update && \ 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 && \ apt-get install -y python-dev python-pip python-setuptools libjpeg-dev zlib1g-dev git 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" && \
pip install -r /bazarr/requirements.txt pip install -r /bazarr/requirements.txt
VOLUME /bazarr/data VOLUME /bazarr/data

View File

@ -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 from bottle import route, run, template, static_file, request, redirect, response
import bottle import bottle
@ -24,6 +24,7 @@ import math
from init_db import * from init_db import *
import update_db import update_db
import update_modules
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
c = conn.cursor() c = conn.cursor()

View File

@ -1,56 +1,21 @@
from get_general_settings import * from get_general_settings import *
import os import os
import pygit2
import logging import logging
import sqlite3 import sqlite3
import git
current_working_directory = os.path.dirname(__file__) 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'): def check_and_apply_update():
repo.config['remote.origin.fetch'] = '+refs/heads/*:refs/remotes/origin/*' g = git.cmd.Git(current_working_directory)
repo.remotes[remote_name].fetch() result = g.pull('origin', branch)
repo.config['user.name'] = 'Bazarr user' if result != 'Already up-to-date.':
repo.config['user.email'] ='bazarr@fakeuser.com' logging.info('Bazarr updated to latest version and need to be restarted.')
updated()
for remote in repo.remotes: else:
if remote.name == remote_name: logging.info('No new version of Bazarr available.')
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
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 updated(): def updated():
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)

View File

@ -4,10 +4,10 @@ bottle
bottle-fdsend bottle-fdsend
dogpile.cache dogpile.cache
enzyme enzyme
gitpython
Pillow Pillow
py-pretty py-pretty
pycountry pycountry
pygit2
requests requests
subliminal subliminal
urllib3 urllib3

6
update_modules.py Normal file
View File

@ -0,0 +1,6 @@
import pip
try:
pip.main(['install', '--user', 'gitpython'])
except SystemExit as e:
pass