blob: 6555b0830c3a424819ad5bc9f5f4cd2a7843d452 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import os
import sys
# DEBUG file format:
# - first non-comment line is debugger type
# - valid values are:
# "vscode" or "vscode-script" - for debugging with vscode
# "pycharm" or "pycharm-script" - for debugging with pycharm
# "pydev" or "pydev-script" - for debugging with pydev
# "none" or empty file - for no debugging
# - for offline debugging without inkscape, set debugger name to
# as "vscode-script" or "pycharm-script" or "pydev-script"
# - in that case running from inkscape will not start debugger
# but prepare script for offline debugging from console
# - backward compatibilty is broken due to confusion
# debug_type = 'pydev' # default debugger backwards compatibility
# if 'PYCHARM_REMOTE_DEBUG' in os.environ: # backwards compatibility
# debug_type = 'pycharm'
# PROFILE file format:
# - first non-comment line is profiler type
# - valid values are:
# "cprofile" - for cProfile
# "pyinstrument" - for pyinstrument
# "profile" - for profile
# "none" - for no profiling
def parse_file(filename):
# parse DEBUG or PROFILE file for type
# - return first noncomment and nonempty line from file
value_type = 'none'
with open(filename, 'r') as f:
for line in f:
line = line.strip().lower()
if line.startswith("#") or line == "": # skip comments and empty lines
continue
value_type = line # first non-comment line is type
break
return value_type
def write_offline_debug_script(SCRIPTDIR):
# prepare script for offline debugging from console
# - only tested on linux
import shutil
ink_file = os.path.join(SCRIPTDIR, ".ink.sh")
with open(ink_file, 'w') as f:
f.write(f"#!/usr/bin/env bash\n\n")
f.write(f"# version: {sys.version}\n") # python version
myargs = " ".join(sys.argv[1:])
f.write(f'# script: {sys.argv[0]} arguments: {myargs}\n') # script name and arguments
# python module path
f.write(f"# python sys.path:\n")
for p in sys.path:
f.write(f"# {p}\n")
# print PYTHONPATH one per line
f.write(f"# PYTHONPATH:\n")
for p in os.environ.get('PYTHONPATH', '').split(os.pathsep):
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 .ink.svg\n")
# check if filer are not the same
if svg_file != '.ink.svg':
shutil.copy(svg_file, f'{SCRIPTDIR}/.ink.svg') # copy file to .ink.svg
myargs = myargs.replace(svg_file, '.ink.svg') # replace file name with .ink.svg
# export INK*|PYTHON* environment variables
for k, v in sorted(os.environ.items()):
if k.startswith('INK') or k.startswith('PYTHON'):
f.write(f'export {k}="{v}"\n')
# f.write(f"# python3 -m debugpy --listen 5678 --wait-for-client inkstitch.py {myargs}\n")
f.write(f"python3 inkstitch.py {myargs}\n")
os.chmod(ink_file, 0o0755) # make file executable
|