2018-08-16 10:01:49 +08:00
|
|
|
from get_argv import config_dir
|
|
|
|
|
2018-08-16 04:51:46 +08:00
|
|
|
from get_general_settings import get_general_settings
|
2017-10-28 10:18:16 +08:00
|
|
|
|
2017-11-07 12:53:31 +08:00
|
|
|
import os
|
2017-12-06 12:07:37 +08:00
|
|
|
import logging
|
2017-12-23 11:40:14 +08:00
|
|
|
import sqlite3
|
2017-11-07 12:53:31 +08:00
|
|
|
|
2017-12-30 13:09:51 +08:00
|
|
|
import git
|
2017-12-06 04:02:08 +08:00
|
|
|
|
2017-12-30 13:09:51 +08:00
|
|
|
current_working_directory = os.path.dirname(__file__)
|
2017-11-22 05:09:33 +08:00
|
|
|
|
2018-01-16 12:00:29 +08:00
|
|
|
def gitconfig():
|
|
|
|
g = git.Repo.init(current_working_directory)
|
|
|
|
config_read = g.config_reader()
|
|
|
|
config_write = g.config_writer()
|
|
|
|
|
|
|
|
try:
|
|
|
|
username = config_read.get_value("user", "name")
|
|
|
|
except:
|
|
|
|
config_write.set_value("user", "name", "Bazarr")
|
|
|
|
|
|
|
|
try:
|
|
|
|
email = config_read.get_value("user", "email")
|
|
|
|
except:
|
|
|
|
config_write.set_value("user", "email", "bazarr@fake.email")
|
|
|
|
|
2017-12-30 13:09:51 +08:00
|
|
|
def check_and_apply_update():
|
2018-01-16 12:00:29 +08:00
|
|
|
gitconfig()
|
2018-06-05 11:36:41 +08:00
|
|
|
branch = get_general_settings()[5]
|
2017-12-30 13:09:51 +08:00
|
|
|
g = git.cmd.Git(current_working_directory)
|
2018-06-05 11:56:22 +08:00
|
|
|
g.fetch('origin')
|
2018-06-05 11:25:07 +08:00
|
|
|
result = g.diff('--shortstat', 'origin/' + branch)
|
|
|
|
if len(result) == 0:
|
2017-12-30 21:33:36 +08:00
|
|
|
logging.info('No new version of Bazarr available.')
|
|
|
|
else:
|
2018-06-05 11:50:23 +08:00
|
|
|
g.reset('--hard', 'HEAD')
|
|
|
|
g.checkout(branch)
|
|
|
|
g.reset('--hard','origin/' + branch)
|
2018-06-05 11:28:16 +08:00
|
|
|
g.pull()
|
2018-06-05 11:25:07 +08:00
|
|
|
logging.info('Bazarr updated to latest version and need to be restarted. ' + result)
|
|
|
|
updated()
|
2017-12-23 11:40:14 +08:00
|
|
|
|
|
|
|
def updated():
|
2018-08-16 10:01:49 +08:00
|
|
|
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2017-12-23 11:40:14 +08:00
|
|
|
c = conn.cursor()
|
|
|
|
c.execute("UPDATE table_settings_general SET updated = 1")
|
|
|
|
conn.commit()
|
|
|
|
c.close()
|