Commit 333087e2 authored by agable@chromium.org's avatar agable@chromium.org

Fix upload.py to properly use a local logger

When rietveld.py overrides upload.py's logging module, it generally works fine...
until someone tries to run upload.py with any level of verbosity. Then the
calls to logging.getLogger and logging.INFO/logging.DEBUG fail. This patches
upload.py to properly use a module-scope logger so that rietveld.py doesn't
have to perform invasive surgery, and everything just works.

This version of upload.py taken from upstream Rietveld at:
changeset:   1267:d7b39eca7dbe
branch:      chromium

R=djacques@chromium.org, maruel@chromium.org

Review URL: https://codereview.chromium.org/221423007

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@262793 0039d316-1c4b-4281-b951-d872f2087c98
parent 1f4e71b0
......@@ -30,10 +30,7 @@ from third_party import upload
import third_party.oauth2client.client as oa2client
from third_party import httplib2
# Hack out upload logging.info()
upload.logging = logging.getLogger('upload')
# Mac pylint choke on this line.
upload.logging.setLevel(logging.WARNING) # pylint: disable=E1103
upload.LOGGER.setLevel(logging.WARNING) # pylint: disable=E1103
class Rietveld(object):
......
......@@ -78,6 +78,7 @@ except ImportError:
# 2: Info logs.
# 3: Debug logs.
verbosity = 1
LOGGER = logging.getLogger('upload')
# The account type used for authentication.
# This line could be changed by the review server (see handler for
......@@ -270,9 +271,9 @@ class AbstractRpcServer(object):
self.account_type = account_type
self.opener = self._GetOpener()
if self.host_override:
logging.info("Server: %s; Host: %s", self.host, self.host_override)
LOGGER.info("Server: %s; Host: %s", self.host, self.host_override)
else:
logging.info("Server: %s", self.host)
LOGGER.info("Server: %s", self.host)
def _GetOpener(self):
"""Returns an OpenerDirector for making HTTP requests.
......@@ -284,7 +285,7 @@ class AbstractRpcServer(object):
def _CreateRequest(self, url, data=None):
"""Creates a new urllib request."""
logging.debug("Creating request for: '%s' with payload:\n%s", url, data)
LOGGER.debug("Creating request for: '%s' with payload:\n%s", url, data)
req = urllib2.Request(url, data=data, headers={"Accept": "text/plain"})
if self.host_override:
req.add_header("Host", self.host_override)
......@@ -931,7 +932,7 @@ def GetRpcServer(server, email=None, host_override=None, save_cookies=True,
if re.match(r'(http://)?localhost([:/]|$)', host):
if email is None:
email = "test@example.com"
logging.info("Using debug user %s. Override with --email" % email)
LOGGER.info("Using debug user %s. Override with --email" % email)
server = HttpRpcServer(
server,
lambda: (email, "password"),
......@@ -1017,7 +1018,7 @@ def RunShellWithReturnCodeAndStderr(command, print_output=False,
Returns:
Tuple (stdout, stderr, return code)
"""
logging.info("Running %s", command)
LOGGER.info("Running %s", command)
env = env.copy()
env['LC_MESSAGES'] = 'C'
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
......@@ -1279,7 +1280,7 @@ class SubversionVCS(VersionControlSystem):
path = path + "/"
base = urlparse.urlunparse((scheme, netloc, path, params,
query, fragment))
logging.info("Guessed %sbase = %s", guess, base)
LOGGER.info("Guessed %sbase = %s", guess, base)
return base
if required:
ErrorExit("Can't find URL in output from svn info")
......@@ -1307,7 +1308,7 @@ class SubversionVCS(VersionControlSystem):
for line in data.splitlines():
if line.startswith("Index:") or line.startswith("Property changes on:"):
count += 1
logging.info(line)
LOGGER.info(line)
if not count:
ErrorExit("No valid patches found in output from svn diff")
return data
......@@ -1736,7 +1737,7 @@ class CVSVCS(VersionControlSystem):
for line in data.splitlines():
if line.startswith("Index:"):
count += 1
logging.info(line)
LOGGER.info(line)
if not count:
ErrorExit("No valid patches found in output from cvs diff")
......@@ -1798,7 +1799,7 @@ class MercurialVCS(VersionControlSystem):
svndiff.append("Index: %s" % filename)
svndiff.append("=" * 67)
filecount += 1
logging.info(line)
LOGGER.info(line)
else:
svndiff.append(line)
if not filecount:
......@@ -2527,9 +2528,9 @@ def RealMain(argv, data=None):
global verbosity
verbosity = options.verbose
if verbosity >= 3:
logging.getLogger().setLevel(logging.DEBUG)
LOGGER.setLevel(logging.DEBUG)
elif verbosity >= 2:
logging.getLogger().setLevel(logging.INFO)
LOGGER.setLevel(logging.INFO)
vcs = GuessVCS(options)
......@@ -2547,7 +2548,7 @@ def RealMain(argv, data=None):
if not base and options.download_base:
options.download_base = True
logging.info("Enabled upload of base file")
LOGGER.info("Enabled upload of base file")
if not options.assume_yes:
vcs.CheckForUnknownFiles()
if data is None:
......@@ -2579,7 +2580,7 @@ def RealMain(argv, data=None):
b = urlparse.urlparse(base)
username, netloc = urllib.splituser(b.netloc)
if username:
logging.info("Removed username from base URL")
LOGGER.info("Removed username from base URL")
base = urlparse.urlunparse((b.scheme, netloc, b.path, b.params,
b.query, b.fragment))
form_fields.append(("base", base))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment