add get version method

This commit is contained in:
Vladimir Mandic
2023-05-25 13:59:57 -04:00
parent 9a3a56dbb2
commit 1e07e871fb
2 changed files with 27 additions and 0 deletions
+25
View File
@@ -771,6 +771,31 @@ def html(filename):
return file.read()
return ""
def get_version():
version = None
if version is None:
try:
import subprocess
res = subprocess.run('git log --pretty=format:"%h %ad" -1 --date=short', stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True, check=True)
ver = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
githash, updated = ver.split(' ')
res = subprocess.run('git remote get-url origin', stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True, check=True)
origin = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
res = subprocess.run('git branch --show-current', stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True, check=True)
branch = res.stdout.decode(encoding = 'utf8', errors='ignore') if len(res.stdout) > 0 else ''
version = {
'app': 'sd.next',
'updated': updated,
'hash': githash,
'url': origin.replace('\n', '') + '/tree/' + branch.replace('\n', '')
}
except:
version = { 'app': 'sd.next' }
pass
return version
class Shared(sys.modules[__name__].__class__):
# this class is here to provide sd_model field as a property, so that it can be created and loaded on demand rather than at program startup.
sd_model_val = None
+2
View File
@@ -197,6 +197,8 @@ def async_policy():
def start_common():
log.debug('Entering start sequence')
if cmd_opts.debug and hasattr(shared, 'get_version'):
log.debug(f'Version: {shared.get_version()}')
logging.disable(logging.NOTSET if cmd_opts.debug else logging.DEBUG)
if shared.cmd_opts.data_dir is not None or len(shared.cmd_opts.data_dir) > 0:
log.info(f'Using data path: {shared.cmd_opts.data_dir}')