Skip to content

Commit

Permalink
Check app version on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
imirzov committed Jul 10, 2021
1 parent b1a074e commit 99fb402
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ You may also need libraries:

What's new in future v0.9.0:

- CalculiX 2.17.1. Linux version of CGX has 'cmap' command and [custom colormaps](https://github.com/calculix/cgx/releases/tag/v2.17.cmap): classic, viridis, inferno and turbo.
- Switch colormaps from menu CGX.
- CalculiX 2.17.1. Linux version of CGX has 'cmap' command and [custom colormaps](https://github.com/calculix/cgx/releases/tag/v2.17.cmap): classic, viridis, inferno and turbo. Switch colormaps from menu CGX.
- Significantly improved INP importer algorithm. Now parser supports keyword line continuation. Tested on over 20 000 INP files, including Abaqus models.
- Dependencies are automatically installed and tested on startup.
- Python version and OS name are checked at startup.
- New checker module. Checks are called on the application start. OS name, Python version, CAE version and default web browser are logged. Requirements are installed automatically via pip.
- Significantly improved window connectivity (master/slave).
- Improved robustness - now almost all python modules have a test method.
- Refactored logging system. Now it is a new dedicated module.
Expand Down Expand Up @@ -220,7 +218,6 @@ Importer:
- Open .fbd/.fbl and forward to CGX. Then import generated model.

Logging and tests:
- Log app version on startup.
- 'Debug' menu to test each module.

Other:
Expand Down
2 changes: 2 additions & 0 deletions config/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do not edit
0.9.0 dev
32 changes: 26 additions & 6 deletions src/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"""© Ihor Mirzov, 2019-2021
Distributed under GNU General Public License v3.0
Utilities to test user's system configuration.
Is called on the application startup.
Utilities to test user's system configuration. Checks are called on the
application start. OS name, Python version, app. version, default web
browser are logged. Requirements are installed automatically via pip.
Run test: Ctrl+F5 from VSCode.
"""
Expand All @@ -15,12 +16,12 @@
import os
import sys
import logging
import importlib
import subprocess
import webbrowser

# My modules
import tests
import path
import log


Expand Down Expand Up @@ -55,6 +56,20 @@ def check_python():
msg = 'Python version is {}.{}.{}.'.format(*v1)
logging.info(msg)

@staticmethod
def check_app_version():
lines = []
with open(path.p.version_txt, 'r') as f:
lines = f.readlines()
for l in lines:
l = l.strip()
if l.startswith('#'):
continue
if not len(l):
continue
logging.info('CAE version is ' + l + '.')
return

@staticmethod
def check_default_web_browser():
"""Get default web browser."""
Expand Down Expand Up @@ -107,9 +122,12 @@ def check_required_package(name):
def install_package(name, prefix=''):
"""Automatically install package."""
try:
logging.info('Installing ' + name + '...')
cmd = [sys.executable, '-m', 'pip', prefix + 'install', name]
# subprocess.check_call(cmd)
if 'un' in prefix:
logging.info('Removing ' + name + '...')
cmd = [sys.executable, '-m', 'pip', prefix + 'install', name, '-y']
else:
logging.info('Installing ' + name + '...')
cmd = [sys.executable, '-m', 'pip', prefix + 'install', name]
msg = subprocess.check_output(cmd)
msg = msg.decode().rstrip()
logging.info(msg)
Expand All @@ -133,6 +151,7 @@ def check_all():
log.print_to_file(log_file, 'STARTUP TESTS\n')
Checks.check_os()
Checks.check_python()
Checks.check_app_version()
Checks.check_default_web_browser()
Checks.check_requirements() # containts SystemExit

Expand All @@ -157,5 +176,6 @@ def test():
Checks.check_package('qwe')
Checks.check_required_package('rty')


if __name__ == '__main__':
test() # run test
2 changes: 1 addition & 1 deletion src/model/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def copy_checks_log_contents_to(job_logfile):
lines = f.readlines()
with open(job_logfile, 'w') as f:
f.writelines(lines)
f.write('\nAPPLICATION START\n')
f.write('\nAPPLICATION START\n\n')
# os.remove(checks_log)


Expand Down
1 change: 1 addition & 0 deletions src/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self):
self.kom_xml = os.path.join(self.config, 'kom.xml')
self.settings_xml = os.path.join(self.config, 'SettingsDialog.xml')
self.dialog_xml = os.path.join(self.config, 'KeywordDialog.xml')
self.version_txt = os.path.join(self.config, 'version.txt')

self.bin = os.path.join(self.app_home_dir, 'bin')
self.ccx = os.path.join(self.app_home_dir, 'ccx_' + self.op_sys, 'src')
Expand Down

0 comments on commit 99fb402

Please sign in to comment.