-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
executable file
·70 lines (57 loc) · 2.1 KB
/
runner.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
66
67
68
69
#!/usr/bin/env python
# coding: utf-8
import argparse
import pystache
import subprocess
from time import sleep
import datetime
from os import listdir
from os.path import isfile, join
def folder_to_occurs(folder="tifs", pattern=".tif"):
"""
Get a list of occurs inside a folder based on the pattern
"""
file_list = []
for filename in listdir(folder):
if isfile(join(folder, filename)):
sufix_to_ignore = len(pattern) * -1
file_list.append(filename[0:sufix_to_ignore])
return list(set(file_list))
def create_descriptors(occurs):
"""
Generate a new descriptor file
"""
#images_folder = "/home/rafael/Desktop/rafael_ubuntu/tifs/"
images_folder = "/home/roger/workspacepy/aligning_images/tifs"
for filename in occurs:
with open('templates/descriptor.txt', 'rb') as descriptor:
content = pystache.render(descriptor.read(), {'filename': filename,
'folder': images_folder})
file = open("descriptors/{0}.txt".format(filename), "w")
file.write(content)
file.close()
def execute_command(occurs):
"""
Execute a command for each occurs
"""
output_folder = "/home/roger/workspacepy/aligning_images/outputs"
descriptor_folder = "/home/roger/workspacepy/aligning_images/descriptors"
for filename in occurs:
cmd = "PTmender -o {0}/{1} {2}/{3}.txt".format(
output_folder,
filename,
descriptor_folder,
filename)
print " -->", cmd
subprocess.Popen(cmd, shell=True, executable='/bin/bash')
sleep(5)
parser = argparse.ArgumentParser(description='Script runner')
parser.add_argument('--folder', help='Folder for locating files. I.e: tifs/')
parser.add_argument('--pattern', help='Pattern to ignore. I.e: _?.tif')
args = parser.parse_args()
if args.folder:
d0 = datetime.datetime.now()
occurs = folder_to_occurs(args.folder, args.pattern)
create_descriptors(occurs)
execute_command(occurs)
print "--------->END", datetime.datetime.now() - d0