1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-22 15:52:47 +00:00

FIX: Changed where version checking would run in startup sequence - is now after the web interface loads so that it will not loop forever in some instances trying to check git but an instance of Mylar is already running, FIX: Added more verbose error logging when checking versions fails

This commit is contained in:
evilhero 2018-04-16 13:59:17 -04:00
parent 0fdb551365
commit 6a2b12313e
3 changed files with 66 additions and 57 deletions

View file

@ -307,7 +307,9 @@ def main():
# Try to start the server.
webstart.initialize(web_config)
#logger.info('Starting Mylar on port: %i' % http_port)
#check for version here after web server initialized so it doesn't try to repeatidly hit github
#for version info if it's already running
versioncheck.versionload()
if mylar.CONFIG.LAUNCH_BROWSER and not args.nolaunch:
mylar.launch_browser(mylar.CONFIG.HTTP_HOST, http_port, mylar.CONFIG.HTTP_ROOT)

View file

@ -171,23 +171,6 @@ def initialize(config_file):
if _INITIALIZED:
return False
# Also sets INSTALL_TYPE variable to 'win', 'git' or 'source'
CURRENT_VERSION, CONFIG.GIT_BRANCH = versioncheck.getVersion()
#versioncheck.getVersion()
#config_write()
if CURRENT_VERSION is not None:
hash = CURRENT_VERSION[:7]
else:
hash = "unknown"
if CONFIG.GIT_BRANCH == 'master':
vers = 'M'
elif CONFIG.GIT_BRANCH == 'development':
vers = 'D'
else:
vers = 'NONE'
# Initialize the database
logger.info('Checking to see if the database has all tables....')
try:
@ -220,22 +203,6 @@ def initialize(config_file):
logger.fdebug('ConcurrentLogHandler package not installed. Using builtin log handler for Rotational logs (default)')
logger.fdebug('[Windows Users] If you are experiencing log file locking and want this auto-enabled, you need to install Python Extensions for Windows ( http://sourceforge.net/projects/pywin32/ )')
logger.info('Config GIT Branch: %s' % CONFIG.GIT_BRANCH)
# Check for new versions (autoupdate)
if CONFIG.CHECK_GITHUB_ON_STARTUP:
try:
LATEST_VERSION = versioncheck.checkGithub()
except:
LATEST_VERSION = CURRENT_VERSION
else:
LATEST_VERSION = CURRENT_VERSION
#
if CONFIG.AUTO_UPDATE:
if CURRENT_VERSION != LATEST_VERSION and INSTALL_TYPE != 'win' and COMMITS_BEHIND > 0:
logger.info('Auto-updating has been enabled. Attempting to auto-update.')
# SIGNAL = 'update'
#check for syno_fix here
if CONFIG.SYNO_FIX:
parsepath = os.path.join(DATA_DIR, 'bs4', 'builder', '_lxml.py')
@ -251,7 +218,6 @@ def initialize(config_file):
else:
logger.info('Synology Parsing Fix already implemented. No changes required at this time.')
USER_AGENT = 'Mylar/' +str(hash) +'(' +vers +') +http://www.github.com/evilhero/mylar/'
CV_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'}

View file

