summaryrefslogtreecommitdiff
path: root/lib/debug_utils.py
diff options
context:
space:
mode:
authorkarnigen <karnigen@gmail.com>2023-12-29 16:25:17 +0100
committerkarnigen <karnigen@gmail.com>2023-12-29 16:25:17 +0100
commitf1f9d275a1ffaeb538a72e3643fb98231323337a (patch)
tree0ede0d3c064e17d4545cb6e085b97110bc8b2b29 /lib/debug_utils.py
parentfe323375e42253f00fd378fbaff1a3373385fccc (diff)
replace DEBUG,PROFILE by DEVEL.ini
Diffstat (limited to 'lib/debug_utils.py')
-rw-r--r--lib/debug_utils.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/debug_utils.py b/lib/debug_utils.py
index b5d7aa6a..183a44f8 100644
--- a/lib/debug_utils.py
+++ b/lib/debug_utils.py
@@ -5,6 +5,12 @@
import os
import sys
+from pathlib import Path
+
+# this file is without: import inkex
+# - so we can modify sys.path before importing inkex
+
+# DEBUG and PROFILE are in DEVEL.ini file
# DEBUG file format:
# - first non-comment line is debugger type
@@ -45,12 +51,24 @@ def parse_file(filename):
break
return value_type
-def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg):
+def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Path):
# prepare script for offline debugging from console
- # - only tested on linux
+
+ # check if input svg file exists in arguments, take argument that not start with '-' as file name
+ svgs = [arg for arg in sys.argv[1:] if not arg.startswith('-')]
+ if len(svgs) != 1:
+ print(f"WARN: {len(svgs)} svg files found, expected 1, [{svgs}]. No script created in write debug script.", file=sys.stderr)
+ return
+
+ svg_file = Path(svgs[0])
+ if svg_file.exists() and bash_svg.exists() and bash_svg.samefile(svg_file):
+ print(f"WARN: input svg file is same as output svg file. No script created in write debug script.", file=sys.stderr)
+ return
+
import shutil
- ink_file = os.path.join(SCRIPTDIR, bash_name)
- with open(ink_file, 'w') as f:
+ bash_file = SCRIPTDIR / bash_name
+
+ with open(bash_file, 'w') as f: # "w" text mode, automatic conversion of \n to os.linesep
f.write(f"#!/usr/bin/env bash\n\n")
f.write(f"# python version: {sys.version}\n") # python version
@@ -67,13 +85,11 @@ def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg):
for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): # PYTHONPATH to list
f.write(f"# {p}\n")
- # take argument that not start with '-' as file name
- svg_file = " ".join([arg for arg in sys.argv[1:] if not arg.startswith('-')])
f.write(f"# copy {svg_file} to {bash_svg}\n")
# check if files are not the same
if svg_file != bash_svg:
shutil.copy(svg_file, SCRIPTDIR / bash_svg) # copy file to bash_svg
- myargs = myargs.replace(svg_file, bash_svg) # replace file name with bash_svg
+ myargs = myargs.replace(str(svg_file), str(bash_svg)) # replace file name with bash_svg
# see void Extension::set_environment() in inkscape/src/extension/extension.cpp
notexported = ["SELF_CALL"] # if an extension calls inkscape itself
@@ -86,5 +102,9 @@ def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg):
if k in os.environ:
f.write(f'export {k}="{os.environ[k]}"\n')
+ f.write('# signal inkstitch.py that we are running from offline script\n')
+ f.write(f'export INKSTITCH_OFFLINE_SCRIPT="True"\n')
+
+ f.write('# call inkstitch\n')
f.write(f"python3 inkstitch.py {myargs}\n")
- os.chmod(ink_file, 0o0755) # make file executable
+ bash_file.chmod(0o0755) # make file executable