Exemplo n.º 1
0
def check_write_copied():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = c0.copy()
    c1.set('foo', 'baz', 'y')
    wconfig.writefile(c1, fname)

    cr = wconfig.readfile(fname)
    assert_equals('x', cr.get('foo', 'bar'))
    assert_equals('y', cr.get('foo', 'baz'))
Exemplo n.º 2
0
def check_write_copied_conflict():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = c0.copy()
    c0.set('foo', 'bar', 'y')
    wconfig.writefile(c0, fname)
    wconfig.writefile(c1, fname)  # shouldn't override foo.bar = y

    cr = wconfig.readfile(fname)
    assert_equals('y', cr.get('foo', 'bar'))
Exemplo n.º 3
0
def check_write_copied_conflict():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = c0.copy()
    c0.set('foo', 'bar', 'y')
    wconfig.writefile(c0, fname)
    wconfig.writefile(c1, fname)  # shouldn't override foo.bar = y

    cr = wconfig.readfile(fname)
    assert_equals('y', cr.get('foo', 'bar'))
Exemplo n.º 4
0
def check_write_copied():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = c0.copy()
    c1.set('foo', 'baz', 'y')
    wconfig.writefile(c1, fname)

    cr = wconfig.readfile(fname)
    assert_equals('x', cr.get('foo', 'bar'))
    assert_equals('y', cr.get('foo', 'baz'))
Exemplo n.º 5
0
def check_write_conflict_set_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    c1.set('foo', 'bar', 'y')
    wconfig.writefile(c1, fname)
    del c0['foo']['bar']
    wconfig.writefile(c0, fname)

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
Exemplo n.º 6
0
def check_write_conflict_del_set():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    c0.set('foo', 'bar', 'z')
    wconfig.writefile(c0, fname)

    cr = wconfig.readfile(fname)
    assert_equals('z', cr.get('foo', 'bar'))
Exemplo n.º 7
0
def check_write_noconflict_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    wconfig.writefile(c0, fname)  # shouldn't override del foo.bar

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
    assert c0.get('foo', 'bar')  # don't reload c1's change implicitly
Exemplo n.º 8
0
def check_write_conflict_del_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    del c0['foo']['bar']
    wconfig.writefile(c0, fname)  # shouldn't raise KeyError

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
Exemplo n.º 9
0
def check_write_noconflict_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    wconfig.writefile(c0, fname)  # shouldn't override del foo.bar

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
    assert c0.get('foo', 'bar')  # don't reload c1's change implicitly
Exemplo n.º 10
0
def check_write_conflict_del_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    del c0['foo']['bar']
    wconfig.writefile(c0, fname)  # shouldn't raise KeyError

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
Exemplo n.º 11
0
def check_write_conflict_set_del():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    c1.set('foo', 'bar', 'y')
    wconfig.writefile(c1, fname)
    del c0['foo']['bar']
    wconfig.writefile(c0, fname)

    cr = wconfig.readfile(fname)
    assert not cr.get('foo', 'bar')
Exemplo n.º 12
0
def check_write_conflict_del_set():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    del c1['foo']['bar']
    wconfig.writefile(c1, fname)
    c0.set('foo', 'bar', 'z')
    wconfig.writefile(c0, fname)

    cr = wconfig.readfile(fname)
    assert_equals('z', cr.get('foo', 'bar'))
Exemplo n.º 13
0
def check_write_noconflict_set_set():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    c1.set('foo', 'baz', 'y')
    wconfig.writefile(c1, fname)
    c0.set('foo', 'bar', 'z')
    wconfig.writefile(c0, fname)  # should not override foo.baz = y

    cr = wconfig.readfile(fname)
    assert_equals('z', cr.get('foo', 'bar'))
    assert_equals('y', cr.get('foo', 'baz'))
    assert not c0.get('foo', 'baz')  # don't reload c1's change implicitly
