-
Notifications
You must be signed in to change notification settings - Fork 0
/
cligeocomp.py
executable file
·84 lines (60 loc) · 1.68 KB
/
cligeocomp.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
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import sys
import time
import os.path
import geocomp
from geocomp import config
from geocomp.gui import dummy
def get_func (strTemp):
listTemp = strTemp.split('/')
if listTemp[0] == 'geocomp':
listTemp.pop (0)
last = listTemp.pop ()
ext = last.rfind ('.py', -4)
#ext = rfind (last, '.py', -4)
if ext != -1:
last = last[:ext]
mod = geocomp
for name in listTemp:
mod = getattr (mod, name)
tempTuple = (list(filter (lambda x, last=last: x[0] == last, mod.children)))[0]
if tempTuple[1] == None: return None
mod = getattr (mod, last)
func = getattr (mod, tempTuple[1])
return func
def run_alg (func, localInput):
init = time.clock ()
cont, extra = geocomp.run_algorithm (func, localInput)
end = time.clock ()
delta = end - init
print(repr(cont), ' ','%.2f'%delta,'s', ' ', extra)
sys.stdout.flush ()
def many_algs (strings):
filename = strings.pop (0)
print(filename, ':')
lInput = geocomp.open_file (filename)
for func_name in strings:
print(os.path.basename (func_name),':', end=' ')
func = get_func (func_name)
run_alg (func, lInput)
def many_files (strings):
func_name = strings.pop (0)
print(func_name,':')
func = get_func (func_name)
for filename in strings:
print(os.path.basename (filename),':', end=' ')
lInput = geocomp.open_file (filename)
run_alg (func, lInput)
if __name__ == '__main__':
if len (sys.argv) < 2:
print(sys.argv[0], '<algorithm> <file1> [file2]...')
print(sys.argv[0], '-a <file1> <algorithm1> [algorithm2]...')
sys.exit (1)
geocomp.init_display (dummy, None)
if sys.argv[1] == '-a':
sys.argv.pop (0)
sys.argv.pop (0)
many_algs (sys.argv)
else:
sys.argv.pop (0)
many_files (sys.argv)