mirror of
https://github.com/oDinZu/callirhoe.git
synced 2025-02-22 00:04:52 -05:00
Made sys.path manipulation in load_plugin a bit more pythonic.
Removed 2nd "try" inside plugin.py and made first work as George suggested. Reverted to "resource:" to make it feel correct. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@181 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df
This commit is contained in:
parent
3a50df8572
commit
eac11c2455
@ -84,13 +84,12 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset):
|
||||
for path in plugin_paths:
|
||||
found += available_files(path, cat, preset)
|
||||
if len(found) == 0: raise IOError
|
||||
if found[0][1] == "/":
|
||||
if found[0][1] == "resource:":
|
||||
m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ])
|
||||
else:
|
||||
old = sys.path[0]
|
||||
sys.path[0] = found[0][1]
|
||||
sys.path.insert(0, found[0][1])
|
||||
m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ])
|
||||
sys.path[0] = old
|
||||
sys.path.pop(0)
|
||||
return m
|
||||
except IOError:
|
||||
sys.exit("callirhoe: %s definition '%s' not found, use %s to see available definitions" % (longcat,
|
||||
|
@ -29,7 +29,7 @@ import glob
|
||||
try:
|
||||
import resources
|
||||
except:
|
||||
pass
|
||||
resources = None
|
||||
|
||||
def available_files(parent, dir, fmatch = None):
|
||||
"""find parent/dir/*.py files to be used for plugins
|
||||
@ -43,7 +43,7 @@ def available_files(parent, dir, fmatch = None):
|
||||
good = False
|
||||
res = []
|
||||
pattern = parent + "/" + dir + "/*.py"
|
||||
for x in glob.glob(pattern) if parent != "/" else resources.resource_list[dir]:
|
||||
for x in glob.glob(pattern) if not parent.startswith('resource:') else resources.resource_list[dir]:
|
||||
basex = os.path.basename(x)
|
||||
if basex == "__init__.py": good = True
|
||||
elif basex.startswith('_'):
|
||||
@ -78,9 +78,6 @@ def get_plugin_paths():
|
||||
@rtype: [str,str,..]
|
||||
"""
|
||||
result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ]
|
||||
try:
|
||||
temp = resources.resource_list
|
||||
result.append("/")
|
||||
except:
|
||||
pass
|
||||
if resources:
|
||||
result.append("resource:")
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user