File: download_issue.py

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (86 lines) | stat: -rwxr-xr-x 2,200 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Downloads a patch and changed files from Rietveld.

Prints the patch of the most recent patchset to stdout.
"""

try:
  import base64

  import gerrit_util
  import git_cl
  import optparse
  import os.path
  #  import StringIO
  import sys
  import tarfile
  #import urllib2

  from third_party import colorama
except ImportError as e:
  print(e)
  print('Perhaps you\'re missing depot_tools in your PYTHONPATH.')
  import sys
  sys.exit(1)


def Progress(message):
  print(message, file=sys.stderr)


def DieWithError(message):
  print(message, file=sys.stderr)
  sys.exit(1)


def main(argv):
  parser = optparse.OptionParser()
  parser.set_usage('%prog [options] issue_number')
  parser.description = __doc__.strip()
  options, args = parser.parse_args(argv)
  if len(args) != 1:
    parser.print_help()
    return 0

  change_id = ""
  try:
    issue = int(args[0])
  except ValueError:
    try:
      change_id = str(args[0])
    except ValueError:
      DieWithError('Invalid issue number or change id')

  if not change_id:
    HOST_ = "chromium-review.googlesource.com"
    change_id = gerrit_util.GetChange(HOST_, issue)["change_id"]
  else:
    HOST_ = "googleplex-android-review.git.corp.google.com"
  query = gerrit_util.GetChangeCurrentRevision(HOST_, change_id)[0]
  current_revision_id = query["current_revision"]
  current_revision = query["revisions"][current_revision_id]
  patchset = current_revision["_number"]
  ref = current_revision["ref"]

  # Fetch the current branch.
  Progress("Fetching... " + ref)
  git_cl.RunGit(
      ["fetch", "https://chromium.googlesource.com/chromium/src", ref])
  print('Issue: %d, patchset: %d\n' % (issue, patchset))
  print()
  print(git_cl.RunGit(["show", "FETCH_HEAD"]))
  git_cl.RunGit(["checkout", "FETCH_HEAD"])

  Progress("finished")
  Progress("Run git checkout FETCH_HEAD, to start reviewing.")


if __name__ == '__main__':
  # These affect sys.stdout so do it outside of main() to simplify mocks in
  # unit testing.

  colorama.init()
  sys.exit(main(sys.argv[1:]))