-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
99 lines (82 loc) · 2.93 KB
/
__init__.py
File metadata and controls
99 lines (82 loc) · 2.93 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import sys
import math
import settings
def _force_reload_of_gx():
keys_to_delete = []
for key in sys.modules:
if key[:3] == 'gx.':
keys_to_delete.append(key)
for key in keys_to_delete:
del sys.modules[key]
if settings.DEBUG:
_force_reload_of_gx()
from gx.libs.vectormath import *
from gx.libs.app import *
from gx.libs.form import *
from gx.libs.robots import *
__author__ = 'Stefan Hechenberger <stefan@nortd.com>'
__version__ = '2013.02'
__license__ = 'GPL3'
__docformat__ = 'restructuredtext en'
_appcontext = {}
def _find_main(name, appsloc):
app_to_run = None
items = os.listdir(appsloc)
for item in items:
if item == name+'.py' and os.path.isfile(os.path.join(appsloc, item)):
print item
# got a match
if not app_to_run:
app_to_run = os.path.join(appsloc, item)
else:
print "WARN: multiple apps with this name"
elif item == name and os.path.isdir(os.path.join(appsloc, item)):
currentapploc = os.path.join(appsloc, item)
appitems = os.listdir(currentapploc)
if name+'.py' in appitems:
# got a match
if not app_to_run:
app_to_run = os.path.join(currentapploc, name+'.py')
else:
print "WARN: multiple apps with this name"
elif 'main.py' in appitems:
# got a match
if not app_to_run:
app_to_run = os.path.join(currentapploc, 'main.py')
else:
print "WARN: multiple apps with this name"
return app_to_run
def run(name):
"""Run an app from the apps folder.
First looks for name+'.py' then for name/name+'.py'
then for name/main.py
returns: module vars from the app that are listed
by _return_. If only one is listed then it is returned
directly. If many then a dict is returned.
"""
global _appcontext
app_to_run = None
thisloc = os.path.dirname(os.path.realpath(__file__))
app_to_run = _find_main(name, os.path.join(thisloc, 'apps'))
if not app_to_run:
app_to_run = _find_main(name, os.path.join(thisloc, 'examples'))
if not app_to_run:
app_to_run = _find_main(name, os.path.join(thisloc, 'tests'))
if app_to_run:
print "INFO: running " + app_to_run
globals_other = {}
# exec open(app_to_run).read()
execfile(app_to_run, globals_other)
_appcontext = globals_other
# _appcontext = globals_other
# if globals_other.has_key('_return_'):
# retlist = globals_other['_return_']
# if len(retlist) == 1:
# return globals_other.get(retlist[0])
# elif len(retlist) > 1:
# return dict((k, globals_other[k]) for k in retlist)
else:
print "ERROR: app not found"
def get(name):
return _appcontext.get(name)