def setup_config(self): if os.path.isfile(config_filename()): # Something is wrong in environment, # we risk overwriting users config self.assert_(config_filename() + "exists, abort") ensure_config_dir_exists() CONFIG=("[DEFAULT]\n" "email=Joe Foo <*****@*****.**>\n" "log_format=line\n") open(config_filename(),'wb').write(CONFIG)
def test_aliases(self): def bzr(args, **kwargs): return self.run_bzr(args, **kwargs)[0] def bzr_catch_error(args, **kwargs): return self.run_bzr(args, **kwargs)[1] if os.path.isfile(config_filename()): # Something is wrong in environment, # we risk overwriting users config self.assert_(config_filename() + "exists, abort") ensure_config_dir_exists() CONFIG=("[ALIASES]\n" "c=cat\n" "c1=cat -r 1\n" "c2=cat -r 1 -r2\n") open(config_filename(),'wb').write(CONFIG) str1 = 'foo\n' str2 = 'bar\n' tree = self.make_branch_and_tree('.') self.build_tree_contents([('a', str1)]) tree.add('a') tree.commit(message='1') self.assertEquals(bzr('c a'), str1) self.build_tree_contents([('a', str2)]) tree.commit(message='2') self.assertEquals(bzr('c a'), str2) self.assertEquals(bzr('c1 a'), str1) self.assertEquals(bzr('c1 --revision 2 a'), str2) # If --no-aliases isn't working, we will not get retcode=3 bzr('--no-aliases c a', retcode=3) # If --no-aliases breaks all of bzr, we also get retcode=3 # So we need to catch the output as well self.assertEquals(bzr_catch_error('--no-aliases c a', retcode=None), 'bzr: ERROR: unknown command "c"\n') bzr('c -r1 -r2', retcode=3) bzr('c1 -r1 -r2', retcode=3) bzr('c2', retcode=3) bzr('c2 -r1', retcode=3)
def _check_global_config_filename_valid(config): # before bzr 2.3, there was no file_name attrib, only _get_filename, and # checking that would be meaningless. if hasattr(config, 'file_name'): return not config.file_name == config_filename() else: return False
def test_aliases(self): def bzr(args, **kwargs): return self.run_bzr(args, **kwargs)[0] def bzr_catch_error(args, **kwargs): return self.run_bzr(args, **kwargs)[1] if os.path.isfile(config_filename()): # Something is wrong in environment, # we risk overwriting users config self.assert_(config_filename() + "exists, abort") ensure_config_dir_exists() CONFIG = ("[ALIASES]\n" "c=cat\n" "c1=cat -r 1\n" "c2=cat -r 1 -r2\n") open(config_filename(), 'wb').write(CONFIG) str1 = 'foo\n' str2 = 'bar\n' tree = self.make_branch_and_tree('.') self.build_tree_contents([('a', str1)]) tree.add('a') tree.commit(message='1') self.assertEquals(bzr('c a'), str1) self.build_tree_contents([('a', str2)]) tree.commit(message='2') self.assertEquals(bzr('c a'), str2) self.assertEquals(bzr('c1 a'), str1) self.assertEquals(bzr('c1 --revision 2 a'), str2) # If --no-aliases isn't working, we will not get retcode=3 bzr('--no-aliases c a', retcode=3) # If --no-aliases breaks all of bzr, we also get retcode=3 # So we need to catch the output as well self.assertEquals(bzr_catch_error('--no-aliases c a', retcode=None), 'bzr: ERROR: unknown command "c"\n') bzr('c -r1 -r2', retcode=3) bzr('c1 -r1 -r2', retcode=3) bzr('c2', retcode=3) bzr('c2 -r1', retcode=3)
def test_help_with_aliases(self): original = self.run_bzr('help cat')[0] ensure_config_dir_exists() CONFIG = ("[ALIASES]\n" "c=cat\n" "cat=cat\n") open(config_filename(), 'wb').write(CONFIG) expected = original + "'bzr cat' is an alias for 'bzr cat'.\n" self.assertEqual(expected, self.run_bzr('help cat')[0]) self.assertEqual("'bzr c' is an alias for 'bzr cat'.\n", self.run_bzr('help c')[0])
def setUp(self): super(TestLogFormats, self).setUp() # Create a config file with some useful variables conf_path = config.config_filename() if os.path.isfile(conf_path): # Something is wrong in environment, # we risk overwriting users config self.fail("%s exists" % conf_path) config.ensure_config_dir_exists() f = open(conf_path, 'wb') try: f.write("""[DEFAULT] email=Joe Foo <*****@*****.**> log_format=line """) finally: f.close()
def setUp(self): super(TestLogFormats, self).setUp() # Create a config file with some useful variables conf_path = config.config_filename() if os.path.isfile(conf_path): # Something is wrong in environment, # we risk overwriting users config self.fail("%s exists" % conf_path) config.ensure_config_dir_exists() f = open(conf_path,'wb') try: f.write("""[DEFAULT] email=Joe Foo <*****@*****.**> log_format=line """) finally: f.close()
def test__get_editor(self): # Test that _get_editor can return a decent list of items bzr_editor = os.environ.get('BZR_EDITOR') visual = os.environ.get('VISUAL') editor = os.environ.get('EDITOR') try: os.environ['BZR_EDITOR'] = 'bzr_editor' os.environ['VISUAL'] = 'visual' os.environ['EDITOR'] = 'editor' ensure_config_dir_exists() f = open(config_filename(), 'wb') f.write('editor = config_editor\n') f.close() editors = list(msgeditor._get_editor()) self.assertEqual( ['bzr_editor', 'config_editor', 'visual', 'editor'], editors[:4]) if sys.platform == 'win32': self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:]) else: self.assertEqual( ['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'], editors[4:]) finally: # Restore the environment if bzr_editor is None: del os.environ['BZR_EDITOR'] else: os.environ['BZR_EDITOR'] = bzr_editor if visual is None: del os.environ['VISUAL'] else: os.environ['VISUAL'] = visual if editor is None: del os.environ['EDITOR'] else: os.environ['EDITOR'] = editor
def _get_editor(): """Return a sequence of possible editor binaries for the current platform""" try: yield os.environ["BZR_EDITOR"], '$BZR_EDITOR' except KeyError: pass e = config.GlobalStack().get('editor') if e is not None: yield e, config.config_filename() for varname in 'VISUAL', 'EDITOR': if varname in os.environ: yield os.environ[varname], '$' + varname if sys.platform == 'win32': for editor in 'wordpad.exe', 'notepad.exe': yield editor, None else: for editor in ['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe']: yield editor, None
def test__get_editor(self): # Test that _get_editor can return a decent list of items bzr_editor = os.environ.get('BZR_EDITOR') visual = os.environ.get('VISUAL') editor = os.environ.get('EDITOR') try: os.environ['BZR_EDITOR'] = 'bzr_editor' os.environ['VISUAL'] = 'visual' os.environ['EDITOR'] = 'editor' ensure_config_dir_exists() f = open(config_filename(), 'wb') f.write('editor = config_editor\n') f.close() editors = list(msgeditor._get_editor()) self.assertEqual(['bzr_editor', 'config_editor', 'visual', 'editor'], editors[:4]) if sys.platform == 'win32': self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[4:]) else: self.assertEqual(['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'], editors[4:]) finally: # Restore the environment if bzr_editor is None: del os.environ['BZR_EDITOR'] else: os.environ['BZR_EDITOR'] = bzr_editor if visual is None: del os.environ['VISUAL'] else: os.environ['VISUAL'] = visual if editor is None: del os.environ['EDITOR'] else: os.environ['EDITOR'] = editor
x = call(edargs + [filename]) except OSError, e: # We're searching for an editor, so catch safe errors and continue if e.errno in (errno.ENOENT, ): continue raise if x == 0: return True elif x == 127: continue else: break raise BzrError("Could not start any editor.\nPlease specify one with:\n" " - $BZR_EDITOR\n - editor=/some/path in %s\n" " - $VISUAL\n - $EDITOR" % \ config.config_filename()) DEFAULT_IGNORE_LINE = "%(bar)s %(msg)s %(bar)s" % \ { 'bar' : '-' * 14, 'msg' : 'This line and the following will be ignored' } def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE, start_message=None): """Let the user edit a commit message in a temp file. This is run if they don't give a message or message-containing file on the command line. :param infotext: Text to be displayed at bottom of message for the user's reference;
x = call(edargs + [filename]) except OSError, e: # We're searching for an editor, so catch safe errors and continue if e.errno in (errno.ENOENT, ): continue raise if x == 0: return True elif x == 127: continue else: break raise BzrError("Could not start any editor.\nPlease specify one with:\n" " - $BZR_EDITOR\n - editor=/some/path in %s\n" " - $VISUAL\n - $EDITOR" % \ config.config_filename()) DEFAULT_IGNORE_LINE = "%(bar)s %(msg)s %(bar)s" % \ { 'bar' : '-' * 14, 'msg' : 'This line and the following will be ignored' } def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE, start_message=None): """Let the user edit a commit message in a temp file. This is run if they don't give a message or message-containing file on the command line. :param infotext: Text to be displayed at bottom of message
def get_qbzr_config(): global _qbzr_config if (_qbzr_config is None or not _qbzr_config._filename == config_filename()): _qbzr_config = QBzrConfig() return _qbzr_config
def __init__(self): super(QBzrConfig, self).__init__(config_filename())