Skip to content

Commit

Permalink
Add a flag to keep the original names
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Apr 3, 2023
1 parent 0bec07f commit df4db06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Charidotella (https://en.wikipedia.org/wiki/Charidotella_sexpunctata) is a toolb
1. Install the Python package

```sh
python3 -m pip install --user charidotella
python3 -m pip install charidotella
```

2. Create a directory _my-wonderful-project_ with the following structure (the file names do not matter as long as their extension is _.es_)
Expand Down
19 changes: 18 additions & 1 deletion charidotella/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def main():
action="store_true",
help="Replace the configuration if it exists",
)
configure_parser.add_argument(
"--preserve-names",
"-p",
action="store_true",
help="Do not generate new names for the recordings",
)
run_parser = subparsers.add_parser("run", help="Process a configuration file")
run_parser.add_argument(
"--configuration",
Expand Down Expand Up @@ -311,7 +317,18 @@ def run_generators(configuration: dict[str, typing.Any]):
paths.sort(key=lambda path: (path.stem, path.parent))
if len(paths) == 0:
utilities.error(f'no .es files found in "{directory}"')
names = animals.generate_names(len(paths))
if args.preserve_names:
names = [path.stem for path in paths]
if len(names) != len(set(names)):
name_to_path: dict[str, pathlib.Path] = {}
for path in paths:
if path.stem in name_to_path:
utilities.error(
f'two files have the same name ("{name_to_path[path.stem]}" and "{path}"), rename one or do *not* use the flag --preserve-name'
)
name_to_path[path.stem] = path
else:
names = animals.generate_names(len(paths))
attachments: dict[str, list[dict[str, str]]] = {}
for name, path in zip(names, paths):
for sibling in path.parent.iterdir():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

setuptools.setup(
name="charidotella",
version="0.5",
version="0.6",
url="https://github.com/neuromorphicsystems/charidotella",
author="Alexandre Marcireau",
author_email="alexandre.marcireau@gmail.com",
Expand Down

0 comments on commit df4db06

Please sign in to comment.