aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorNiall Douglas (a [underscors] sourceforge {at} nedprod [dot] com) <spam@spamtrap.com>2012-02-24 14:35:04 -0500
committerW. Trevor King <wking@tremily.us>2012-08-23 12:35:48 -0400
commite55730c6b0737e3edb4ff407c12b34b5390ef4a1 (patch)
tree43aa35c981a0ae9beb0510e59f45c50f63ffd168 /libbe
parent4ee1b33812e3eb9f43406601245b8bc6aa2ed632 (diff)
downloadbugseverywhere-e55730c6b0737e3edb4ff407c12b34b5390ef4a1.tar.gz
Cherrypick initial zipfile support from Niall Douglas.
WTK: This is a portion of Niall's commit 7f7a7738bcbcfd06a026f2985c1823a4ba5eb55b Author: Niall Douglas ... Date: Tue Feb 21 20:35:28 2012 +0000 Several hacks to make BE compatible with bbfreeze and therefore compilable into a self contained directory
Diffstat (limited to 'libbe')
-rw-r--r--libbe/util/plugin.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/libbe/util/plugin.py b/libbe/util/plugin.py
index 211e608..1fee690 100644
--- a/libbe/util/plugin.py
+++ b/libbe/util/plugin.py
@@ -27,6 +27,7 @@ submodules (i.e. "plugins").
import os
import os.path
import sys
+import zipfile
_PLUGIN_PATH = os.path.realpath(
@@ -52,6 +53,15 @@ def import_by_name(modname):
module = getattr(module, comp)
return module
+def ziplistdir(path):
+ """Lists items in a directory contained in a zip file"""
+ zipidx=path.find('.zip')
+ zippath=path[:4+zipidx]
+ path=path[5+zipidx:].replace(os.sep, '/')
+ with zipfile.ZipFile(zippath, 'r') as zf:
+ files=[f[len(path)+1:] for f in zf.namelist() if f[:len(path)]==path and '/' not in f[len(path)+1:]]
+ return files
+
def modnames(prefix):
"""
>>> 'list' in [n for n in modnames('libbe.command')]
@@ -60,10 +70,25 @@ def modnames(prefix):
True
"""
components = prefix.split('.')
- modfiles = os.listdir(os.path.join(_PLUGIN_PATH, *components))
+ modfilespath=os.path.join(_PLUGIN_PATH, *components)
+ # Cope if we are executing from inside a zip archive full of precompiled .pyc's
+ modfiles=ziplistdir(modfilespath) if '.zip' in modfilespath else os.listdir(modfilespath)
modfiles.sort()
+ # Eliminate .py/.pyc duplicates
+ print modfiles
+ x=1
+ while x<len(modfiles):
+ if modfiles[x].endswith('.pyc') and modfiles[x-1]==modfiles[x][:len(modfiles[x-1])]:
+ del modfiles[x-1]
+ else:
+ x+=1
+ print modfiles
for modfile in modfiles:
if modfile.startswith('.'):
continue # the occasional emacs temporary file
- if modfile.endswith('.py') and modfile != '__init__.py':
+ if modfile == '__init__.py' or modfile == '__init__.pyc':
+ continue
+ if modfile.endswith('.py'):
yield modfile[:-3]
+ elif modfile.endswith('.pyc'):
+ yield modfile[:-4]