[Compress][Added] Option to use the output's `dir` as reference

- `from_output_dir`
This commit is contained in:
Salvador E. Tropea 2023-01-06 13:16:48 -03:00
parent 42f5dcd8d6
commit 59b90283ed
4 changed files with 32 additions and 16 deletions

View File

@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `_only_smd` used to get only SMD parts
- `_only_tht` used to get only THT parts
- `_only_virtual` used to get only virtual parts
- Compress:
- Option to use the output's `dir` as reference (`from_output_dir`)
- iBoM:
- `hide_excluded` to hide excluded *.Fab drawings.
- Internal templates:
- FusionPCB: gerber, drill and compress
- Elecrow: gerber, drill and compress
@ -25,8 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for the KiCad 6 "sketch_pads_on_fab_layers" option. (#356)
- Variants:
- Support for multi-boards as defined by KiKit
- iBoM:
- `hide_excluded` to hide excluded *.Fab drawings.
- SVG:
- Options to limit the view box to the used area.
### Fixed

View File

@ -1802,10 +1802,13 @@ Notes:
When used the `source` option is ignored.
- **`source`**: [string='*'] File names to add, wildcards allowed. Use ** for recursive match.
By default this pattern is applied to the output dir specified with `-d` command line option.
See the `from_cwd` option.
See the `from_cwd` and `from_output_dir` options.
- `dest`: [string=''] Destination directory inside the archive, empty means the same of the file.
- `filter`: [string='.*'] A regular expression that source files must match.
- `from_cwd`: [boolean=false] Use the current working directory instead of the dir specified by `-d`.
- `from_output_dir`: [boolean=false] Use the current the directory specified by the output instead of the dir specified by `-d`.
Note that it only applies when using `from_output` and no `dest` is specified.
It has more prescedence than `from_cwd`.
- **`format`**: [string='ZIP'] [ZIP,TAR,RAR] Output file format.
- **`output`**: [string='%f-%i%I%v.%x'] Name for the generated archive (%i=name of the output %x=according to format). Affected by global options.
- `compression`: [string='auto'] [auto,stored,deflated,bzip2,lzma] Compression algorithm. Use auto to let KiBot select a suitable one.

View File

@ -449,9 +449,13 @@ outputs:
# [string=''] Collect files from the selected output.
# When used the `source` option is ignored
from_output: ''
# [boolean=false] Use the current the directory specified by the output instead of the dir specified by `-d`.
# Note that it only applies when using `from_output` and no `dest` is specified.
# It has more prescedence than `from_cwd`
from_output_dir: false
# [string='*'] File names to add, wildcards allowed. Use ** for recursive match.
# By default this pattern is applied to the output dir specified with `-d` command line option.
# See the `from_cwd` option
# See the `from_cwd` and `from_output_dir` options
source: '*'
# [boolean=true] Store the file pointed by symlinks, not the symlink
follow_links: true

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021-2022 Salvador E. Tropea
# Copyright (c) 2021-2022 Instituto Nacional de Tecnología Industrial
# Copyright (c) 2021-2023 Salvador E. Tropea
# Copyright (c) 2021-2023 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
"""
@ -41,9 +41,13 @@ class FilesList(Optionable):
self.source = '*'
""" *File names to add, wildcards allowed. Use ** for recursive match.
By default this pattern is applied to the output dir specified with `-d` command line option.
See the `from_cwd` option """
See the `from_cwd` and `from_output_dir` options """
self.from_cwd = False
""" Use the current working directory instead of the dir specified by `-d` """
self.from_output_dir = False
""" Use the current the directory specified by the output instead of the dir specified by `-d`.
Note that it only applies when using `from_output` and no `dest` is specified.
It has more prescedence than `from_cwd` """
self.from_output = ''
""" *Collect files from the selected output.
When used the `source` option is ignored """
@ -146,19 +150,19 @@ class CompressOptions(BaseOptions):
for f in self.files:
# Get the list of candidates
files_list = None
output_out_dir = None
if f.from_output:
logger.debugl(2, '- From output `{}`'.format(f.from_output))
out = RegOutput.get_output(f.from_output)
if out is not None:
config_output(out)
out_dir = get_output_dir(out.dir, out, dry=True)
files_list = out.get_targets(out_dir)
logger.debugl(2, '- List of files: {}'.format(files_list))
if out_dir not in dirs_list:
dirs_list.append(out_dir)
else:
if out is None:
logger.error('Unknown output `{}` selected in {}'.format(f.from_output, self._parent))
exit(WRONG_ARGUMENTS)
config_output(out)
output_out_dir = out_dir = get_output_dir(out.dir, out, dry=True)
files_list = out.get_targets(out_dir)
logger.debugl(2, '- List of files: {}'.format(files_list))
if out_dir not in dirs_list:
dirs_list.append(out_dir)
if not no_out_run:
extra_files = []
for file in files_list:
@ -187,6 +191,10 @@ class CompressOptions(BaseOptions):
if GS.debug_level > 1:
files_list = list(files_list)
logger.debug('- Pattern {} list of files: {}'.format(source, files_list))
# Compute the reference dir when no f.dest
out_dir = out_dir_cwd if f.from_cwd else out_dir_default
if f.from_output_dir:
out_dir = output_out_dir
# Filter and adapt them
for fname in filter(re.compile(f.filter).match, files_list):
fname_real = os.path.realpath(fname) if self.follow_links else os.path.abspath(fname)
@ -198,7 +206,6 @@ class CompressOptions(BaseOptions):
if f.dest:
dest = os.path.join(f.dest, os.path.basename(fname))
else:
out_dir = out_dir_cwd if f.from_cwd else out_dir_default
dest = os.path.relpath(dest, out_dir)
files[fname_real] = dest
return files, dirs_list