Ejemplo n.º 1
0
def auto_init_repo(cfg,topdir,repopath):
    # create leading directories
    p = topdir

    assert repopath.endswith('.git'), 'must have .git extension'
    newdirmode = util.getConfigDefault(cfg,
                                       'repo %s' % repopath[:-4],
                                       'dirmode',
                                       None,
                                       'defaults')
    if newdirmode is not None:
        newdirmode = int(newdirmode, 8)
    else:
        newdirmode = 0750

    for segment in repopath.split(os.sep)[:-1]:
        p = os.path.join(p, segment)
        util.mkdir(p, newdirmode)

    fullpath = os.path.join(topdir, repopath)

    # init using a custom template, if required
    try:
        template = cfg.get('gitosis', 'init-template')
        repository.init(path=fullpath, template=template, mode=newdirmode)
    except (NoSectionError, NoOptionError):
        pass

    repository.init(path=fullpath, mode=newdirmode)
Ejemplo n.º 2
0
def set_descriptions(config):
    """
    Set descriptions for gitweb use.
    """
    log = logging.getLogger('gitosis.gitweb.set_descriptions')

    for (section, name, topdir, subpath) in enum_cfg_repos(config):
        description = util.getConfigDefault(config, section, 'description', None)
        if not description:
            continue

        if not os.path.exists(os.path.join(topdir,subpath)):
            log.warning(
                'Cannot find %(name)r in %(topdir)r'
                % dict(name=name,topdir=topdir))
            continue

        path = os.path.join(
            topdir,
            subpath,
            'description',
            )
        tmp = '%s.%d.tmp' % (path, os.getpid())
        f = file(tmp, 'w')
        try:
            print >>f, description
        finally:
            f.close()
        os.rename(tmp, path)
Ejemplo n.º 3
0
def generate_project_list_fp(config, fp):
    """
    Generate projects list for ``gitweb``.

    :param config: configuration to read projects from
    :type config: RawConfigParser

    :param fp: writable for ``projects.list``
    :type fp: (file-like, anything with ``.write(data)``)
    """
    log = logging.getLogger('gitosis.gitweb.generate_projects_list')

    global_enable = util.getConfigDefaultBoolean(config, 'defaults', 'gitweb', False)

    for (section, name, topdir, subpath) in enum_cfg_repos(config):
        enable = util.getConfigDefaultBoolean(config, section, 'gitweb', global_enable)
        if not enable:
            continue

        if not os.path.exists(os.path.join(topdir,subpath)):
            log.warning(
                'Cannot find %(name)r in %(topdir)r'
                % dict(name=name,topdir=topdir))
            # preserve old behavior, using the original name for
            # completely nonexistant repos:
            subpath = name

        response = [subpath]

        owner = util.getConfigDefault(config, section, 'owner', None)
        if owner:
            username = util.getConfigDefault(config, 'user %s' % owner, 'name', None)
            if username:
                response.append(username)
            response.append(owner)

        line = ' '.join([urllib.quote_plus(s) for s in response])
        print >>fp, line
Ejemplo n.º 4
0
def haveAccess(config, user, mode, path):
    """
    Map request for write access to allowed path.

    Note for read-only access, the caller should check for write
    access too.

    Returns ``None`` for no access, or a tuple of toplevel directory
    containing repositories and a relative path to the physical repository.
    """
    log = logging.getLogger('gitosis.access.haveAccess')

    log.debug(
        'Access check for %(user)r as %(mode)r on %(path)r...'
        % dict(
        user=user,
        mode=mode,
        path=path,
        ))

    basename, ext = os.path.splitext(path)
    if ext == '.git':
        log.debug(
            'Stripping .git suffix from %(path)r, new value %(basename)r'
            % dict(
            path=path,
            basename=basename,
            ))
        path = basename

    sections = ['group %s' % item for item in
                 group.getMembership(config=config, user=user)]
    sections.insert(0, 'user %s' % user)

    for sectname in sections:
        repos = util.getConfigList(config, sectname, mode)

        mapping = None

        if pathMatchPatterns(path, repos):
            log.debug(
                'Access ok for %(user)r as %(mode)r on %(path)r'
                % dict(
                user=user,
                mode=mode,
                path=path,
                ))
            mapping = path
        else:
            mapping = util.getConfigDefault(config,
                                            sectname,
                                            'map %s %s' % (mode, path),
                                            None)
            if mapping:
                log.debug(
                    'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r'
                    % dict(
                    user=user,
                    mode=mode,
                    path=path,
                    mapping=mapping,
                    ))

        if mapping is not None:
            prefix = util.getConfigDefault(config,
                                           sectname,
                                           'repositories',
                                           'repositories',
                                           'gitosis')

            log.debug(
                'Using prefix %(prefix)r for %(path)r'
                % dict(
                prefix=prefix,
                path=mapping,
                ))
            return (prefix, mapping)