Added support for compressed YAML files.

This commit is contained in:
Salvador E. Tropea 2020-06-14 11:05:08 -03:00
parent 61f1ebbab2
commit 4101f69cd4
7 changed files with 19 additions and 22 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### Added
- Better debug information when a BoM fails to be generated. - Better debug information when a BoM fails to be generated.
- Support for compressed YAML files.
### Changed ### Changed
- Allowed operations that doesn't involve a PCB now can run if the PCB file is - Allowed operations that doesn't involve a PCB now can run if the PCB file is
missing or corrupted. missing or corrupted.

View File

@ -29,8 +29,9 @@ Kiplot uses a configuration file where you can specify what *outputs* to
generate. By default you'll generate all of them, but you can specify which generate. By default you'll generate all of them, but you can specify which
ones from the command line. ones from the command line.
The configuration file should be named **.kiplot.yaml*. The format used is The configuration file should be named **.kiplot.yaml**. The format used is
[YAML](https://yaml.org/). This is basically a text file with some structure. [YAML](https://yaml.org/). This is basically a text file with some structure.
This file can be compressed using *gzip* file format.
### The header ### The header

View File

@ -9,6 +9,7 @@ __status__ = 'beta'
import argparse import argparse
import os import os
import sys import sys
import gzip
from glob import glob from glob import glob
# Import log first to set the domain # Import log first to set the domain
@ -91,6 +92,11 @@ def main():
cr = config_reader.CfgYamlReader(board_file) cr = config_reader.CfgYamlReader(board_file)
try:
# The Python way ...
with gzip.open(plot_config) as cf_file:
cfg = cr.read(cf_file)
except gzip.BadGzipFile:
with open(plot_config) as cf_file: with open(plot_config) as cf_file:
cfg = cr.read(cf_file) cfg = cr.read(cf_file)

View File

@ -11,6 +11,7 @@ We test (both CSV and ASCII):
- without 'comment' field - without 'comment' field
- with coloured logs - with coloured logs
- in quiet mode - in quiet mode
- compressed YAML file
For debug information use: For debug information use:
pytest-3 --log-cli-level debug pytest-3 --log-cli-level debug
@ -133,7 +134,8 @@ def test_3Rs_position_unified_th_csv():
def test_3Rs_position_inches_csv(): def test_3Rs_position_inches_csv():
ctx = context.TestContext('3Rs_position_inches_csv', '3Rs', 'simple_position_inches_csv', POS_DIR) """ Also test a compressed configuration YAML file """
ctx = context.TestContext('3Rs_position_inches_csv', '3Rs', 'simple_position_inches_csv', POS_DIR, yaml_compressed=True)
ctx.run() ctx.run()
pos_top = ctx.get_pos_top_csv_filename() pos_top = ctx.get_pos_top_csv_filename()
pos_bot = ctx.get_pos_bot_csv_filename() pos_bot = ctx.get_pos_bot_csv_filename()

View File

@ -19,7 +19,7 @@ MODE_PCB = 0
class TestContext(object): class TestContext(object):
def __init__(self, test_name, board_name, yaml_name, sub_dir): def __init__(self, test_name, board_name, yaml_name, sub_dir, yaml_compressed=False):
# We are using PCBs # We are using PCBs
self.mode = MODE_PCB self.mode = MODE_PCB
# The name used for the test output dirs and other logging # The name used for the test output dirs and other logging
@ -29,7 +29,7 @@ class TestContext(object):
# The actual board file that will be loaded # The actual board file that will be loaded
self._get_board_file() self._get_board_file()
# The YAML file we'll use # The YAML file we'll use
self._get_yaml_name(yaml_name) self._get_yaml_name(yaml_name, yaml_compressed)
# The actual output dir for this run # The actual output dir for this run
self._set_up_output_dir(pytest.config.getoption('test_dir')) self._set_up_output_dir(pytest.config.getoption('test_dir'))
# Where are we expecting to get the outputs (inside test_name) # Where are we expecting to get the outputs (inside test_name)
@ -54,8 +54,10 @@ class TestContext(object):
this_dir = os.path.dirname(os.path.realpath(__file__)) this_dir = os.path.dirname(os.path.realpath(__file__))
return os.path.join(this_dir, '../yaml_samples') return os.path.join(this_dir, '../yaml_samples')
def _get_yaml_name(self, name): def _get_yaml_name(self, name, yaml_compressed):
self.yaml_file = os.path.abspath(os.path.join(self._get_yaml_dir(), name+'.kiplot.yaml')) self.yaml_file = os.path.abspath(os.path.join(self._get_yaml_dir(), name+'.kiplot.yaml'))
if yaml_compressed:
self.yaml_file += '.gz'
logging.info('YAML file: '+self.yaml_file) logging.info('YAML file: '+self.yaml_file)
assert os.path.isfile(self.yaml_file) assert os.path.isfile(self.yaml_file)

View File

@ -1,15 +0,0 @@
# Example KiPlot config file for a basic 2-layer board
kiplot:
version: 1
outputs:
- name: 'position'
comment: "Pick and place file"
type: position
dir: positiondir
options:
format: CSV # CSV or ASCII format
units: inches # millimeters or inches
separate_files_for_front_and_back: true
only_smd: true