예제 #1
0
    def __init__(self, **kwargs):
        """Initialize the record.

    **kwargs keys need to correspond to elements in __slots__.  These arguments
    can be lists:
    - cmd_args
    - cmd_base
    - cmd_line

    If unset, the |username| and |host|  attributes will be determined
    automatically.
    """
        if kwargs.get('username') is None:
            kwargs['username'] = git.GetProjectUserEmail(
                os.path.dirname(__file__))

        if kwargs.get('host') is None:
            kwargs['host'] = cros_build_lib.GetHostName(fully_qualified=True)

        for attr in ('cmd_args', 'cmd_base', 'cmd_line'):
            val = kwargs.get(attr)
            if isinstance(val, (
                    list,
                    tuple,
            )):
                kwargs[attr] = ' '.join(map(repr, val))

        for arg in self.__slots__:
            setattr(self, arg, kwargs.pop(arg, None))
        if kwargs:
            raise TypeError('Unknown options specified %r:' % kwargs)
예제 #2
0
파일: gerrit.py 프로젝트: sjg20/chromite
def _MyUserInfo():
    email = git.GetProjectUserEmail(constants.CHROMITE_DIR)
    [username, _, domain] = email.partition('@')
    if domain in ('google.com', 'chromium.org'):
        emails = [
            '%s@%s' % (username, domain)
            for domain in ('google.com', 'chromium.org')
        ]
    else:
        emails = [email]
    reviewers = ['reviewer:%s' % x for x in emails]
    owners = ['owner:%s' % x for x in emails]
    return emails, reviewers, owners
예제 #3
0
def FindUserEmail(options):
  """Decide which email address is submitting the job.

  Args:
    options: Parsed command line options for cros tryjob.

  Returns:
    Email address for the tryjob as a string.
  """

  if options.committer_email:
    return options.committer_email

  cwd = os.path.dirname(os.path.realpath(__file__))
  return git.GetProjectUserEmail(cwd)
예제 #4
0
    def __init__(self, options, bots, local_patches):
        """Construct the object.

    Args:
      options: The parsed options passed into cbuildbot.
      bots: A list of configs to run tryjobs for.
      local_patches: A list of LocalPatch objects.
    """
        self.options = options
        self.use_buildbucket = options.use_buildbucket
        self.user = getpass.getuser()
        self.repo_cache = cache.DiskCache(self.options.cache_dir)
        cwd = os.path.dirname(os.path.realpath(__file__))
        self.user_email = git.GetProjectUserEmail(cwd)
        logging.info('Using email:%s', self.user_email)
        # Name of the job that appears on the waterfall.
        patch_list = options.gerrit_patches + options.local_patches
        self.name = options.remote_description
        if self.name is None:
            self.name = ''
            if options.branch != 'master':
                self.name = '[%s] ' % options.branch

            self.name += ','.join(patch_list[:self.MAX_PATCHES_IN_DESCRIPTION])
            if len(patch_list) > self.MAX_PATCHES_IN_DESCRIPTION:
                remaining_patches = len(
                    patch_list) - self.MAX_PATCHES_IN_DESCRIPTION
                self.name += '... (%d more CLs)' % (remaining_patches, )

        self.bots = bots[:]
        self.slaves_request = options.slaves
        self.description = ('name: %s\n patches: %s\nbots: %s' %
                            (self.name, patch_list, self.bots))
        self.extra_args = options.pass_through_args
        if '--buildbot' not in self.extra_args:
            self.extra_args.append('--remote-trybot')

        self.extra_args.append('--remote-version=%s' %
                               (self.TRYJOB_FORMAT_VERSION, ))
        self.local_patches = local_patches
        self.repo_url = self.EXTERNAL_URL
        self.cache_key = ('trybot', )
        self.manifest = None
        if repository.IsARepoRoot(options.sourceroot):
            self.manifest = git.ManifestCheckout.Cached(options.sourceroot)
            if repository.IsInternalRepoCheckout(options.sourceroot):
                self.repo_url = self.INTERNAL_URL
                self.cache_key = ('trybot-internal', )
