from os import walk, chdir, getcwd
from os.path import join, getsize, exists, dirname, getmtime, sep
from subprocess import Popen, PIPE, run
+from logging import debug
from time import strftime
from pathlib import Path
from hashlib import md5
def _branch():
'''Returns the current branch.'''
git_branch = exec_cmd('git symbolic-ref HEAD').split('/')[-1].strip()
+ print('git_branch result: %s' % git_branch)
branches = ['master', 'rc', 'stable']
if git_branch in branches:
+ print('git_branch: %s' % git_branch)
return git_branch
root = str(Path(dirname(dirname(__file__))).parent) + '/'
if 'itch' in __file__.split(sep):
root = str(Path(dirname(__file__))) + '/'
- if __file__ == '/app/bin/yocto': # flatpak
+ if __file__ == '/app/bin/pmachines': # flatpak
root = '/app/bin/'
for branch in branches:
try:
+ print('try: %s' % root + 'assets/bld_version.txt')
with open(root + 'assets/bld_version.txt') as fver:
ver = fver.read()
- if branch in ver:
+ print('ver: %s' % ver)
+ #if branch in ver:
+ b2c = {'master': 'a', 'rc': 'r', 'stable': '.'}
+ if ver[1] == b2c[branch]:
return branch
except FileNotFoundError:
print('file not found: %s' % root + 'assets/bld_version.txt')
+def _commit():
+ '''Returns the current branch.'''
+ git_commit = exec_cmd('git rev-parse HEAD')[:7]
+ print('git_commit result: %s' % git_commit)
+ if not git_commit.startswith("Can't r"):
+ return git_commit
+ root = str(Path(dirname(dirname(__file__))).parent) + '/'
+ if 'itch' in __file__.split(sep):
+ root = str(Path(dirname(__file__))) + '/'
+ if __file__ == '/app/bin/pmachines': # flatpak
+ root = '/app/bin/'
+ try:
+ print('try: %s' % root + 'assets/bld_version.txt')
+ with open(root + 'assets/bld_version.txt') as fver:
+ ver = fver.read()
+ print('ver: %s' % ver)
+ return ver.split('-')[1]
+ except FileNotFoundError:
+ print('file not found: %s' % root + 'assets/bld_version.txt')
+
+
def _version():
'''Computes the version of the current build.'''
day = strftime('%y%m%d')
root = str(Path(dirname(dirname(__file__))).parent) + '/'
- if __file__ == '/app/bin/yocto': # flatpak
+ if __file__ == '/app/bin/pmachines': # flatpak
root = '/app/bin/'
if _branch() == 'stable':
pref, _ver = '', ''
_ver = fver.read().strip()
ret_ver = _ver or ('0.' + day)
else:
- try:
- pref = {'master': 'a', 'rc': 'rc', '': 'runtime'}[_branch()]
- except KeyError:
- pref = 'notfound'
+ #try: we want an error!
+ pref = {'master': 'a', 'rc': 'rc', '': 'runtime'}[_branch()]
+ #except KeyError:
+ # pref = 'notfound'
ret_ver = '0%s%s' % (pref, day)
pref = ret_ver
- bld_ver = pref + '-' + exec_cmd('git rev-parse HEAD')[:7]
+ bld_ver = pref + '-' + _commit()
try:
with open(root + 'assets/bld_version.txt', 'w') as fver:
fver.write(bld_ver)