Compare commits

...

4 Commits

Author SHA1 Message Date
34e5b107ff Updated 'README.md' with more help
All checks were successful
ydeng/renamebycsv/pipeline/head This commit looks good
2023-04-26 13:52:01 -05:00
70af81ed84 Preparing for 0.0.7 release 2023-04-26 13:47:34 -05:00
b745915e49 Added some more logging to the INFO level 2023-04-26 13:47:09 -05:00
c6d79c9eb1 Fixed bug where CLI wouldn't run
Caused by wrong argument name parameter for run function
2023-04-26 13:44:27 -05:00
4 changed files with 24 additions and 3 deletions

View File

@ -32,3 +32,11 @@ This program makes heavy use of REGEX, also known as Regular Expression to give
Let's say we have files `run325-a-1.vcf`, `run326-b-2.vcf`, and `run327-b-3.vcf`. If we know that all that matters is the `1` after the `run[numbers]-[character]-`, we can write `run\d+-\w-(\d).vcf` which will match with all 3 of the above examples, and select the last digit. The program can then use a given CSV to look up the selected digits and replace the name with what is given by the CSV.
For learning and testing your own REGEX, checkout [regex101.com](https://regex101.com/), which allows you to write the strings that you're trying to match, and the REGEX. It will show you live which parts of the strings match to what, if any parts match.
## Not Working?
If the program is not working the way you would like it, try running the program in `-v DEBUG` mode which increases verbosity. Typically, files not being renamed can be attributed to one of two problems:
1. It's looking in the wrong directory. The solution would be to double check that the directory it's looking in (printed by the program each run) is correct. If not, try adding quotes around the path in the command line.
2. The provided REGEX pattern isn't matching to any of the files. In this case, test one or two of the files at [regex101.com](https://regex101.com/) with your pattern.

View File

@ -7,7 +7,7 @@ from renamebycsv.renamer import find_all_candidates, rename_by_csv
def run(args):
candidates = find_all_candidates(args.input_dir, args.regex, args.recursive)
candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive)
rename_by_csv(
args.csv,
candidates,

View File

@ -6,6 +6,12 @@ from typing import Iterable
def find_all_candidates(input_dir: str, regex: str, recursive: bool):
logging.info(
'Searching "%s" for files that match "%s" %s',
input_dir,
regex,
"recursively" if recursive else "non-recursively",
)
results = []
for subitem in os.listdir(input_dir):
subitem_path = os.path.join(input_dir, subitem)
@ -19,6 +25,13 @@ def find_all_candidates(input_dir: str, regex: str, recursive: bool):
continue
results.append((subitem_path, subitem, match))
logging.debug(f'Collecting "{subitem}"...')
if len(results) < 1:
logging.info(
'No results found matching "%s" in "%s". Please double check your REGEX '
"pattern and directory being searched.",
regex,
input_dir,
)
return results

View File

@ -1,6 +1,6 @@
[metadata]
name = renamebycsv
version = 0.0.6
version = 0.0.7
[options]
packages = renamebycsv