ya2 · news · projects · code · about

fixed version
authorFlavio Calva <f.calva@gmail.com>
Wed, 18 May 2022 18:58:04 +0000 (19:58 +0100)
committerFlavio Calva <f.calva@gmail.com>
Wed, 18 May 2022 18:58:04 +0000 (19:58 +0100)
game/app.py
lib/build/build.py
lib/engine/log.py

index 88c9216359916195b82ddd0ec841b876d9fac9e7..057a6808f94f0bf9edc929c87d255c2c78cd87c4 100755 (executable)
@@ -198,12 +198,14 @@ class PmachinesApp:
         if res:
             res = LVector2i(*[int(_res) for _res in res.split('x')])
         else:
-            d_i = base.pipe.get_display_information()
-            def _res(idx):
-                return d_i.get_display_mode_width(idx), \
-                    d_i.get_display_mode_height(idx)
-            resolutions = [
-                _res(idx) for idx in range(d_i.get_total_display_modes())]
+            resolutions = []
+            if not self.version:
+                d_i = base.pipe.get_display_information()
+                def _res(idx):
+                    return d_i.get_display_mode_width(idx), \
+                        d_i.get_display_mode_height(idx)
+                resolutions = [
+                    _res(idx) for idx in range(d_i.get_total_display_modes())]
             res = sorted(resolutions)[-1]
         fullscreen = self._options['settings']['fullscreen']
         props = WindowProperties()
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)
index ac4920ea53ec6b4a08b29e1b5b13574880f6f147..13f104c5cd44f4e14352f8ba6d7bb233cba336ec 100755 (executable)
@@ -61,38 +61,51 @@ class LogMgrBase(Colleague):  # headless log manager
         is_appimage = par_path.startswith('/tmp/.mount_Pmachi')
         return is_appimage and par_path.endswith('/usr/bin')
 
+    # @property
+    # def curr_path(self):
+    #     # this is different from the music's one since it does not work
+    #     # with the version in windows
+    #     if sys.platform == 'darwin':
+    #         return dirname(__file__) + '/../Resources/'
+    #     # return dirname(__file__)
+    #     par_path = str(Path(__file__).parent.absolute())
+    #     if self.is_appimage:
+    #         return str(Path(par_path).absolute())
+    #     is_snap = par_path.startswith('/snap/')
+    #     is_snap = is_snap and par_path.endswith('/x1')
+    #     if is_snap:
+    #         return str(Path(par_path).absolute())
+    #     #return getcwd()
+    #     #curr_path = dirname(__file__)
+    #     curr_path = str(Path(__file__).parent.parent.parent.absolute())
+    #     info('current path: %s' % curr_path)
+    #     return curr_path
+
     @property
     def curr_path(self):
-        # this is different from the music's one since it does not work
-        # with the version in windows
-        if sys.platform == 'darwin':
-            return dirname(__file__) + '/../Resources/'
-        # return dirname(__file__)
-        par_path = str(Path(__file__).parent.absolute())
+        if system() == 'Windows':
+            return ''
+        if exists('main.py'):
+            return ''
+        else:
+            par_path = str(Path(__file__).parent.absolute())
         if self.is_appimage:
-            return str(Path(par_path).absolute())
-        is_snap = par_path.startswith('/snap/')
-        is_snap = is_snap and par_path.endswith('/x1')
-        if is_snap:
-            return str(Path(par_path).absolute())
-        #return getcwd()
-        #curr_path = dirname(__file__)
-        curr_path = str(Path(__file__).parent.parent.parent.absolute())
-        info('current path: %s' % curr_path)
-        return curr_path
+            par_path = str(Path(par_path).absolute())
+        par_path += '/'
+        return par_path
 
     @property
     def build_version(self):
         appimg_mnt = glob('/tmp/.mount_Pmachi*')
         if appimg_mnt:
             #with open(appimg_mnt[0] + '/usr/bin/appimage_version.txt') as fver:
-            with open(self.curr_path + '/assets/bld_version.txt') as fver:
+            with open(self.curr_path + 'assets/bld_version.txt') as fver:
                 return fver.read().strip()
         try:
-            with open(self.curr_path + '/assets/bld_version.txt') as fver:
+            with open(self.curr_path + 'assets/bld_version.txt') as fver:
                 return fver.read().strip()
         except FileNotFoundError:
-            info('not found ' + self.curr_path + '/assets/bld_version.txt')
+            info('not found ' + self.curr_path + 'assets/bld_version.txt')
             return 'notfound'
 
     def log_cfg(self):