Operations that copies the project now also copies the DRU

See #491
This commit is contained in:
Salvador E. Tropea 2023-12-06 08:21:25 -03:00
parent d9f0324e39
commit b91c24b28e
6 changed files with 29 additions and 12 deletions

View File

@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.6.4] - UNRELEASED
### Added
- General:
- Operations that copies the project now also copies the PRL
- Operations that copies the project now also copies the PRL and the DRU
- Command line:
- `--help-list-offsets` to list footprint offsets (JLCPCB)
- `--help-list-rotations` to list footprint rotations (JLCPCB)

View File

@ -171,7 +171,7 @@
which is used by the KiBot docker images, on other OSs *your mileage may vary*.
- ``restore_project`` :index:`: <pair: global options; restore_project>` [boolean=false] Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables`.
Starting with 1.6.4 it also restores the PRL (Project Local Settings) file.
Starting with 1.6.4 it also restores the PRL (Project Local Settings) and DRU (Design RUles) files.
- ``set_text_variables_before_output`` :index:`: <pair: global options; set_text_variables_before_output>` [boolean=false] Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than
one variant in the same run. Note that this could be slow because it forces a board

View File

@ -239,7 +239,7 @@ class Globals(FiltersOptions):
self.restore_project = False
""" Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables`.
Starting with 1.6.4 it also restores the PRL (Project Local Settings) file """
Starting with 1.6.4 it also restores the PRL (Project Local Settings) and DRU (Design RUles) files """
self.set_text_variables_before_output = False
""" Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than

View File

@ -254,7 +254,12 @@ class GS(object):
if os.path.isfile(prl_name):
with open(prl_name, 'rb') as f:
prl = f.read()
return (pro, prl)
dru_name = GS.pro_file[:-3]+'dru'
dru = None
if os.path.isfile(dru_name):
with open(dru_name, 'rb') as f:
dru = f.read()
return (pro, prl, dru)
@staticmethod
def write_pro(data):
@ -262,10 +267,12 @@ class GS(object):
return
with open(GS.pro_file, 'wb') as f:
f.write(data[0])
if data[1] is None:
return
with open(GS.pro_file[:-3]+'prl', 'wb') as f:
f.write(data[1])
if data[1] is not None:
with open(GS.pro_file[:-3]+'prl', 'wb') as f:
f.write(data[1])
if data[2] is not None:
with open(GS.pro_file[:-3]+'dru', 'wb') as f:
f.write(data[2])
@staticmethod
def load_sch_title_block():
@ -480,7 +487,7 @@ class GS(object):
def copy_project(new_pcb_name, dry=False):
pro_name = GS.pro_file
if pro_name is None or not os.path.isfile(pro_name):
return None, None
return None, None, None
pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext)
if not dry:
logger.debug(f'Copying project `{pro_name}` to `{pro_copy}`')
@ -493,7 +500,15 @@ class GS(object):
if not dry:
logger.debug(f'Copying project local settings `{prl_name}` to `{prl_copy}`')
copy2(prl_name, prl_copy)
return pro_copy, prl_copy
# ... and the DRU
dru_name = pro_name[:-3]+'dru'
dru_copy = None
if os.path.isfile(dru_name):
dru_copy = pro_copy[:-3]+'dru'
if not dry:
logger.debug(f'Copying project custom design rules `{dru_name}` to `{dru_copy}`')
copy2(dru_name, dru_copy)
return pro_copy, prl_copy, dru_copy
@staticmethod
def copy_project_sch(sch_dir):

View File

@ -930,7 +930,7 @@ class VariantOptions(BaseOptions):
fname = os.path.join(pcb_dir, basename+'.kicad_pcb')
logger.debug('Storing modified PCB to `{}`'.format(fname))
GS.board.Save(fname)
pro_name, _ = GS.copy_project(fname)
pro_name, _, _ = GS.copy_project(fname)
KiConf.fix_page_layout(pro_name)
return fname, pcb_dir

View File

@ -235,13 +235,15 @@ class Copy_FilesOptions(Base3DOptions):
self.add_sch_files(extra_files, dest_dir)
elif mode_project:
self.add_sch_files(extra_files, dest_dir)
prj_name, prl_name = GS.copy_project(fname, dry)
prj_name, prl_name, dru_name = GS.copy_project(fname, dry)
# Extra files that we are generating
extra_files.append(fname)
if prj_name:
extra_files.append(prj_name)
if prl_name:
extra_files.append(prl_name)
if dru_name:
extra_files.append(dru_name)
if mode_project:
extra_files += self.copy_footprints(f.dest, dry)
extra_files += self.copy_symbols(f.dest, dry)