def aliases(self): for alias, expansion in config.GlobalConfig().get_aliases().iteritems( ): for token in cmdline.split(expansion): if not token.startswith("-"): self.user_aliases.setdefault(token, set()).add(alias) break
def test_lock_without_email(self): global_config = config.GlobalConfig() # Intentionally has no email address global_config.set_user_option('email', 'User Identity') ld1 = self.get_lock() ld1.create() ld1.lock_write() ld1.unlock()
def install(): global _translation if not os.environ.get('LANGUAGE'): from bzrlib import config lang = config.GlobalConfig().get_user_option('language') if lang: os.environ['LANGUAGE'] = lang if sys.platform == 'win32': _check_win32_locale() _translation = _gettext.translation('qbzr', localedir=_get_locale_dir(), fallback=True)
def test_gather_user_credentials_prompts(self): service = LaunchpadService() self.assertIs(None, service.registrant_password) g_conf = config.GlobalConfig() g_conf.set_user_option('email', 'Test User <*****@*****.**>') stdout = tests.StringIOWrapper() ui.ui_factory = tests.TestUIFactory(stdin='userpass\n', stdout=stdout) self.assertIs(None, service.registrant_password) service.gather_user_credentials() self.assertEqual('*****@*****.**', service.registrant_email) self.assertEqual('userpass', service.registrant_password) self.assertContainsRe(stdout.getvalue(), 'launchpad.net password for test@user\\.com')
def gather_user_credentials(self): """Get the password from the user.""" the_config = config.GlobalConfig() self.registrant_email = the_config.user_email() if self.registrant_password is None: auth = config.AuthenticationConfig() scheme, hostinfo = urlsplit(self.service_url)[:2] prompt = 'launchpad.net password for %s: ' % \ self.registrant_email # We will reuse http[s] credentials if we can, prompt user # otherwise self.registrant_password = auth.get_password(scheme, hostinfo, self.registrant_email, prompt=prompt)
def test_wo_branch(self): bug_urls = [ 'https://launchpad.net/bugs/261234 fixed', 'http://bugs.python.org/issue5243 fixed', ] # w/o global options we can match only unique lp url self.assertEqual(['lp:261234'], bug_urls_to_ids(bug_urls)) # set some options cfg = config.GlobalConfig() cfg.set_user_option('bugtracker_py_url', 'http://bugs.python.org/issue{id}') cfg.set_user_option('bugzilla_kde_url', 'http://bugs.kde.org/') cfg.set_user_option('trac_mbz_url', 'http://bugs.musicbrainz.org/') self.assertEqual(['lp:261234', 'py:5243'], bug_urls_to_ids(bug_urls))
def test_get_global_bug_tags(self): # check empty bazaar.conf self.assertEqual({}, get_global_bug_tags()) # set some options cfg = config.GlobalConfig() cfg.set_user_option('bugtracker_py_url', 'http://bugs.python.org/issue{id}') cfg.set_user_option('bugzilla_kde_url', 'http://bugs.kde.org/') cfg.set_user_option('trac_mbz_url', 'http://bugs.musicbrainz.org/ticket/') self.assertEquals({ 'py': 'bugtracker', 'kde': "bugzilla", 'mbz': 'trac'}, get_global_bug_tags())
def test_w_branch(self): bug_urls = [ 'https://launchpad.net/bugs/261234 fixed', 'http://bugs.python.org/issue5243 fixed', 'http://bugs.kde.org/show_bug.cgi?id=169104 fixed', ] wt = self.make_branch_and_tree('.') branch = wt.branch # w/o user settings we can match only unique lp url self.assertEqual(['lp:261234'], bug_urls_to_ids(bug_urls, branch)) # set some bugtrackers g_cfg = config.GlobalConfig() g_cfg.set_user_option('bugtracker_py_url', 'http://bugs.python.org/issue{id}') b_cfg = branch.get_config() b_cfg.set_user_option('bugzilla_kde_url', 'http://bugs.kde.org/') self.assertEqual(['kde:169104', 'lp:261234', 'py:5243'], bug_urls_to_ids(bug_urls, branch))
def test_gather_user_credentials_from_auth_conf(self): auth_path = config.authentication_config_filename() service = LaunchpadService() g_conf = config.GlobalConfig() g_conf.set_user_option('email', 'Test User <*****@*****.**>') f = open(auth_path, 'wb') try: scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2] f.write('[section]\n' 'scheme=%s\n' 'host=%s\n' '[email protected]\n' 'password=testpass\n' % (scheme, hostinfo)) finally: f.close() self.assertIs(None, service.registrant_password) service.gather_user_credentials() self.assertEqual('*****@*****.**', service.registrant_email) self.assertEqual('testpass', service.registrant_password)
def test_pending_with_ghosts(self): """Test when a pending merge's ancestry includes ghosts.""" config.GlobalConfig().set_user_option('email', 'Joe Foo <*****@*****.**>') tree = self.make_branch_and_tree('a') tree.commit('empty commit') tree2 = tree.bzrdir.clone('b').open_workingtree() tree2.commit('a non-ghost', timestamp=1196796819, timezone=0) tree2.add_parent_tree_id('a-ghost-revision') tree2.commit('commit with ghost', timestamp=1196796819, timezone=0) tree2.commit('another non-ghost', timestamp=1196796819, timezone=0) tree.merge_from_branch(tree2.branch) tree.lock_read() self.addCleanup(tree.unlock) output = StringIO() show_pending_merges(tree, output) self.assertEqualDiff( 'pending merges:\n' ' Joe Foo 2007-12-04 another non-ghost\n' ' Joe Foo 2007-12-04 commit with ghost\n' ' (ghost) a-ghost-revision\n' ' Joe Foo 2007-12-04 a non-ghost\n', output.getvalue())
def _get_editor(): """Return a sequence of possible editor binaries for the current platform""" try: yield os.environ["BZR_EDITOR"] except KeyError: pass e = config.GlobalConfig().get_editor() if e is not None: yield e for varname in 'VISUAL', 'EDITOR': if varname in os.environ: yield os.environ[varname] if sys.platform == 'win32': for editor in 'wordpad.exe', 'notepad.exe': yield editor else: for editor in ['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe']: yield editor
def test_multiple_pending(self): config.GlobalConfig().set_user_option('email', 'Joe Foo <*****@*****.**>') tree = self.make_branch_and_tree('a') tree.commit('commit 1', timestamp=1196796819, timezone=0) tree2 = tree.bzrdir.clone('b').open_workingtree() tree.commit('commit 2', timestamp=1196796819, timezone=0) tree2.commit('commit 2b', timestamp=1196796819, timezone=0) tree3 = tree2.bzrdir.clone('c').open_workingtree() tree2.commit('commit 3b', timestamp=1196796819, timezone=0) tree3.commit('commit 3c', timestamp=1196796819, timezone=0) tree.merge_from_branch(tree2.branch) tree.merge_from_branch(tree3.branch) output = StringIO() tree.lock_read() self.addCleanup(tree.unlock) show_pending_merges(tree, output) # Even though 2b is in the ancestry of 3c, it should only be displayed # under the first merge parent. self.assertEqualDiff( 'pending merges:\n' ' Joe Foo 2007-12-04 commit 3b\n' ' Joe Foo 2007-12-04 commit 2b\n' ' Joe Foo 2007-12-04 commit 3c\n', output.getvalue())
def setup_config(self, text): my_config = config.GlobalConfig() config_file = StringIO(text) my_config._get_parser(config_file) return my_config
def get_connection(self, text, smtp_factory=None): my_config = config.GlobalConfig() config_file = StringIO(text) my_config._get_parser(config_file) return smtp_connection.SMTPConnection(my_config, _smtp_factory=smtp_factory)
def _get_config(self, config_text): my_config = config.GlobalConfig() config_file = StringIO(config_text.encode('utf-8')) my_config._parser = my_config._get_parser(file=config_file) return my_config
def get_global_bug_tags(): """Return bug tags collected from global config bazaar.conf""" cfg = config.GlobalConfig() keys = cfg._get_parser().get('DEFAULT', {}).keys() return get_user_bug_trackers_tags(keys)
def __init__(self): self._config = config.GlobalConfig()