@ -44,12 +44,15 @@ def runGit(args):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=mylar.PROG_DIR)
output, err = p.communicate()
#logger.debug('Git output: %s' % output)
except OSError as e:
logger.fdebug('Command %s didn\'t work [%s]' % (cmd, e))
except Exception as e:
logger.error('Command %s didn\'t work [%s]' % (cmd, e))
continue
else:
if all([err is not None, err != '']):
logger.error('Encountered error: %s' % err)
if 'not found' in output or "not recognized as an internal or external command" in output:
logger.fdebug('Unable to find git with command ' + cmd)
logger.error('[%s] Unable to find git with command: %s' % (output, cmd))
output = None
elif 'fatal:' in output or err:
logger.error('Error: %s' % err)
@ -96,20 +99,24 @@ def getVersion():
else:
branch = None
branch_name, err = runGit('branch --contains ' + cur_commit_hash) #rev-parse --abbrev-ref HEAD')
for line in branch_name.split('\n'):
if '*' in line:
branch = re.sub('[\*\n]','',line).strip()
break
if not branch and mylar.CONFIG.GIT_BRANCH:
logger.warn('Unable to retrieve branch name [' + branch + '] from git. Setting branch to configuration value of : ' + mylar.CONFIG.GIT_BRANCH)
branch = mylar.CONFIG.GIT_BRANCH
if not branch:
logger.warn('Could not retrieve branch name [' + branch + '] form git. Defaulting to Master.')
branch_name, err = runGit('branch --contains %s' % cur_commit_hash)
if not branch_name:
logger.warn('Could not retrieve branch name [%s] from git. Defaulting to Master.' % branch)
branch = 'master'
else:
logger.info('Branch detected & set to : ' + branch)
for line in branch_name.split('\n'):
if '*' in line:
branch = re.sub('[\*\n]','',line).strip()
break
if not branch and mylar.CONFIG.GIT_BRANCH:
logger.warn('Unable to retrieve branch name [%s] from git. Setting branch to configuration value of : %s' % (branch, mylar.CONFIG.GIT_BRANCH))
branch = mylar.CONFIG.GIT_BRANCH
if not branch:
logger.warn('Could not retrieve branch name [%s] from git. Defaulting to Master.' % branch)
branch = 'master'
else:
logger.info('Branch detected & set to : %s' % branch)
return cur_commit_hash, branch
@ -154,11 +161,12 @@ def getVersion():
logger.warn('Unable to determine which commit is currently being run. Defaulting to Master branch.')
def checkGithub():
def checkGithub(current_version=None):
if current_version is None:
current_version = mylar.CURRENT_VERSION
# Get the latest commit available from github
url = 'https://api.github.com/repos/%s/mylar/commits/%s' % (mylar.CONFIG.GIT_USER, mylar.CONFIG.GIT_BRANCH)
logger.info ('Retrieving latest version information from github')
try:
response = requests.get(url, verify=True)
git = response.json()
@ -169,9 +177,9 @@ def checkGithub():
return mylar.CURRENT_VERSION
# See how many commits behind we are
if mylar.CURRENT_VERSION:
logger.fdebug('Comparing currently installed version [' + mylar.CURRENT_VERSION + '] with latest github version [' + mylar.LATEST_VERSION +']')
url = 'https://api.github.com/repos/%s/mylar/compare/%s...%s' % (mylar.CONFIG.GIT_USER, mylar.CURRENT_VERSION, mylar.LATEST_VERSION)
if current_version is not None:
logger.fdebug('Comparing currently installed version [%s] with latest github version [%s]' % (current_version, mylar.LATEST_VERSION))
url = 'https://api.github.com/repos/%s/mylar/compare/%s...%s' % (mylar.CONFIG.GIT_USER, current_version, mylar.LATEST_VERSION)
try:
response = requests.get(url, verify=True)
@ -276,6 +284,39 @@ def update():
try:
with open(version_path, 'w') as f:
f.write(str(mylar.LATEST_VERSION))
except IOError, e:
logger.error("Unable to write current version to version.txt, update not complete: " +ex(e))
except IOError as e:
logger.error("Unable to write current version to version.txt, update not complete: %s" % ex(e))
return
def versionload():
mylar.CURRENT_VERSION, mylar.CONFIG.GIT_BRANCH = getVersion()
if mylar.CURRENT_VERSION is not None:
hash = mylar.CURRENT_VERSION[:7]
else:
hash = "unknown"
if mylar.CONFIG.GIT_BRANCH == 'master':
vers = 'M'
elif mylar.CONFIG.GIT_BRANCH == 'development':
vers = 'D'
else:
vers = 'NONE'
mylar.USER_AGENT = 'Mylar/' +str(hash) +'(' +vers +') +http://www.github.com/evilhero/mylar/'
logger.info('Version information: %s [%s]' % (mylar.CONFIG.GIT_BRANCH, mylar.CURRENT_VERSION))
if mylar.CONFIG.CHECK_GITHUB_ON_STARTUP:
try:
mylar.LATEST_VERSION = checkGithub() #(CURRENT_VERSION)
except:
mylar.LATEST_VERSION = mylar.CURRENT_VERSION
else:
mylar.LATEST_VERSION = mylar.CURRENT_VERSION
if mylar.CONFIG.AUTO_UPDATE:
if mylar.CURRENT_VERSION != mylar.LATEST_VERSION and mylar.INSTALL_TYPE != 'win' and mylar.COMMITS_BEHIND > 0:
logger.info('Auto-updating has been enabled. Attempting to auto-update.')
#SIGNAL = 'update'