Skip to content

Commit

Permalink
Basename (#130)
Browse files Browse the repository at this point in the history
* Bump version number

* Back to dev.

* Addition of basename to output from list_templates.

* Flake 8

* Flake 8

* change of basename to name in returned object (from list_templates)

Use of name in matching templates.

* Removal of cwd from default paths if CSV2BUFR_TEMPLATES set.

* use .stem.
  • Loading branch information
david-i-berry authored Feb 14, 2024
1 parent 586673f commit f7890eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion csv2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
###############################################################################

__version__ = '0.8.0'
__version__ = '0.8.1'

import csv
from datetime import timezone, datetime
Expand Down
17 changes: 14 additions & 3 deletions csv2bufr/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
THISDIR = os.path.dirname(os.path.realpath(__file__))
LOGGER = logging.getLogger(__name__)
SCHEMA = f"{THISDIR}{os.sep}resources{os.sep}schema"
TEMPLATE_DIRS = [Path("./")]
TEMPLATE_DIRS = [] # [Path("./")]

_SUCCESS_ = True

Expand All @@ -47,10 +47,20 @@
LOGGER.error(msg)
raise RuntimeError(msg)

_template_flag = False
# Set user defined location first
if 'CSV2BUFR_TEMPLATES' in os.environ:
TEMPLATE_DIRS.append(Path(os.environ['CSV2BUFR_TEMPLATES']))
else:
TEMPLATE_DIRS.append(Path("./"))
_template_flag = True

# Check if /opt/csv2bur/templates exists and add to search path
if Path("/opt/csv2bufr/templates").exists() and \
"/opt/csv2bufr/templates" not in TEMPLATE_DIRS:
TEMPLATE_DIRS.append(Path("/opt/csv2bufr/templates"))

if _template_flag:
LOGGER.warning(f"""CSV2BUFR_TEMPLATES is not set, default search path(s)
will be used ({TEMPLATE_DIRS}).""")

Expand Down Expand Up @@ -81,7 +91,7 @@ def load_template(template_name: str) -> Union[dict, None]:
msg = f"Requested template {template_name} not found, " +\
"searching by file name"
for _template in TEMPLATES.values():
if template_name in _template.get('path'):
if template_name == _template.get('name'):
fname = _template.get('path')
break
if fname is None:
Expand Down Expand Up @@ -182,7 +192,8 @@ def index_templates() -> bool:
"author": tmpl['metadata'].get("author", ""),
"dateCreated": tmpl['metadata'].get("dateCreated", ""), # noqa
"id": tmpl['metadata'].get("id", ""),
"path": fname
"path": fname,
"name": Path(fname).stem
}

except Exception as e:
Expand Down

0 comments on commit f7890eb

Please sign in to comment.