13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""bzr python plugin support.
53
52
from bzrlib import plugins as _mod_plugins
56
from bzrlib.symbol_versioning import deprecated_function, one_three
55
from bzrlib.symbol_versioning import deprecated_function
59
58
DEFAULT_PLUGIN_PATH = None
254
253
trace.print_exception(sys.exc_info(), sys.stderr)
257
@deprecated_function(one_three)
258
def load_from_zip(zip_name):
259
"""Load all the plugins in a zip."""
260
valid_suffixes = ('.py', '.pyc', '.pyo') # only python modules/packages
263
index = zip_name.rindex('.zip')
266
archive = zip_name[:index+4]
267
prefix = zip_name[index+5:]
269
trace.mutter('Looking for plugins in %r', zip_name)
271
# use zipfile to get list of files/dirs inside zip
273
z = zipfile.ZipFile(archive)
274
namelist = z.namelist()
276
except zipfile.error:
281
prefix = prefix.replace('\\','/')
282
if prefix[-1] != '/':
285
namelist = [name[ix:]
287
if name.startswith(prefix)]
289
trace.mutter('Names in archive: %r', namelist)
291
for name in namelist:
292
if not name or name.endswith('/'):
295
# '/' is used to separate pathname components inside zip archives
298
head, tail = '', name
300
head, tail = name.rsplit('/',1)
302
# we don't need looking in subdirectories
305
base, suffix = osutils.splitext(tail)
306
if suffix not in valid_suffixes:
309
if base == '__init__':
320
if getattr(_mod_plugins, plugin_name, None):
321
trace.mutter('Plugin name %s already loaded', plugin_name)
325
exec "import bzrlib.plugins.%s" % plugin_name in {}
326
trace.mutter('Load plugin %s from zip %r', plugin_name, zip_name)
327
except KeyboardInterrupt:
330
## import pdb; pdb.set_trace()
331
trace.warning('Unable to load plugin %r from %r'
333
trace.log_exception_quietly()
334
if 'error' in debug.debug_flags:
335
trace.print_exception(sys.exc_info(), sys.stderr)
339
257
"""Return a dictionary of the plugins.
386
304
self.module = module
388
def get_help_text(self, additional_see_also=None):
306
def get_help_text(self, additional_see_also=None, verbose=True):
389
307
"""Return a string with the help for this topic.
391
309
:param additional_see_also: Additional help topics to be