Exemplo n.º 14
0
def check_write_noconflict_set_set():
    fname = writetempfile('[foo]\nbar = x')
    c0 = wconfig.readfile(fname)
    c1 = wconfig.readfile(fname)
    c1.set('foo', 'baz', 'y')
    wconfig.writefile(c1, fname)
    c0.set('foo', 'bar', 'z')
    wconfig.writefile(c0, fname)  # should not override foo.baz = y

    cr = wconfig.readfile(fname)
    assert_equals('z', cr.get('foo', 'bar'))
    assert_equals('y', cr.get('foo', 'baz'))
    assert not c0.get('foo', 'baz')  # don't reload c1's change implicitly
Exemplo n.º 15
0
def _readconfig(ui, repopath, webconfpath):
    """Create new ui and webconf object and read appropriate files"""
    lui = ui.copy()
    if webconfpath:
        lui.readconfig(webconfpath)
        # TODO: handle file not found
        c = wconfig.readfile(webconfpath)
        c.path = os.path.abspath(webconfpath)
        return lui, c
    elif repopath:  # imitate webconf for single repo
        lui.readconfig(os.path.join(repopath, '.hg', 'hgrc'), repopath)
        c = wconfig.config()
        try:
            if not os.path.exists(os.path.join(repopath, '.hgsub')):
                # no _asconfigliststr(repopath) for now, because ServeDialog
                # cannot parse it as a list in single-repo mode.
                c.set('paths', '/', repopath)
            else:
                # since hg 8cbb59124e67, path entry is parsed as a list
                base = hglib.shortreponame(lui) or os.path.basename(repopath)
                c.set('paths', base,
                      _asconfigliststr(os.path.join(repopath, '**')))
        except (EnvironmentError, error.Abort, error.RepoError):
            c.set('paths', '/', repopath)
        return lui, c
    else:
        return lui, None
Exemplo n.º 16
0
def _newwebconf(repopath, webconfpath):
    """create config obj for hgweb"""
    if webconfpath:
        # TODO: handle file not found
        c = wconfig.readfile(webconfpath)
        c.path = os.path.abspath(webconfpath)
        return c
    elif repopath:  # imitate webconf for single repo
        c = wconfig.config()
        try:
            repo = thgrepo.repository(None, repopath)
            roots = [root for root in recursiveRepoSearch(repo)]
            if len(roots) == 1:
                # no _asconfigliststr(repopath) for now, because ServeDialog
                # cannot parse it as a list in single-repo mode.
                c.set("paths", "/", repopath)
            else:
                # since hg 8cbb59124e67, path entry is parsed as a list
                base = hglib.fromunicode(repo.shortname)
                c.set("paths", base, _asconfigliststr(repopath))
                for root in roots[1:]:
                    c.set("paths", base + root[len(repopath) :], _asconfigliststr(root))
        except (EnvironmentError, error.Abort, error.RepoError):
            c.set("paths", "/", repopath)
        return c
Exemplo n.º 17
0
def _newwebconf(repopath, webconfpath):
    """create config obj for hgweb"""
    if webconfpath:
        # TODO: handle file not found
        c = wconfig.readfile(webconfpath)
        c.path = os.path.abspath(webconfpath)
        return c
    elif repopath:  # imitate webconf for single repo
        c = wconfig.config()
        try:
            repo = thgrepo.repository(None, repopath)
            roots = [root for root in recursiveRepoSearch(repo)]
            if len(roots) == 1:
                # no _asconfigliststr(repopath) for now, because ServeDialog
                # cannot parse it as a list in single-repo mode.
                c.set('paths', '/', repopath)
            else:
                # since hg 8cbb59124e67, path entry is parsed as a list
                base = hglib.fromunicode(repo.shortname)
                c.set('paths', base, _asconfigliststr(repopath))
                for root in roots[1:]:
                    c.set('paths', base + root[len(repopath):],
                          _asconfigliststr(root))
        except (EnvironmentError, error.Abort, error.RepoError):
            c.set('paths', '/', repopath)
        return c
