Compare commits
7 Commits
c579c172ef
...
main
Author | SHA1 | Date | |
---|---|---|---|
2edd8a2093 | |||
7a400457fe | |||
59cfe486aa | |||
266a611fea | |||
cb36b8adb3 | |||
ded60aa742 | |||
adf734f3c1 |
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@@ -8,19 +8,20 @@
|
||||
"name": "Use Test Resources",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/csvbyname/csvbyname.py",
|
||||
"console": "integratedTerminal",
|
||||
"args": [
|
||||
"${workspaceFolder}/tests/resources",
|
||||
"${workspaceFolder}/output.csv",
|
||||
"-r",
|
||||
"-n",
|
||||
"-p",
|
||||
"group_num:group(\\d)-\\w-\\d+\\.txt",
|
||||
"group(\\d)-(?P<sect>\\w)-(?P<patid>\\d+)\\.txt",
|
||||
"-V",
|
||||
"DEBUG"
|
||||
],
|
||||
"justMyCode": true
|
||||
"justMyCode": true,
|
||||
"module": "csvbyname.cli"
|
||||
}
|
||||
]
|
||||
}
|
1
Jenkinsfile
vendored
1
Jenkinsfile
vendored
@@ -20,6 +20,7 @@ pipeline {
|
||||
stage("test") {
|
||||
steps {
|
||||
sh "pip install dist/*.whl"
|
||||
sh "csvbyname -h"
|
||||
}
|
||||
}
|
||||
stage("archive") {
|
||||
|
@@ -13,7 +13,7 @@ def run(args):
|
||||
args.recursive,
|
||||
args.add_re_property,
|
||||
)
|
||||
write_collected_to_csv(args.output, collected, pkeys)
|
||||
write_collected_to_csv(args.output, collected, pkeys, args.output_basename)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -63,6 +63,17 @@ def main():
|
||||
"Alternatively, use named REGEX groups.",
|
||||
nargs="+",
|
||||
type=str,
|
||||
required=True
|
||||
)
|
||||
argparser.add_argument(
|
||||
"-n",
|
||||
"--output-basename",
|
||||
help='Adds a column called "basename" to the resulting CSV where it is just '
|
||||
"The base name of the path instead of the entire path. This is not guaranteed "
|
||||
"to be unique.",
|
||||
default=False,
|
||||
required=False,
|
||||
action="store_true",
|
||||
)
|
||||
argparser.add_argument(
|
||||
"-V",
|
||||
|
@@ -72,20 +72,24 @@ def collect_files(
|
||||
|
||||
|
||||
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", newline="", encoding="utf-8") as output_fd:
|
||||
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.writerow(header)
|
||||
for full_path, properties in collected.items():
|
||||
writer.writerow(
|
||||
[
|
||||
full_path,
|
||||
*(
|
||||
properties[k] if k in properties else "N/A"
|
||||
for k in s_property_keys
|
||||
),
|
||||
]
|
||||
row = [full_path]
|
||||
if output_basename:
|
||||
row.append(os.path.basename(full_path))
|
||||
row.extend(
|
||||
(properties[k] if k in properties else "N/A" for k in s_property_keys)
|
||||
)
|
||||
writer.writerow(row)
|
||||
|
Reference in New Issue
Block a user