Exemplo n.º 1
0
    def __rename_group(self, old, old_parent_id, new, new_parent_id):
        """
        Renames a group on filesystem
        
        :param group_name:
        """
        log.debug('renaming repos group from %s to %s', old, new)

        if new_parent_id:
            paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
            new_parent_path = os.sep.join(paths)
        else:
            new_parent_path = ''

        if old_parent_id:
            paths = Group.get(old_parent_id).full_path.split(Group.url_sep())
            old_parent_path = os.sep.join(paths)
        else:
            old_parent_path = ''

        old_path = os.path.join(self.repos_path, old_parent_path, old)
        new_path = os.path.join(self.repos_path, new_parent_path, new)

        log.debug('renaming repos paths from %s to %s', old_path, new_path)

        if os.path.isdir(new_path):
            raise Exception('Was trying to rename to already '
                            'existing dir %s' % new_path)
        shutil.move(old_path, new_path)
Exemplo n.º 2
0
    def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False):
        """
        makes repository on filesystem. It's group aware means it'll create
        a repository within a group, and alter the paths accordingly of
        group location

        :param repo_name:
        :param alias:
        :param parent_id:
        :param clone_uri:
        """
        from rhodecode.lib.utils import check_repo

        if new_parent_id:
            paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
            new_parent_path = os.sep.join(paths)
        else:
            new_parent_path = ""

        repo_path = os.path.join(*map(lambda x: safe_str(x), [self.repos_path, new_parent_path, repo_name]))

        if check_repo(repo_path, self.repos_path):
            log.info("creating repo %s in %s @ %s", repo_name, repo_path, clone_uri)
            backend = get_backend(alias)

            backend(repo_path, create=True, src_url=clone_uri)
Exemplo n.º 3
0
    def __delete_group(self, group):
        """
        Deletes a group from a filesystem
        
        :param group: instance of group from database
        """
        paths = group.full_path.split(Group.url_sep())
        paths = os.sep.join(paths)

        rm_path = os.path.join(self.repos_path, paths)
        os.rmdir(rm_path)
Exemplo n.º 4
0
        def to_python(self, value, state):

            repo_name = value.get('repo_name')

            slug = repo_name_slug(repo_name)
            if slug in [ADMIN_PREFIX, '']:
                e_dict = {'repo_name': _('This repository name is disallowed')}
                raise formencode.Invalid('', value, state, error_dict=e_dict)


            if value.get('repo_group'):
                gr = Group.get(value.get('repo_group'))
                group_path = gr.full_path
                # value needs to be aware of group name in order to check
                # db key This is an actual just the name to store in the
                # database
                repo_name_full = group_path + Group.url_sep() + repo_name
                
            else:
                group_path = ''
                repo_name_full = repo_name


            value['repo_name_full'] = repo_name_full
            rename = old_data.get('repo_name') != repo_name_full
            create = not edit
            if  rename or create:

                if group_path != '':
                    if RepoModel().get_by_repo_name(repo_name_full,):
                        e_dict = {'repo_name':_('This repository already '
                                                'exists in a group "%s"') %
                                  gr.group_name}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)
                elif Group.get_by_group_name(repo_name_full):
                        e_dict = {'repo_name':_('There is a group with this'
                                                ' name already "%s"') %
                                  repo_name_full}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)

                elif RepoModel().get_by_repo_name(repo_name_full):
                        e_dict = {'repo_name':_('This repository '
                                                'already exists')}
                        raise formencode.Invalid('', value, state,
                                                 error_dict=e_dict)

            return value
Exemplo n.º 5
0
    def __create_group(self, group_name, parent_id):
        """
        makes repositories group on filesystem

        :param repo_name:
        :param parent_id:
        """

        if parent_id:
            paths = Group.get(parent_id).full_path.split(Group.url_sep())
            parent_path = os.sep.join(paths)
        else:
            parent_path = ''

        create_path = os.path.join(self.repos_path, parent_path, group_name)
        log.debug('creating new group in %s', create_path)

        if os.path.isdir(create_path):
            raise Exception('That directory already exists !')


        os.makedirs(create_path)
Exemplo n.º 6
0
    def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False):
        """
        makes repository on filesystem. It's group aware means it'll create
        a repository within a group, and alter the paths accordingly of
        group location

        :param repo_name:
        :param alias:
        :param parent_id:
        :param clone_uri:
        """
        from rhodecode.lib.utils import is_valid_repo,is_valid_repos_group

        if new_parent_id:
            paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
            new_parent_path = os.sep.join(paths)
        else:
            new_parent_path = ''

        repo_path = os.path.join(*map(lambda x:safe_str(x),
                                [self.repos_path, new_parent_path, repo_name]))

        
        # check if this path is not a repository
        if is_valid_repo(repo_path, self.repos_path):
            raise Exception('This path %s is a valid repository' % repo_path)

        # check if this path is a group
        if is_valid_repos_group(repo_path, self.repos_path):
            raise Exception('This path %s is a valid group' % repo_path)
                
        log.info('creating repo %s in %s @ %s', repo_name, repo_path,
                 clone_uri)
        backend = get_backend(alias)

        backend(repo_path, create=True, src_url=clone_uri)