-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (37 loc) · 1.35 KB
/
Copy pathmain.py
File metadata and controls
40 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import argparse
from test_file import TestFile
def main(in_path, out_path, dry_run):
if os.path.isdir(in_path):
files = os.listdir(in_path)
elif os.path.isfile(in_path):
files = [in_path]
else:
raise FileNotFoundError
files = list(map(lambda x: os.path.join(in_path, x), files))
files = list(filter(lambda x: x.endswith(".xml"), files))
num_files = len(files)
counter = 0
dry_run_output = ""
for file_path in files:
counter += 1
print("Processing file: {}/{}".format(counter, num_files))
file = TestFile(file_path)
file.convert()
if dry_run:
dry_run_output += f"{file_path}\n{"=" * len(file_path)}\n{file.file_contents}\n\n"
else:
if out_path != "":
file.save(os.path.join(out_path, os.path.basename(file_path)))
else:
file.save()
print()
print(dry_run_output)
print("Date conversion successful")
if __name__ == "__main__":
parser = argparse.ArgumentParser("DBUnit date converter")
parser.add_argument('input', help="Input directory path")
parser.add_argument('-o', '--output', default="", help="Output directory path")
parser.add_argument('--dry-run', action='store_true', help="Dry run")
args = parser.parse_args()
main(args.input, args.output, args.dry_run)