ya2 · news · projects · code · about

fixed version
[pmachines.git] / lib / build / build.py
index d424c792cab8575cab785793b4f9364982b088f2..9fdd8cb435956c6c5f2fad4c2c509a36b259bb24 100644 (file)
@@ -2,6 +2,7 @@
 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
@@ -21,8 +22,10 @@ def exec_cmd(cmd):
 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):
@@ -31,14 +34,39 @@ def _branch():
         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')
@@ -53,13 +81,13 @@ def _version():
                 _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)