Exemplo n.º 18
0
def loadIniFile(rcpath, parent=None):
    for fn in rcpath:
        if os.path.exists(fn):
            break
    else:
        for fn in rcpath:
            # Try to create a file from rcpath
            try:
                f = open(fn, 'w')
                f.write('# Generated by TortoiseHg\n')
                f.close()
                break
            except EnvironmentError:
                pass
        else:
            qtlib.WarningMsgBox(_('Unable to create a config file'),
                   _('Insufficient access rights.'), parent=parent)
            return None, {}

    return fn, wconfig.readfile(fn)
Exemplo n.º 19
0
def loadIniFile(rcpath, parent=None):
    for fn in rcpath:
        if os.path.exists(fn):
            break
    else:
        for fn in rcpath:
            # Try to create a file from rcpath
            try:
                f = open(fn, 'w')
                f.write('# Generated by TortoiseHg\n')
                f.close()
                break
            except EnvironmentError:
                pass
        else:
            qtlib.WarningMsgBox(_('Unable to create a config file'),
                                _('Insufficient access rights.'),
                                parent=parent)
            return None, {}

    return fn, wconfig.readfile(fn)
Exemplo n.º 20
0
def _newwebconf(repopath, webconfpath):
    """create config obj for hgweb"""
    if webconfpath:
        # TODO: handle file not found
        c = wconfig.readfile(webconfpath)
        c.path = os.path.abspath(webconfpath)
        return c
    elif repopath:  # imitate webconf for single repo
        c = wconfig.config()
        try:
            repo = thgrepo.repository(None, repopath)
            roots = [root for root in recursiveRepoSearch(repo)]
            if len(roots) == 1:
                c.set('paths', '/', repopath)
            else:
                base = hglib.fromunicode(repo.shortname)
                c.set('paths', base, repopath)
                for root in roots[1:]:
                    c.set('paths', base + root[len(repopath):], root)
        except (EnvironmentError, error.Abort, error.RepoError):
            c.set('paths', '/', repopath)
        return c
Exemplo n.º 21
0
def _newwebconf(repopath, webconfpath):
    """create config obj for hgweb"""
    if webconfpath:
        # TODO: handle file not found
        c = wconfig.readfile(webconfpath)
        c.path = os.path.abspath(webconfpath)
        return c
    elif repopath:  # imitate webconf for single repo
        c = wconfig.config()
        try:
            # TODO: not nice to instantiate repo just for repo.shortname
            repo = thgrepo.repository(None, repopath)
            if not os.path.exists(os.path.join(repopath, '.hgsub')):
                # no _asconfigliststr(repopath) for now, because ServeDialog
                # cannot parse it as a list in single-repo mode.
                c.set('paths', '/', repopath)
            else:
                # since hg 8cbb59124e67, path entry is parsed as a list
                base = hglib.fromunicode(repo.shortname)
                c.set('paths', base,
                      _asconfigliststr(os.path.join(repopath, '**')))
        except (EnvironmentError, error.Abort, error.RepoError):
            c.set('paths', '/', repopath)
        return c
Exemplo n.º 22
0
def check_readfile():
    fname = writetempfile('[foo]\nbar = baz')
    c = wconfig.readfile(fname)
    assert_equals('baz', c.get('foo', 'bar'))
Exemplo n.º 23
0
def check_readfile():
    fname = writetempfile('[foo]\nbar = baz')
    c = wconfig.readfile(fname)
    assert_equals('baz', c.get('foo', 'bar'))
Exemplo n.º 24
0
 def openwebconf(self, path):
     """load the specified webconf file"""
     path = hglib.fromunicode(path)
     c = wconfig.readfile(path)
     c.path = os.path.abspath(path)
     self.setwebconf(c)