Normalized the PCB and SCH file names.

Now the GS members contains the absolute path and various useful parts
of the name are computed and stored in GS to avoid computing them in
each output.
This commit is contained in:
Salvador E. Tropea 2020-07-23 12:03:42 -03:00
parent 43b97db20c
commit d4d88a5c9d
3 changed files with 34 additions and 11 deletions

View File

@ -205,9 +205,9 @@ def main():
sys.exit(0)
# Determine the SCH file
GS.sch_file = solve_schematic(args.schematic, args.board_file)
GS.set_sch(solve_schematic(args.schematic, args.board_file))
# Determine the PCB file
GS.pcb_file = solve_board_file(GS.sch_file, args.board_file)
GS.set_pcb(solve_board_file(GS.sch_file, args.board_file))
generate_outputs(outputs, args.target, args.invert_sel, args.skip_pre)

View File

@ -13,10 +13,17 @@ class GS(object):
Class to keep the global settings.
Is a static class, just a placeholder for some global variables.
"""
pcb_file = None
sch_basename = None
sch_file = None
sch_basename = None
# PCB name and useful parts
pcb_file = None # /.../dir/file.sch
pcb_no_ext = None # /.../dir/file
pcb_dir = None # /.../dir
pcb_basename = None # file
# SCH name and useful parts
sch_file = None # /.../dir/pcb.kicad_pcb
sch_basename = None # /.../dir/pcb
sch_no_ext = None # /.../dir
sch_dir = None # pcb
# Main output dir
out_dir = None
filter_file = None
board = None
@ -35,6 +42,24 @@ class GS(object):
pcb_rev = None
pcb_comp = None
@staticmethod
def set_sch(name):
if name:
name = os.path.abspath(name)
GS.sch_file = name
GS.sch_basename = os.path.splitext(os.path.basename(name))[0]
GS.sch_no_ext = os.path.splitext(name)[0]
GS.sch_dir = os.path.dirname(name)
@staticmethod
def set_pcb(name):
if name:
name = os.path.abspath(name)
GS.pcb_file = name
GS.pcb_basename = os.path.splitext(os.path.basename(name))[0]
GS.pcb_no_ext = os.path.splitext(name)[0]
GS.pcb_dir = os.path.dirname(name)
@staticmethod
def load_sch_title_block():
if GS.sch_title is not None:
@ -64,7 +89,6 @@ class GS(object):
if not GS.sch_date:
file_mtime = os.path.getmtime(GS.sch_file)
GS.sch_date = datetime.fromtimestamp(file_mtime).strftime('%Y-%m-%d_%H-%M-%S')
GS.sch_basename = os.path.splitext(os.path.basename(GS.sch_file))[0]
if not GS.sch_title:
GS.sch_title = GS.sch_basename
logger.debug("SCH title: `{}`".format(GS.sch_title))
@ -86,7 +110,6 @@ class GS(object):
if not GS.pcb_date:
file_mtime = os.path.getmtime(GS.pcb_file)
GS.pcb_date = datetime.fromtimestamp(file_mtime).strftime('%Y-%m-%d_%H-%M-%S')
GS.pcb_basename = os.path.splitext(os.path.basename(GS.pcb_file))[0]
GS.pcb_title = title_block.GetTitle()
if not GS.pcb_title:
GS.pcb_title = GS.pcb_basename

View File

@ -153,7 +153,7 @@ class KiBoMConfig(Optionable):
csv = None
columns = None
try:
xml = os.path.splitext(os.path.abspath(GS.sch_file))[0]+'.xml'
xml = GS.sch_no_ext+'.xml'
config = os.path.abspath(KiBoMConfig._create_minimal_ini())
with NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as f:
csv = f.name
@ -324,8 +324,8 @@ class KiBoMOptions(BaseOptions):
def run(self, output_dir, board):
check_script(CMD_KIBOM, URL_KIBOM, '1.8.0')
format = self.format.lower()
prj = os.path.splitext(os.path.abspath(GS.sch_file))[0]
config = os.path.join(os.path.dirname(os.path.abspath(GS.sch_file)), self.conf)
prj = GS.sch_no_ext
config = os.path.join(GS.sch_dir, self.conf)
if self.output:
force_output = True
output = self.expand_filename_sch(output_dir, self.output, 'bom', format)