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:
ph4ntome@gmail.com 2014-10-31 16:51:54 +00:00
parent 3a50df8572
commit eac11c2455
3 changed files with 8 additions and 12 deletions

View File

@ -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,

View File

@ -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

View File

@ -2,7 +2,7 @@
# Create Callirhoe package
mkdir _callirhoe
./make_resources_list > resources.py
./make_resources_list
cp -R geom holidays lang layouts lib style _callirhoe
cp callirhoe.py _callirhoe/__main__.py
mv resources.py _callirhoe/lib