-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_tcore_sol.py
More file actions
executable file
·40 lines (27 loc) · 941 Bytes
/
clean_tcore_sol.py
File metadata and controls
executable file
·40 lines (27 loc) · 941 Bytes
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
import click
from os.path import join
@click.command()
@click.argument('solution')
def main(solution):
''' The result of this script is a file named 'clean_SOLUTION'
placed into the same folder of SOLUTION'''
input_sol_path = solution
with open(input_sol_path, 'r') as fin:
strips_sol = fin.read()
splitted_sol = strips_sol.split('\n')
new_plan_actions = [action.replace('__', ' ') for action in splitted_sol]
lifted_sol = '\n'.join(new_plan_actions)
path_sol = get_path(input_sol_path)
name_sol = get_name(input_sol_path)
lifted_path = join(path_sol, 'clean_{}'.format(name_sol))
with open(lifted_path, 'w') as fout:
fout.write(lifted_sol)
print(lifted_path)
def get_name(path):
return path.split('/')[-1]
def get_path(path):
if len(path.split('/')) == 1:
return ''
return '/'.join(path.split('/')[0:-1])
if __name__ == "__main__":
main()