Esempio n. 1
0
def checkout_for_args(args):
  """A contextmanager that supplies the Checkout configured in args.

  The Checkout's teardown() method will be invoked on cleanup.

  Args:
    args (argparse.Options): Parsed option list.
  """
  LOGGER.warning('Checking out temporary repositories. This may take a few '
                 'minutes.')
  return checkout.Checkout.use(
      path=args.checkout_path)
Esempio n. 2
0
def checkout_for_args(args):
  """A contextmanager that supplies the Checkout configured in args.

  The Checkout's teardown() method will be invoked on cleanup.

  Args:
    args (argparse.Options): Parsed option list.
  """
  LOGGER.warning('Checking out temporary repositories. This may take a few '
                 'minutes.')
  return checkout.Checkout.use(
      build_revision=args.build_revision, path=args.checkout_path)
Esempio n. 3
0
  def _upload_patch(self, repo_path, commit_msg):
    # Check if the Git repository actually has changes.
    diff_args = ['git', 'diff', '--no-ext-diff', '--exit-code']
    if not LOGGER.isEnabledFor(logging.DEBUG):
      diff_args.append('--quiet')
    rv, diff = execute.call(diff_args, cwd=repo_path)
    LOGGER.debug('Diff for [%s]:\n%s', repo_path, diff)
    if rv == 0:
      LOGGER.warning('No changes in repository; refusing to commit.')
      return

    commit_msg_file = self._c.mktempfile(commit_msg)

    LOGGER.warning('Creating commit in [%s] with message:\n%s',
                   repo_path, commit_msg)
    execute.check_call(
        ['git', 'checkout', '-b', '_cros_pin'],
        cwd=repo_path)
    execute.check_call(
        ['git', 'commit', '--all', '-F', commit_msg_file],
        cwd=repo_path)

    LOGGER.debug('Uploading CL!')
    args = [
        'git', 'cl', 'upload',
        '--bypass-hooks', # The CQ will take care of them!
        '--send-mail',
        '--message-file', commit_msg_file,
        '-f',
        ]
    if self._cq:
      print 'Commit? [Y/n]:',
      input_string = raw_input()
      if input_string != '' and not distutils.util.strtobool(input_string):
        LOGGER.warning('User opted not to commit; aborting.')
        return
      args.append('--use-commit-queue')
    if not self._reviewers:
      args.append('--tbr-owners')

    output = execute.check_call(args, cwd=repo_path, dry_run=self._dry_run)
    issue = None
    for line in output.splitlines():
      for rx in self.RE_ISSUE_CREATED:
        match = rx.match(line)
        if match:
          issue = match.group(1)
          LOGGER.debug('Extracted issue from output: %s', issue)
          self._issues.add(issue)
          break
    else:
      LOGGER.warning("Unable to extract issue from patch submission from:\n%s",
                     output)
Esempio n. 4
0
    def update(self, pin_name, create=False, version=None):
      """Updates a single pin value."""
      if not version:
        LOGGER.debug('Resolving version for pin [%s]', pin_name)
        version = self._editor.get_commit(pin_name)
      elif self._editor._validate:
        LOGGER.debug('Validating pin [%s]', pin_name)
        self._editor.validate_pin(version)

      with self.edit() as pins:
        current = pins.get(pin_name)
        if current == version:
          LOGGER.warning('Pin [%s.%s] is already at version [%s]',
                         self._pin.name, pin_name, current)
          return None

        LOGGER.info('Updating pin [%s.%s]: [%s] => [%s]',
                    self._pin.name, pin_name, current, version)
        if not (current or create):
          raise ReadOnlyError("Pin does not exist [%s]" % (pin_name,))
        pins[pin_name] = version
      return PinUpdate(pin_name, current, version)