def _SetupWorkDirectoryForPatch(work_dir, patch, branch, manifest, email):
    """Set up local dir for uploading changes to the given patch's project."""
    logging.notice('Setting up dir %s for uploading changes to %s', work_dir,
                   patch.project_url)

    # Clone the git repo from reference if we have a pointer to a
    # ManifestCheckout object.
    reference = None
    if manifest:
        # Get the path to the first checkout associated with this change. Since
        # all of the checkouts share git objects, it doesn't matter which checkout
        # we pick.
        path = manifest.FindCheckouts(patch.project,
                                      only_patchable=True)[0]['path']

        reference = os.path.join(constants.SOURCE_ROOT, path)
        if not os.path.isdir(reference):
            logging.error('Unable to locate git checkout: %s', reference)
            logging.error('Did you mean to use --nomirror?')
            # This will do an "raise OSError" with the right values.
            os.open(reference, os.O_DIRECTORY)
        # Use the email if email wasn't specified.
        if not email:
            email = git.GetProjectUserEmail(reference)

    repository.CloneGitRepo(work_dir, patch.project_url, reference=reference)

    # Set the git committer.
    git.RunGit(work_dir, ['config', '--replace-all', 'user.email', email])

    mbranch = git.MatchSingleBranchName(work_dir,
                                        branch,
                                        namespace='refs/remotes/origin/')
    if branch != mbranch:
        logging.notice('Auto resolved branch name "%s" to "%s"', branch,
                       mbranch)
    branch = mbranch

    # Finally, create a local branch for uploading changes to the given remote
    # branch.
    git.CreatePushBranch(constants.PATCH_BRANCH,
                         work_dir,
                         sync=False,
                         remote_push_branch=git.RemoteRef(
                             'ignore', 'origin/%s' % branch))

    return branch
예제 #6
0
  def __init__(self, options, bots, local_patches):
    """Construct the object.

    Args:
      options: The parsed options passed into cbuildbot.
      bots: A list of configs to run tryjobs for.
      local_patches: A list of LocalPatch objects.
    """
    self.options = options
    self.user = getpass.getuser()
    cwd = os.path.dirname(os.path.realpath(__file__))
    self.user_email = git.GetProjectUserEmail(cwd)
    cros_build_lib.Info('Using email:%s', self.user_email)
    # Name of the job that appears on the waterfall.
    patch_list = options.gerrit_patches + options.local_patches
    self.name = options.remote_description
    if self.name is None:
      self.name = ''
      if options.branch != 'master':
        self.name = '[%s] ' % options.branch
      self.name += ','.join(patch_list)
    self.bots = bots[:]
    self.slaves_request = options.slaves
    self.description = ('name: %s\n patches: %s\nbots: %s' %
                        (self.name, patch_list, self.bots))
    self.extra_args = options.pass_through_args
    if '--buildbot' not in self.extra_args:
      self.extra_args.append('--remote-trybot')

    self.extra_args.append('--remote-version=%s'
                           % (self.TRYJOB_FORMAT_VERSION,))
    self.tryjob_repo = None
    self.local_patches = local_patches
    self.ssh_url = self.EXT_SSH_URL
    self.manifest = None
    if repository.IsARepoRoot(options.sourceroot):
      self.manifest = git.ManifestCheckout.Cached(options.sourceroot)
      if repository.IsInternalRepoCheckout(options.sourceroot):
        self.ssh_url = self.INT_SSH_URL
예제 #7
0
def UploadConditionsMet():
    """Return True if upload conditions are met."""

    # Verify that host domain is in golo.chromium.org or corp.google.com.
    domain = cros_build_lib.GetHostDomain()
    if not domain or not DOMAIN_RE.search(domain):
        return False

    # Verify that git user email is from chromium.org or google.com.
    cwd = os.path.dirname(os.path.realpath(__file__))
    git_id = git.GetProjectUserEmail(cwd)
    if not git_id:
        logging.warning('Unable to determine current "git id".  Skipping stats'
                        ' upload.')
        return False
    if not GIT_ID_RE.search(git_id):
        return False

    # Check for presence of file that disables stats upload.
    if os.path.exists(DISABLE_FILE):
        return False

    return True
예제 #8
0
def _MyUserInfo():
    """Try to return e-mail addresses used by the active user."""
    return [git.GetProjectUserEmail(constants.CHROMITE_DIR)]