Browse Source

update template

master
Nils 3 months ago
parent
commit
2afb1c22e1
  1. 8
      template/helper.py
  2. 12
      template/qtgui/debugScript.py

8
template/helper.py

@ -27,6 +27,14 @@ from functools import lru_cache #https://docs.python.org/3.4/library/functools.h
cache_unlimited = lru_cache(maxsize=None)
#use as @cache_unlimited decorator
def dictdiff(a, b):
"""We use dicts for internal export packages. Compare two of them for changes"""
result = {}
for key, value in a.items():
if not b[key] == value:
result[key] = (value, b[key])
return result
import itertools
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."

12
template/qtgui/debugScript.py

@ -39,9 +39,11 @@ class DebugScriptRunner(object):
assert nsmClient
self.nsmClient = nsmClient
self.absoluteScriptFilePath = os.path.join(self.nsmClient.ourPath, "debugscript.py")
logger.info(f"{self.nsmClient.ourClientNameUnderNSM}: Using script file: {self.absoluteScriptFilePath}")
def _createEmptyDebugScript(self):
assert self.absoluteScriptFilePath
print(f"{self.nsmClient.ourClientNameUnderNSM}: Script file not found. Initializing: {self.absoluteScriptFilePath}")
logger.info(f"{self.nsmClient.ourClientNameUnderNSM}: Script file not found. Initializing: {self.absoluteScriptFilePath}")
text = ("""#! /usr/bin/env python3"""
"\n"
@ -54,14 +56,14 @@ class DebugScriptRunner(object):
)
with open(self.absoluteScriptFilePath, "w", encoding="utf-8") as f:
f.write(text)
f.write(text)
def run(self):
if not os.path.exists(self.absoluteScriptFilePath):
if not os.path.exists(self.nsmClient.ourPath):
os.makedirs(self.nsmClient.ourPath)
os.makedirs(self.nsmClient.ourPath)
self._createEmptyDebugScript()
try:
exec(compile(open(self.absoluteScriptFilePath).read(), filename=self.absoluteScriptFilePath, mode="exec"), globals(), self.apilocals)
except Exception as e:

Loading…
Cancel
Save