Compare commits

..

2 Commits

Author SHA1 Message Date
59cfe486aa Bumped package version
All checks were successful
ydeng/csvbyname/pipeline/head This commit looks good
2023-04-23 14:44:03 -05:00
266a611fea Fixed inconsistent CSV writing function
All checks were successful
ydeng/csvbyname/pipeline/head This commit looks good
2023-04-23 14:42:44 -05:00
4 changed files with 17 additions and 11 deletions

1
.vscode/launch.json vendored
View File

@ -13,6 +13,7 @@
"${workspaceFolder}/tests/resources", "${workspaceFolder}/tests/resources",
"${workspaceFolder}/output.csv", "${workspaceFolder}/output.csv",
"-r", "-r",
"-n",
"-p", "-p",
"group_num:group(\\d)-\\w-\\d+\\.txt", "group_num:group(\\d)-\\w-\\d+\\.txt",
"group(\\d)-(?P<sect>\\w)-(?P<patid>\\d+)\\.txt", "group(\\d)-(?P<sect>\\w)-(?P<patid>\\d+)\\.txt",

View File

@ -63,6 +63,7 @@ def main():
"Alternatively, use named REGEX groups.", "Alternatively, use named REGEX groups.",
nargs="+", nargs="+",
type=str, type=str,
required=True
) )
argparser.add_argument( argparser.add_argument(
"-n", "-n",

View File

@ -72,20 +72,24 @@ def collect_files(
def write_collected_to_csv( def write_collected_to_csv(
output_path: str, collected: dict[str, dict[str, str]], property_keys: Iterable[str] output_path: str,
collected: dict[str, dict[str, str]],
property_keys: Iterable[str],
output_basename: bool,
): ):
with open(output_path, "w") as output_fd: with open(output_path, "w") as output_fd:
s_property_keys = sorted(property_keys) s_property_keys = sorted(property_keys)
header = ["path", *s_property_keys] header = ["path"]
if output_basename:
header.append("basename")
header.extend(s_property_keys)
writer = csv.writer(output_fd) writer = csv.writer(output_fd)
writer.writerow(header) writer.writerow(header)
for full_path, properties in collected.items(): for full_path, properties in collected.items():
writer.writerow( row = [full_path]
[ if output_basename:
full_path, row.append(os.path.basename(full_path))
*( row.extend(
properties[k] if k in properties else "N/A" (properties[k] if k in properties else "N/A" for k in s_property_keys)
for k in s_property_keys
),
]
) )
writer.writerow(row)

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = csvbyname name = csvbyname
version = 0.0.4 version = 0.0.5
author = Harrison author = Harrison
[options] [options]