def setUp(self): super(TestXMLRPCTransport, self).setUp() self.server = self.server_class() self.server.start_server() self.addCleanup(self.server.stop_server) # Ensure we don't clobber env self.overrideEnv('BRZ_LP_XMLRPC_URL', None) # Ensure we use the right certificates for https. # FIXME: There should be a better way but the only alternative I can # think of involves carrying the ca_certs through the lp_registration # infrastructure to _urllib2_wrappers... -- vila 2012-01-20 breezy.get_global_state().cmdline_overrides._from_cmdline( ['ssl.ca_certs=%s' % ssl_certs.build_path('ca.crt')])
def load_plugins(path=None, state=None): """Load breezy plugins. The environment variable BRZ_PLUGIN_PATH is considered a delimited set of paths to look through. Each entry is searched for `*.py` files (and whatever other extensions are used in the platform, such as `*.pyd`). :param path: The list of paths to search for plugins. By default, it is populated from the __path__ of the breezy.plugins package. :param state: The library state object that records loaded plugins. """ if state is None: state = breezy.get_global_state() if getattr(state, 'plugins', None) is not None: # People can make sure plugins are loaded, they just won't be twice return if path is None: # Calls back into extend_path() here from breezy.plugins import __path__ as path state.plugin_warnings = {} _load_plugins_from_path(state, path) if (None, 'entrypoints') in _env_plugin_path(): _load_plugins_from_entrypoints(state) state.plugins = plugins()
def describe_plugins(show_paths=False, state=None): """Generate text description of plugins. Includes both those that have loaded, and those that failed to load. :param show_paths: If true, include the plugin path. :param state: The library state object to inspect. :returns: Iterator of text lines (including newlines.) """ if state is None: state = breezy.get_global_state() loaded_plugins = getattr(state, 'plugins', {}) plugin_warnings = set(getattr(state, 'plugin_warnings', [])) all_names = sorted(set(loaded_plugins.keys()).union(plugin_warnings)) for name in all_names: if name in loaded_plugins: plugin = loaded_plugins[name] version = plugin.__version__ if version == 'unknown': version = '' yield '%s %s\n' % (name, version) d = plugin.module.__doc__ if d: doc = d.split('\n')[0] else: doc = '(no description)' yield (" %s\n" % doc) if show_paths: yield (" %s\n" % plugin.path()) else: yield "%s (failed to load)\n" % name if name in state.plugin_warnings: for line in state.plugin_warnings[name]: yield " ** " + line + '\n' yield '\n'
def test_apport_report(self): crash_dir = osutils.joinpath((self.test_base_dir, 'crash')) os.mkdir(crash_dir) self.overrideEnv('APPORT_CRASH_DIR', crash_dir) self.assertEqual(crash_dir, config.crash_dir()) self.overrideAttr(breezy.get_global_state(), 'plugin_warnings', {'example': ['Failed to load plugin foo']}) stderr = StringIO() try: raise AssertionError("my error") except AssertionError as e: crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr) # message explaining the crash self.assertContainsRe(stderr.getvalue(), " apport-bug %s" % crash_filename) with open(crash_filename) as crash_file: report = crash_file.read() self.assertContainsRe(report, '(?m)^BrzVersion:') # should be in the traceback self.assertContainsRe(report, 'my error') self.assertContainsRe(report, 'AssertionError') # see https://bugs.launchpad.net/bzr/+bug/528114 self.assertContainsRe(report, 'ExecutablePath') self.assertContainsRe(report, 'test_apport_report') # should also be in there self.assertContainsRe(report, '(?m)^CommandLine:') self.assertContainsRe(report, 'Failed to load plugin foo')
def format_concise_plugin_list(state=None): """Return a string holding a concise list of plugins and their version. """ if state is None: state = breezy.get_global_state() items = [] for name, a_plugin in sorted(getattr(state, 'plugins', {}).items()): items.append("%s[%s]" % (name, a_plugin.__version__)) return ', '.join(items)
def disable_plugins(state=None): """Disable loading plugins. Future calls to load_plugins() will be ignored. :param state: The library state object that records loaded plugins. """ if state is None: state = breezy.get_global_state() state.plugins = {}
def __init__(self): self.counts = weakref.WeakKeyDictionary() client._SmartClient.hooks.install_named_hook('call', self.increment_call_count, 'hpss call counter') breezy.get_global_state().exit_stack.callback(self.flush_all)
def setup_fake_plugins(self): fake = plugin.PlugIn('fake_plugin', plugin) fake.version_info = lambda: (1, 2, 3) fake_plugins = {"fake_plugin": fake} self.overrideAttr(breezy.get_global_state(), 'plugins', fake_plugins)