-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion_json.py
65 lines (55 loc) · 2.09 KB
/
conversion_json.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import subprocess
import glob
import os
# Read the paths from the config file
config = {}
with open(r'C:\Users\wout.decrop\environments\Imagine\flowcytometer\flowcytometer_utils\cyz2json\cyz2json_python\config.txt', 'r') as file:
for line in file:
# Skip empty lines and comments
if line.strip() == '' or line.strip().startswith('#'):
continue
# Split the line by the first occurrence of '='
parts = line.split('=', 1)
# Check if the line follows the key=value format
if len(parts) != 2:
print(f"Ignoring invalid line in config file: {line.strip()}")
continue
key, value = parts
# Remove leading/trailing whitespace from key and value
key = key.strip()
value = value.strip()
config[key] = value
# Extract directory and dotnet program paths from the config dictionary
directory = config.get('directory_path', None)
dotnet_program = config.get('dotnet_program_path', None)
# Ensure the directory and dotnet program paths exist
if not directory or not os.path.isdir(directory):
print("Error: Directory path not provided or does not exist.")
exit(1)
if not dotnet_program or not os.path.isfile(dotnet_program):
print("Error: Dotnet program path not provided or does not exist.")
exit(1)
# Get the list of all .cyz files in the current directory
cyz_files = glob.glob(os.path.join(directory, '*.cyz'))
# Loop through each file and run the dotnet command
for file in cyz_files:
output_file = f"{file}.json"
# Construct the command
command = [
'dotnet',
dotnet_program,
file,
'--output',
output_file
]
print(command)
try:
# Run the command
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Successfully processed {file}")
print(f"Output: {result.stdout}")
except subprocess.CalledProcessError as e:
print(f"Error processing {file}")
print(f"Error: {e.stderr}")
# Make sure to handle potential errors
print("Finished processing all files.")