コード例 #1
0
ファイル: create.py プロジェクト: bopopescu/follow-airbnb
    def Run(self, args):
        """Create a GCP repository to the current directory.

    Args:
      args: argparse.Namespace, the arguments this command is run with.

    Returns:
      (sourcerepo_v1_messages.Repo) The created respository.

    Raises:
      ToolException: on project initialization errors, on missing billing
        account, and when the repo name is already in use.
    """
        res = sourcerepo.ParseRepo(args.repository_name)
        # check that the name does not have forbidden characters.
        # we'd like to do this by putting the validator in the flag type, but
        # we cannot for now because it needs to work on the parsed name.
        flags.REPO_NAME_VALIDATOR(res.Name())
        source_handler = sourcerepo.Source()

        try:
            repo = source_handler.CreateRepo(res)
            if repo:
                log.CreatedResource(res.Name())
                log.warn('You may be billed for this repository. '
                         'See {url} for details.'.format(url=_BILLING_URL))
                return repo
        except exceptions.HttpError as error:
            exc = c_exc.HttpException(error)
            exc.error_format = _ERROR_FORMAT
            if 'API is not enabled' in unicode(exc):
                link = _LINK_FORMAT.format(
                    project=properties.VALUES.core.project.GetOrFail())
                exc.error_format += link
            raise exc
コード例 #2
0
ファイル: create.py プロジェクト: eduardofacanha/Robin
  def Run(self, args):
    """Create a GCP repository to the current directory.

    Args:
      args: argparse.Namespace, the arguments this command is run with.

    Returns:
      (sourcerepo_v1_messages.Repo) The created respository.

    Raises:
      ToolException: on project initialization errors, on missing billing
        account, and when the repo name is already in use.
    """
    project_id = resolvers.FromProperty(properties.VALUES.core.project)
    res = resources.REGISTRY.Parse(
        args.name,
        params={'projectsId': project_id},
        collection='sourcerepo.projects.repos')
    # check that the name does not have forbidden characters.
    # we'd like to do this by putting the validator in the flag type, but
    # we cannot for now because it needs to work on the parsed name.
    flags.REPO_NAME_VALIDATOR(res.Name())
    source_handler = sourcerepo.Source()

    # This service enabled check can be removed when cl/148491846 is ready
    if not enable_api.IsServiceEnabled(res.projectsId,
                                       _SOURCEREPO_SERVICE_NAME):
      message = ('{api} is required for repository creation and is not '
                 'enabled.'.format(api=_SOURCEREPO_SERVICE_NAME))
      if console_io.PromptContinue(
          message=message,
          prompt_string='Would you like to enable it?',
          default=True):
        operation = enable_api.EnableServiceApiCall(res.projectsId,
                                                    _SOURCEREPO_SERVICE_NAME)
        # wait for the operation to complete, will raise an exception if the
        # operation fails.
        services_util.ProcessOperationResult(operation, async=False)
      else:
        error_message = ('Cannot create a repository without enabling '
                         '{api}'.format(api=_SOURCEREPO_SERVICE_NAME))
        raise exceptions.Error(error_message)
    try:
      repo = source_handler.CreateRepo(res)
      if repo:
        log.CreatedResource(res.Name())
        log.Print('You may be billed for this repository. '
                  'See {url} for details.'.format(url=_BILLING_URL))
        return repo
    except exceptions.HttpError as error:
      exc = c_exc.HttpException(error)
      exc.error_format = _ERROR_FORMAT
      raise exc