Esempio n. 5
0
  def _upload_patch(self, repo_path, commit_msg):
    # Check if the Git repository actually has changes.
    diff_args = ['git', 'diff', '--no-ext-diff', '--exit-code']
    if not LOGGER.isEnabledFor(logging.DEBUG):
      diff_args.append('--quiet')
    rv, diff = execute.call(diff_args, cwd=repo_path)
    LOGGER.debug('Diff for [%s]:\n%s', repo_path, diff)
    if rv == 0:
      LOGGER.warning('No changes in repository; refusing to commit.')
      return

    LOGGER.warning('Creating commit in [%s] with message:\n%s',
                   repo_path, commit_msg)
    execute.check_call(
        ['git', 'checkout', '-b', '_cros_pin'],
        cwd=repo_path)
    execute.check_call(
        ['git', 'commit', '--all', '--message', commit_msg],
        cwd=repo_path)

    LOGGER.debug('Uploading CL!')
    args = [
        'git', 'cl', 'upload',
        '--bypass-hooks', # The CQ will take care of them!
        '-t', commit_msg,
        '-m', 'Auto-generated by `%s`' % (__name__,),
        '-f',
        ]
    if self._cq:
      print 'Commit? [Y/n]:',
      input_string = raw_input()
      if input_string != '' and not distutils.util.strtobool(input_string):
        LOGGER.warning('User opted not to commit; aborting.')
        return
      args.append('--use-commit-queue')
    if not self._reviewers:
      args.append('--tbr-owners')

    output = execute.check_call(args, cwd=repo_path, dry_run=self._dry_run)
    issue = None
    for line in output.splitlines():
      match = self.RE_ISSUE_CREATED.match(line)
      if match:
        issue = match.group(1)
        LOGGER.debug('Extracted issue from output: %s', issue)
        self._issues.add(issue)
        break
    else:
      LOGGER.warning("Unable to extract issue from patch submission.")
Esempio n. 6
0
def subcommand_update(args):
  """Update a single Chromite pin."""
  require = (args.target != 'existing')
  target_pins = []
  if args.target in ('external', 'both', 'existing'):
    target_pins.append(pinfile.EXTERNAL)
  if args.target in ('internal', 'both', 'existing'):
    target_pins.append(pinfile.INTERNAL)

  with checkout_for_args(args) as c:
    pfe = pinfile_editor_from_args(args, c)
    tracker = UpdateTracker.from_args(args, c)

    for pin in target_pins:
      logging.debug('Updating target pin [%s]', pin)

      # Update the pin.
      pf = pfe.load(pin)
      if not (require or pf.has_pin(args.name)):
        LOGGER.debug('Pin not found in [%s]. Only updating existing pins.', pin)
        continue

      update = pf.update(args.name, version=args.version, create=require)
      if not update:
        LOGGER.debug('Did not update pins for [%s]', pin)
        continue
      tracker.add(pin, update)
      LOGGER.debug('Updated pin set: %s', update)

    if not tracker:
      LOGGER.error('No pins were updated.')
      return 1

    # Regenerate slave pools for affected masters.
    tracker.update()
    for i in tracker.issues:
      LOGGER.warning('Created Issue: %s', i)
  return 0
Esempio n. 7
0
def subcommand_update(args):
  """Update a single Chromite pin."""
  require = (args.target != 'existing')
  target_pins = []
  if args.target in ('external', 'both', 'existing'):
    target_pins.append(pinfile.EXTERNAL)
  if args.target in ('internal', 'both', 'existing'):
    target_pins.append(pinfile.INTERNAL)

  with checkout_for_args(args) as c:
    pfe = pinfile_editor_from_args(args, c)
    tracker = UpdateTracker.from_args(args, c)

    for pin in target_pins:
      logging.debug('Updating target pin [%s]', pin)

      # Update the pin.
      pf = pfe.load(pin)
      if not (require or pf.has_pin(args.name)):
        LOGGER.debug('Pin not found in [%s]. Only updating existing pins.', pin)
        continue

      update = pf.update(args.name, version=args.version, create=require)
      if not update:
        LOGGER.debug('Did not update pins for [%s]', pin)
        continue
      tracker.add(pin, update)

    LOGGER.debug('Updated pin set: %s', update)
    if not tracker:
      LOGGER.error('No pins were updated.')
      return 1

    # Regenerate slave pools for affected masters.
    tracker.update()
    for i in tracker.issues:
      LOGGER.warning('Created Issue: %s', i)
  return 0
Esempio n. 8
0
        def update(self, pin_name, create=False, version=None):
            """Updates a single pin value."""
            if not version:
                LOGGER.debug('Resolving version for pin [%s]', pin_name)
                version = self._editor.get_commit(pin_name)
            elif self._editor._validate:
                LOGGER.debug('Validating pin [%s]', pin_name)
                self._editor.validate_pin(version)

            with self.edit() as pins:
                current = pins.get(pin_name)
                if current == version:
                    LOGGER.warning('Pin [%s.%s] is already at version [%s]',
                                   self._pin.name, pin_name, current)
                    return None

                LOGGER.info('Updating pin [%s.%s]: [%s] => [%s]',
                            self._pin.name, pin_name, current, version)
                if not (current or create):
                    raise ReadOnlyError("Pin does not exist [%s]" %
                                        (pin_name, ))
                pins[pin_name] = version
            return PinUpdate(pin_name, current, version)
Esempio n. 9
0
 def log_failure(_function, path, excinfo):
     LOGGER.warning('Failed when destroying [%s]: %s', path,
                    excinfo[1].message)