[Windows] Try to fix %X expansions

- They convert \ to / and remove :
- So we now avoid it on Windows
Related to #325
This commit is contained in:
Salvador E. Tropea 2022-12-01 07:36:53 -03:00
parent fdd38d176a
commit 75ebc7a677
4 changed files with 24 additions and 3 deletions

View File

@ -74,6 +74,7 @@ from glob import glob
import gzip
import locale
import os
import platform
import re
import sys
from sys import path as sys_path
@ -98,7 +99,7 @@ if os.environ.get('KIAUS_USE_NIGHTLY'): # pragma: no cover (nightly)
os.environ['PYTHONPATH'] = pcbnew_path
nightly = True
from .gs import GS
from .misc import EXIT_BAD_ARGS, W_VARCFG, NO_PCBNEW_MODULE, W_NOKIVER, hide_stderr, TRY_INSTALL_CHECK
from .misc import EXIT_BAD_ARGS, W_VARCFG, NO_PCBNEW_MODULE, W_NOKIVER, hide_stderr, TRY_INSTALL_CHECK, W_ONWIN
from .pre_base import BasePreFlight
from .error import KiPlotConfigurationError, config_error
from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example,
@ -285,6 +286,14 @@ def debug_arguments(args):
logger.debug('Command line parsed:\n'+str(args))
def detect_windows():
if platform.system() != 'Windows':
return
# Note: We assume this is the Python from KiCad, but we should check it ...
GS.on_windows = True
logger.warning(W_ONWIN+'Running on Windows, this is experimental, please report any problem')
def main():
set_locale()
ver = 'KiBot '+__version__+' - '+__copyright__+' - License: '+__license__
@ -298,6 +307,7 @@ def main():
apply_warning_filter(args)
# Now we have the debug level set we can check (and optionally inform) KiCad info
detect_kicad()
detect_windows()
debug_arguments(args)
# Force iBoM to avoid the use of graphical stuff

View File

@ -54,6 +54,7 @@ class GS(object):
debug_level = 0
kibot_version = None
n = datetime.now()
on_windows = False
kicad_version = ''
kicad_conf_path = None
kicad_share_path = None

View File

@ -241,6 +241,7 @@ W_MISSFPINFO = '(W102) '
W_PCBDRAW = '(W103) '
W_NOCRTYD = '(W104) '
W_PANELEMPTY = '(W105) '
W_ONWIN = '(W106) '
# Somehow arbitrary, the colors are real, but can be different
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e",

View File

@ -15,6 +15,7 @@ from . import log
logger = log.get_logger()
HEX_DIGIT = '[A-Fa-f0-9]{2}'
INVALID_CHARS = r'[?%*:|"<>]'
def do_filter(v):
@ -345,8 +346,16 @@ class Optionable(object):
name = GS.expand_text_variables(name)
if make_safe:
# sanitize the name to avoid characters illegal in file systems
name = name.replace('\\', '/')
name = re.sub(r'[?%*:|"<>]', '_', name)
if GS.on_windows:
# Here \ *is* valid
if len(name) >= 2 and name[0].isalpha() and name[1] == ':':
# This name starts with a drive letter, : is valid in the first 2
name = name[:2]+re.sub(INVALID_CHARS, '_', name[2:])
else:
name = re.sub(INVALID_CHARS, '_', name)
else:
name = name.replace('\\', '/')
name = re.sub(INVALID_CHARS, '_', name)
if GS.debug_level > 3:
logger.debug('Expanded `{}`'.format(name))
return name