-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcor.py
More file actions
80 lines (67 loc) · 2.68 KB
/
cor.py
File metadata and controls
80 lines (67 loc) · 2.68 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
# This file is part of the OpenWire Framework.
#
# OpenWire is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenWire is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenWIre. If not, see <http://www.gnu.org/licenses/>.
import sys
import glob
import os
class core:
def __init__(self, framework):
self.fw = framework
self._corelist = self.preloadCore()
for core in self._corelist:
if '__init__' in core or '.pyc' in core:
continue
# Create an instance of the library
def loadCore(self, core):
if core == "core." or "__init__" in core or ".pyc" in core:
return False
coref = "core."+str(core)
if not os.path.isfile("core/"+core+".py"):
print self.fw.prompt + " " + coref + " is not a valid library"
return False
coreFile = self.ezImport(coref)
setattr(self, str(core), coreFile(self.fw))
# Import Library
def ezImport(self, name):
components = name.split('.')
comp = components[1]
mod = __import__(name, fromlist=[comp])
mod = getattr(mod, comp)
return mod
# Load modules into global namespace
def preloadCore(self):
sys.path.append("core")
core = glob.glob("core/*.py")
core_files = []
for i in range(len(core)):
self.loadCore(core[i][5:-3])
core[i] = core[i].split(".")[0].split("/")[1]
core[i] = "core."+core[i]
globals()[core[i]] = self.ezImport(core[i])
core_files.append(core[i])
return core_files
# List installed libraries
def listCore(self):
classes = glob.glob("core/*.py")
for i in range(len(classes)):
classes[i] = classes[i].split(".")[0].split("/")[1]
if classes[i] == '__init__':
continue
classes[i] = "core."+classes[i]
if classes[i] in globals():
core = self.ezImport(classes[i])
coreFile = core(self)
#print self.fw.prompt+self.fw.libs.colours.cstring(' ~> ', 'white')+self.fw.libs.colours.cstring(coreFile.name+" - "+coreFile.description, "blue")
coreFile = None
return True