コード例 #1
0
ファイル: test_branch.py プロジェクト: c0ns0le/cygwin
 def test_get_push_location_exact(self):
     from bzrlib.config import (locations_config_filename,
                                ensure_config_dir_exists)
     ensure_config_dir_exists()
     fn = locations_config_filename()
     open(fn, 'wt').write(("[%s]\n"
                               "push_location=foo\n" %
                               self.get_branch().base[:-1]))
     self.assertEqual("foo", self.get_branch().get_push_location())
コード例 #2
0
 def _set_user_ignore_content(self, ignores):
     """Create user ignore file and set its content to ignores."""
     config.ensure_config_dir_exists()
     user_ignore_file = config.user_ignore_config_filename()
     f = open(user_ignore_file, 'wb')
     try:
         f.write(ignores)
     finally:
         f.close()
コード例 #3
0
ファイル: test_branch.py プロジェクト: saminigod/cygwin
 def test_get_push_location_exact(self):
     from bzrlib.config import (locations_config_filename,
                                ensure_config_dir_exists)
     ensure_config_dir_exists()
     fn = locations_config_filename()
     open(fn, 'wt').write(
         ("[%s]\n"
          "push_location=foo\n" % self.get_branch().base[:-1]))
     self.assertEqual("foo", self.get_branch().get_push_location())
コード例 #4
0
ファイル: test_is_ignored.py プロジェクト: Distrotech/bzr
 def _set_user_ignore_content(self, ignores):
     """Create user ignore file and set its content to ignores."""
     config.ensure_config_dir_exists()
     user_ignore_file = config.user_ignore_config_filename()
     f = open(user_ignore_file, 'wb')
     try:
         f.write(ignores)
     finally:
         f.close()
コード例 #5
0
    def test_global_ignored(self):
        tree = self.make_branch_and_tree('.')

        config.ensure_config_dir_exists()
        user_ignore_file = config.user_ignore_config_filename()
        f = open(user_ignore_file, 'wb')
        try:
            f.write('*.py[co]\n'
                    './.shelf\n'
                    '# comment line\n'
                    '\n'  #Blank line
                    '\r\n'  #Blank dos line
                    ' * \n'  #Trailing and suffix spaces
                    'crlf\r\n'  # dos style line
                    '*\xc3\xa5*\n'  # u'\xe5'.encode('utf8')
                    )
        finally:
            f.close()

        # Rooted
        self.assertEqual('./.shelf', tree.is_ignored('.shelf'))
        self.assertEqual(None, tree.is_ignored('foo/.shelf'))

        # Glob style
        self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
        self.assertEqual('*.py[co]', tree.is_ignored('foo.pyo'))
        self.assertEqual(None, tree.is_ignored('foo.py'))

        # Glob in subdir
        self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyc'))
        self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyo'))
        self.assertEqual(None, tree.is_ignored('bar/foo.py'))

        # Unicode
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5gfors'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5gfors'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b/\xe5'))

        # Whitespace
        self.assertEqual(' * ', tree.is_ignored(' bbb '))
        self.assertEqual(' * ', tree.is_ignored('subdir/ bbb '))
        self.assertEqual(None, tree.is_ignored('bbb '))
        self.assertEqual(None, tree.is_ignored(' bbb'))

        # Dos lines
        self.assertEqual('crlf', tree.is_ignored('crlf'))
        self.assertEqual('crlf', tree.is_ignored('subdir/crlf'))

        # Comment line should be ignored
        self.assertEqual(None, tree.is_ignored('# comment line'))

        # Blank line should also be ignored
        self.assertEqual(None, tree.is_ignored(''))
        self.assertEqual(None, tree.is_ignored('baz/'))
コード例 #6
0
ファイル: util.py プロジェクト: biji/qbzr
 def save(self):
     ensure_config_dir_exists(os.path.dirname(self._filename))
     self._lock.lock_write()
     try:
         self._load()
         f = open(self._filename, 'wb')
         self._configobj.write(f)
         f.close()
     finally:
         self._lock.unlock()
