Skip to content

Commit

Permalink
Merge pull request #198 from INTI-CMNB/colon_sep_option
Browse files Browse the repository at this point in the history
Added a command line option to exclude `:` as INI delimiter
  • Loading branch information
SchrodingersGat authored Jan 30, 2024
2 parents 6a53771 + 0c03bca commit 8fea8b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ optional arguments:
not specified here)
-s SEPARATOR, --separator SEPARATOR
CSV Separator (default ',')
-k, --no-colon-sep Don't use : as delimiter in the config file
--version show program's version number and exit
~~~~
Expand All @@ -98,6 +100,8 @@ optional arguments:

**-s --separator** Override the delimiter for CSV or TSV generation

**-k --no-colon-sep** Only accept `=` as a delimiter for KEY/VALUE pairs in the config file, enables the use of `:` in field names

--------
To run from KiCad, simply add the same command line in the *Bill of Materials* script window. e.g. to generate a HTML output:

Expand Down
3 changes: 2 additions & 1 deletion kibom/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def main():
parser.add_argument("-d", "--subdirectory", help="Subdirectory within which to store the generated BoM files.", type=str, default=None)
parser.add_argument("--cfg", help="BoM config file (script will try to use 'bom.ini' if not specified here)")
parser.add_argument("-s", "--separator", help="CSV Separator (default ',')", type=str, default=None)
parser.add_argument("-k", "--no-colon-sep", help="Don't use : as delimiter in the config file", action='store_true')
parser.add_argument('--version', action='version', version="KiBOM Version: {v}".format(v=KIBOM_VERSION))

args = parser.parse_args()
Expand Down Expand Up @@ -221,7 +222,7 @@ def main():
have_cfile = os.path.exists(config_file)

if have_cfile:
pref.Read(config_file)
pref.Read(config_file, no_colon_sep=args.no_colon_sep)
debug.message("Configuration file:", config_file)
else:
pref.Write(config_file)
Expand Down
4 changes: 2 additions & 2 deletions kibom/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ def checkStr(self, opt, default=False):
return default

# Read KiBOM preferences from file
def Read(self, file, verbose=False):
def Read(self, file, verbose=False, no_colon_sep=False):
file = os.path.abspath(file)
if not os.path.exists(file) or not os.path.isfile(file):
debug.error("{f} is not a valid file!".format(f=file))
return

cf = ConfigParser.RawConfigParser(allow_no_value=True)
cf = ConfigParser.RawConfigParser(allow_no_value=True, delimiters=('=') if no_colon_sep else ('=', ':'))
self.parser = cf
cf.optionxform = str

Expand Down

0 comments on commit 8fea8b1

Please sign in to comment.