Esempio n. 1
0
File: hg.py Progetto: mensi/cydra
    def create_repository(self, project, repository_name, **params):
        if not is_valid_repository_name(repository_name):
            raise CydraError("Invalid Repository Name", name=repository_name)

        path = os.path.join(self._base, project.name, repository_name)

        if os.path.exists(path):
            raise CydraError('Path already exists', path=path)

        if not os.path.exists(os.path.join(self._base, project.name)):
            os.mkdir(os.path.join(self._base, project.name))

        hg_cmd = subprocess.Popen([self.hgcommand, 'init', path],
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
        _, errors = hg_cmd.communicate()

        if hg_cmd.returncode != 0:
            if hg_cmd.returncode == 127:
                # assume this is command not found
                raise CydraError(
                    'Command not found encountered while calling hg',
                    stderr=errors)
            else:
                raise CydraError('Error encountered while calling hg',
                                 stderr=errors,
                                 code=hg_cmd.returncode)

        repository = HgRepository(self.compmgr, self._base, project,
                                  repository_name)
        repository.set_params(**params)
        repository.sync()  # synchronize repository
        return repository
Esempio n. 2
0
File: git.py Progetto: mensi/cydra
    def create_repository(self, project, repository_name, **params):
        """Create a new git repository

        A repository's name can only contain letters, numbers and dashes/underscores."""
        if not is_valid_repository_name(repository_name):
            raise CydraError("Invalid Repository Name", name=repository_name)

        path = os.path.join(self._base, project.name, repository_name + '.git')

        if os.path.exists(path):
            raise CydraError('Path already exists', path=path)

        if not os.path.exists(os.path.join(self._base, project.name)):
            os.mkdir(os.path.join(self._base, project.name))

        git_cmd = subprocess.Popen([self.gitcommand, 'init', '--bare', path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        _, errors = git_cmd.communicate()

        if git_cmd.returncode != 0:
            if git_cmd.returncode == 127:
                # assume this is command not found
                raise CydraError('Command not found encountered while calling git', stderr=errors)
            else:
                raise CydraError('Error encountered while calling git', stderr=errors, code=git_cmd.returncode)

        # Customize config
        repository = GitRepository(self.compmgr, self._base, project, repository_name)
        repository.set_params(**params)
        repository.sync()  # synchronize repository
        return repository
Esempio n. 3
0
    def create_repository(self, project, repository_name):
        if repository_name != project.name:
            raise CydraError(
                "SVN Repository name has to be the same as the project's name")

        path = os.path.join(self._base, project.name)

        if os.path.exists(path):
            raise CydraError('Path already exists', path=path)

        svn_cmd = subprocess.Popen([self.svncommand, 'create', path],
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        output, errors = svn_cmd.communicate()

        if svn_cmd.returncode != 0:
            if svn_cmd.returncode == 127:
                # assume this is command not found
                raise CydraError(
                    'Command not found encountered while calling svn',
                    stderr=errors)
            else:
                raise CydraError('Error encountered while calling svn',
                                 stderr=errors,
                                 code=hg_cmd.returncode)

        # Customize config

        repository = SVNRepository(self.compmgr, self._base, project)
        repository.sync()
        return repository
Esempio n. 4
0
File: hg.py Progetto: mensi/cydra
 def _set_config(self, config):
     try:
         with open(self.hgrc_path, 'wb') as f:
             config.write(f)
     except Exception:
         logger.exception("Unable to write hgrc file %s", self.hgrc_path)
         raise CydraError('Unable to write hgrc file')
Esempio n. 5
0
File: git.py Progetto: mensi/cydra
    def _repo_exists(self, project, name):
        if not is_valid_repository_name(name):
            raise CydraError("Invalid Repository Name", name=name)

        path = os.path.join(self._base, project.name, name + '.git')

        return os.path.exists(path)
Esempio n. 6
0
File: hg.py Progetto: mensi/cydra
    def _get_config(self):
        cp = ConfigParser.RawConfigParser()

        if os.path.exists(self.hgrc_path):
            try:
                cp.read(self.hgrc_path)
            except:
                logger.exception("Unable to parse hgrc file %s",
                                 self.hgrc_path)
                raise CydraError('Cannot parse existing hgrc file')
        else:
            logger.info("No hgrc file found at %s", self.hgrc_path)

        return cp