コード例 #7
0
ファイル: test_is_ignored.py プロジェクト: Distrotech/bzr
    def test_global_ignored(self):
        tree = self.make_branch_and_tree('.')

        config.ensure_config_dir_exists()
        user_ignore_file = config.user_ignore_config_filename()
        self._set_user_ignore_content(
            '*.py[co]\n'
            './.shelf\n'
            '# comment line\n'
            '\n' #Blank line
            '\r\n' #Blank dos line
            ' * \n' #Trailing and suffix spaces
            'crlf\r\n' # dos style line
            '*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
            )

        # Rooted
        self.assertEqual('./.shelf', tree.is_ignored('.shelf'))
        self.assertEqual(None, tree.is_ignored('foo/.shelf'))

        # Glob style
        self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
        self.assertEqual('*.py[co]', tree.is_ignored('foo.pyo'))
        self.assertEqual(None, tree.is_ignored('foo.py'))

        # Glob in subdir
        self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyc'))
        self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyo'))
        self.assertEqual(None, tree.is_ignored('bar/foo.py'))

        # Unicode
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5gfors'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5gfors'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5'))
        self.assertEqual(u'*\xe5*', tree.is_ignored(u'b/\xe5'))

        # Whitespace
        self.assertEqual(' * ', tree.is_ignored(' bbb '))
        self.assertEqual(' * ', tree.is_ignored('subdir/ bbb '))
        self.assertEqual(None, tree.is_ignored('bbb '))
        self.assertEqual(None, tree.is_ignored(' bbb'))

        # Dos lines
        self.assertEqual('crlf', tree.is_ignored('crlf'))
        self.assertEqual('crlf', tree.is_ignored('subdir/crlf'))

        # Comment line should be ignored
        self.assertEqual(None, tree.is_ignored('# comment line'))

        # Blank line should also be ignored
        self.assertEqual(None, tree.is_ignored(''))
        self.assertEqual(None, tree.is_ignored('baz/'))
コード例 #8
0
ファイル: test_logformats.py プロジェクト: saminigod/cygwin
    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)
コード例 #9
0
ファイル: test_aliases.py プロジェクト: c0ns0le/cygwin
    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)
コード例 #10
0
    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])
コード例 #11
0
 def __init__(self):
     cmd.Cmd.__init__(self)
     self.prompt = "bzr> "
     try:
         self.tree = WorkingTree.open_containing('.')[0]
     except:
         self.tree = None
     self.set_title()
     self.set_prompt()
     self.identchars += '-'
     ensure_config_dir_exists()
     self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
     readline.set_completer_delims(string.whitespace)
     if os.access(self.history_file, os.R_OK) and \
         os.path.isfile(self.history_file):
         readline.read_history_file(self.history_file)
     self.cwd = os.getcwd()
コード例 #12
0
ファイル: ssh.py プロジェクト: shahwangithub/lib
def save_host_keys():
    """
    Save "discovered" host keys in $(config)/ssh_host_keys/.
    """
    global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
    bzr_hostkey_path = osutils.pathjoin(config.config_dir(), 'ssh_host_keys')
    config.ensure_config_dir_exists()

    try:
        f = open(bzr_hostkey_path, 'w')
        f.write('# SSH host keys collected by bzr\n')
        for hostname, keys in BZR_HOSTKEYS.iteritems():
            for keytype, key in keys.iteritems():
                f.write('%s %s %s\n' % (hostname, keytype, key.get_base64()))
        f.close()
    except IOError, e:
        trace.mutter('failed to save bzr host keys: ' + str(e))
コード例 #13
0
 def __init__(self):
     cmd.Cmd.__init__(self)
     self.prompt = "bzr> "
     try:
         self.tree = WorkingTree.open_containing('.')[0]
     except:
         self.tree = None
     self.set_title()
     self.set_prompt()
     self.identchars += '-'
     ensure_config_dir_exists()
     self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
     readline.set_completer_delims(string.whitespace)
     if os.access(self.history_file, os.R_OK) and \
         os.path.isfile(self.history_file):
         readline.read_history_file(self.history_file)
     self.cwd = os.getcwd()
コード例 #14
0
ファイル: ssh.py プロジェクト: ArslanRafique/dist-packages
def save_host_keys():
    """
    Save "discovered" host keys in $(config)/ssh_host_keys/.
    """
    global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
    bzr_hostkey_path = osutils.pathjoin(config.config_dir(), 'ssh_host_keys')
    config.ensure_config_dir_exists()

    try:
        f = open(bzr_hostkey_path, 'w')
        f.write('# SSH host keys collected by bzr\n')
        for hostname, keys in BZR_HOSTKEYS.iteritems():
            for keytype, key in keys.iteritems():
                f.write('%s %s %s\n' % (hostname, keytype, key.get_base64()))
        f.close()
    except IOError, e:
        trace.mutter('failed to save bzr host keys: ' + str(e))
コード例 #15
0
ファイル: test_aliases.py プロジェクト: saminigod/cygwin
    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)
コード例 #16
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()
コード例 #17
0
ファイル: ignores.py プロジェクト: saminigod/cygwin
def _set_user_ignores(patterns):
    """Fill out the user ignore file with the given patterns

    This may raise an error if it doesn't have permission to
    write to the user ignore file.
    This is mostly used for testing, since it would be
    bad form to rewrite a user's ignore list.
    bzrlib only writes this file if it does not exist.
    """
    ignore_path = config.user_ignore_config_filename()
    config.ensure_config_dir_exists()

    # Create an empty file
    f = open(ignore_path, 'wb')
    try:
        for pattern in patterns:
            f.write(pattern.encode('utf8') + '\n')
    finally:
        f.close()
コード例 #18
0
ファイル: __init__.py プロジェクト: davedoman/dotfiles
 def run(self, name, location=None, delete=False, branch=False):
     if branch:
         provider = LocationBookmarkProvider()
     else:
         provider = GlobalBookmarkProvider()
     ensure_config_dir_exists()
     if delete:
         if provider.resolve_bookmark(name) is None:
             raise BzrCommandError(
                 'bookmark "%s" does not exist' % (name,))
         provider.unset_bookmark(name)
     else:
         if '/' in name:
             raise BzrCommandError(
                 '"%s" contains a "/" character, bookmarks should not contain"/" characters"' % name)
         if not location:
             raise BzrCommandError(
                 'no location provided for bookmark "%s"' % (name,))
         provider.set_bookmark(name, location)
コード例 #19
0
ファイル: test_logformats.py プロジェクト: Distrotech/bzr
    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()
コード例 #20
0
    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
コード例 #21
0
 def run(self, name, location=None, delete=False, branch=False):
     if branch:
         provider = LocationBookmarkProvider()
     else:
         provider = GlobalBookmarkProvider()
     ensure_config_dir_exists()
     if delete:
         if provider.resolve_bookmark(name) is None:
             raise BzrCommandError('bookmark "%s" does not exist' %
                                   (name, ))
         provider.unset_bookmark(name)
     else:
         if '/' in name:
             raise BzrCommandError(
                 '"%s" contains a "/" character, bookmarks should not contain"/" characters"'
                 % name)
         if not location:
             raise BzrCommandError(
                 'no location provided for bookmark "%s"' % (name, ))
         provider.set_bookmark(name, location)
コード例 #22
0
ファイル: test_msgeditor.py プロジェクト: c0ns0le/cygwin
    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
コード例 #23
0
ファイル: test_branch.py プロジェクト: c0ns0le/cygwin
    def test_set_push_location(self):
        from bzrlib.config import (locations_config_filename,
                                   ensure_config_dir_exists)
        ensure_config_dir_exists()
        fn = locations_config_filename()
        # write correct newlines to locations.conf
        # by default ConfigObj uses native line-endings for new files
        # but uses already existing line-endings if file is not empty
        f = open(fn, 'wb')
        try:
            f.write('# comment\n')
        finally:
            f.close()

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual("# comment\n"
                             "[%s]\n"
                             "push_location = foo\n"
                             "push_location:policy = norecurse\n" % local_path,
                             fn)
コード例 #24
0
    def test_set_push_location(self):
        from bzrlib.config import (locations_config_filename,
                                   ensure_config_dir_exists)
        ensure_config_dir_exists()
        fn = locations_config_filename()
        # write correct newlines to locations.conf
        # by default ConfigObj uses native line-endings for new files
        # but uses already existing line-endings if file is not empty
        f = open(fn, 'wb')
        try:
            f.write('# comment\n')
        finally:
            f.close()

        branch = self.make_branch('.', format='knit')
        branch.set_push_location('foo')
        local_path = urlutils.local_path_from_url(branch.base[:-1])
        self.assertFileEqual(
            "# comment\n"
            "[%s]\n"
            "push_location = foo\n"
            "push_location:policy = norecurse\n" % local_path, fn)