Apply Python 3 futurize transform lib2to3.fixes.fix_has_key.

This commit is contained in:
Tim Abbott 2015-11-01 08:10:01 -08:00
parent a49e641719
commit 5f1d06390c

View file

@ -575,7 +575,7 @@ def gitBranchExists(branch):
_gitConfig = {} _gitConfig = {}
def gitConfig(key): def gitConfig(key):
if not _gitConfig.has_key(key): if key not in _gitConfig:
cmd = [ "git", "config", key ] cmd = [ "git", "config", key ]
s = read_pipe(cmd, ignore_error=True) s = read_pipe(cmd, ignore_error=True)
_gitConfig[key] = s.strip() _gitConfig[key] = s.strip()
@ -586,7 +586,7 @@ def gitConfigBool(key):
variable is set to true, and False if set to false or not present variable is set to true, and False if set to false or not present
in the config.""" in the config."""
if not _gitConfig.has_key(key): if key not in _gitConfig:
cmd = [ "git", "config", "--bool", key ] cmd = [ "git", "config", "--bool", key ]
s = read_pipe(cmd, ignore_error=True) s = read_pipe(cmd, ignore_error=True)
v = s.strip() v = s.strip()
@ -594,7 +594,7 @@ def gitConfigBool(key):
return _gitConfig[key] return _gitConfig[key]
def gitConfigList(key): def gitConfigList(key):
if not _gitConfig.has_key(key): if key not in _gitConfig:
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True) s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
_gitConfig[key] = s.strip().split(os.linesep) _gitConfig[key] = s.strip().split(os.linesep)
return _gitConfig[key] return _gitConfig[key]
@ -650,7 +650,7 @@ def findUpstreamBranchPoint(head = "HEAD"):
tip = branches[branch] tip = branches[branch]
log = extractLogMessageFromGitCommit(tip) log = extractLogMessageFromGitCommit(tip)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
if settings.has_key("depot-paths"): if "depot-paths" in settings:
paths = ",".join(settings["depot-paths"]) paths = ",".join(settings["depot-paths"])
branchByDepotPath[paths] = "remotes/p4/" + branch branchByDepotPath[paths] = "remotes/p4/" + branch
@ -660,9 +660,9 @@ def findUpstreamBranchPoint(head = "HEAD"):
commit = head + "~%s" % parent commit = head + "~%s" % parent
log = extractLogMessageFromGitCommit(commit) log = extractLogMessageFromGitCommit(commit)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
if settings.has_key("depot-paths"): if "depot-paths" in settings:
paths = ",".join(settings["depot-paths"]) paths = ",".join(settings["depot-paths"])
if branchByDepotPath.has_key(paths): if paths in branchByDepotPath:
return [branchByDepotPath[paths], settings] return [branchByDepotPath[paths], settings]
parent = parent + 1 parent = parent + 1
@ -686,8 +686,8 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
originHead = line originHead = line
original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead)) original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead))
if (not original.has_key('depot-paths') if ('depot-paths' not in original
or not original.has_key('change')): or 'change' not in original):
continue continue
update = False update = False
@ -697,7 +697,7 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
update = True update = True
else: else:
settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead)) settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
if settings.has_key('change') > 0: if ('change' in settings) > 0:
if settings['depot-paths'] == original['depot-paths']: if settings['depot-paths'] == original['depot-paths']:
originP4Change = int(original['change']) originP4Change = int(original['change'])
p4Change = int(settings['change']) p4Change = int(settings['change'])
@ -836,7 +836,7 @@ class P4UserMap:
results = p4CmdList("user -o") results = p4CmdList("user -o")
for r in results: for r in results:
if r.has_key('User'): if 'User' in r:
self.myP4UserId = r['User'] self.myP4UserId = r['User']
return r['User'] return r['User']
die("Could not find your p4 user id") die("Could not find your p4 user id")
@ -860,7 +860,7 @@ class P4UserMap:
self.emails = {} self.emails = {}
for output in p4CmdList("users"): for output in p4CmdList("users"):
if not output.has_key("User"): if "User" not in output:
continue continue
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">" self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
self.emails[output["Email"]] = output["User"] self.emails[output["Email"]] = output["User"]
@ -1081,7 +1081,7 @@ class P4Submit(Command, P4UserMap):
gitEmail = read_pipe(["git", "log", "--max-count=1", gitEmail = read_pipe(["git", "log", "--max-count=1",
"--format=%ae", id]) "--format=%ae", id])
gitEmail = gitEmail.strip() gitEmail = gitEmail.strip()
if not self.emails.has_key(gitEmail): if gitEmail not in self.emails:
return (None,gitEmail) return (None,gitEmail)
else: else:
return (self.emails[gitEmail],gitEmail) return (self.emails[gitEmail],gitEmail)
@ -1105,14 +1105,14 @@ class P4Submit(Command, P4UserMap):
results = p4CmdList("client -o") # find the current client results = p4CmdList("client -o") # find the current client
client = None client = None
for r in results: for r in results:
if r.has_key('Client'): if 'Client' in r:
client = r['Client'] client = r['Client']
break break
if not client: if not client:
die("could not get client spec") die("could not get client spec")
results = p4CmdList(["changes", "-c", client, "-m", "1"]) results = p4CmdList(["changes", "-c", client, "-m", "1"])
for r in results: for r in results:
if r.has_key('change'): if 'change' in r:
return r['change'] return r['change']
die("Could not get changelist number for last submit - cannot patch up user details") die("Could not get changelist number for last submit - cannot patch up user details")
@ -1130,10 +1130,10 @@ class P4Submit(Command, P4UserMap):
result = p4CmdList("change -f -i", stdin=input) result = p4CmdList("change -f -i", stdin=input)
for r in result: for r in result:
if r.has_key('code'): if 'code' in r:
if r['code'] == 'error': if r['code'] == 'error':
die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data'])) die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data']))
if r.has_key('data'): if 'data' in r:
print("Updated user field for changelist %s to %s" % (changelist, newUser)) print("Updated user field for changelist %s to %s" % (changelist, newUser))
return return
die("Could not modify user field of changelist %s to %s" % (changelist, newUser)) die("Could not modify user field of changelist %s to %s" % (changelist, newUser))
@ -1143,7 +1143,7 @@ class P4Submit(Command, P4UserMap):
# which are required to modify changelists. # which are required to modify changelists.
results = p4CmdList(["protects", self.depotPath]) results = p4CmdList(["protects", self.depotPath])
for r in results: for r in results:
if r.has_key('perm'): if 'perm' in r:
if r['perm'] == 'admin': if r['perm'] == 'admin':
return 1 return 1
if r['perm'] == 'super': if r['perm'] == 'super':
@ -1195,7 +1195,7 @@ class P4Submit(Command, P4UserMap):
mtime = os.stat(template_file).st_mtime mtime = os.stat(template_file).st_mtime
# invoke the editor # invoke the editor
if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""): if "P4EDITOR" in os.environ and (os.environ.get("P4EDITOR") != ""):
editor = os.environ.get("P4EDITOR") editor = os.environ.get("P4EDITOR")
else: else:
editor = read_pipe("git var GIT_EDITOR").strip() editor = read_pipe("git var GIT_EDITOR").strip()
@ -1379,7 +1379,7 @@ class P4Submit(Command, P4UserMap):
separatorLine = "######## everything below this line is just the diff #######\n" separatorLine = "######## everything below this line is just the diff #######\n"
# diff # diff
if os.environ.has_key("P4DIFF"): if "P4DIFF" in os.environ:
del(os.environ["P4DIFF"]) del(os.environ["P4DIFF"])
diff = "" diff = ""
for editedFile in editedFiles: for editedFile in editedFiles:
@ -1503,7 +1503,7 @@ class P4Submit(Command, P4UserMap):
logMessage = extractLogMessageFromGitCommit(name) logMessage = extractLogMessageFromGitCommit(name)
values = extractSettingsGitLog(logMessage) values = extractSettingsGitLog(logMessage)
if not values.has_key('change'): if 'change' not in values:
# a tag pointing to something not sent to p4; ignore # a tag pointing to something not sent to p4; ignore
if verbose: if verbose:
print "git tag %s does not give a p4 commit" % name print "git tag %s does not give a p4 commit" % name
@ -1939,7 +1939,7 @@ class P4Sync(Command, P4UserMap):
for path in self.cloneExclude] for path in self.cloneExclude]
files = [] files = []
fnum = 0 fnum = 0
while commit.has_key("depotFile%s" % fnum): while "depotFile%s" % fnum in commit:
path = commit["depotFile%s" % fnum] path = commit["depotFile%s" % fnum]
if [p for p in self.cloneExclude if [p for p in self.cloneExclude
@ -2003,7 +2003,7 @@ class P4Sync(Command, P4UserMap):
branches = {} branches = {}
fnum = 0 fnum = 0
while commit.has_key("depotFile%s" % fnum): while "depotFile%s" % fnum in commit:
path = commit["depotFile%s" % fnum] path = commit["depotFile%s" % fnum]
found = [p for p in self.depotPaths found = [p for p in self.depotPaths
if p4PathStartsWith(path, p)] if p4PathStartsWith(path, p)]
@ -2141,7 +2141,7 @@ class P4Sync(Command, P4UserMap):
else: else:
die("Error from p4 print: %s" % err) die("Error from p4 print: %s" % err)
if marshalled.has_key('depotFile') and self.stream_have_file_info: if 'depotFile' in marshalled and self.stream_have_file_info:
# start of a new file - output the old one first # start of a new file - output the old one first
self.streamOneP4File(self.stream_file, self.stream_contents) self.streamOneP4File(self.stream_file, self.stream_contents)
self.stream_file = {} self.stream_file = {}
@ -2197,7 +2197,7 @@ class P4Sync(Command, P4UserMap):
cb=streamP4FilesCbSelf) cb=streamP4FilesCbSelf)
# do the last chunk # do the last chunk
if self.stream_file.has_key('depotFile'): if 'depotFile' in self.stream_file:
self.streamOneP4File(self.stream_file, self.stream_contents) self.streamOneP4File(self.stream_file, self.stream_contents)
def make_email(self, userid): def make_email(self, userid):
@ -2213,7 +2213,7 @@ class P4Sync(Command, P4UserMap):
gitStream.write("tag %s\n" % labelName) gitStream.write("tag %s\n" % labelName)
gitStream.write("from %s\n" % commit) gitStream.write("from %s\n" % commit)
if labelDetails.has_key('Owner'): if 'Owner' in labelDetails:
owner = labelDetails["Owner"] owner = labelDetails["Owner"]
else: else:
owner = None owner = None
@ -2229,7 +2229,7 @@ class P4Sync(Command, P4UserMap):
gitStream.write("tagger %s\n" % tagger) gitStream.write("tagger %s\n" % tagger)
print "labelDetails=",labelDetails print "labelDetails=",labelDetails
if labelDetails.has_key('Description'): if 'Description' in labelDetails:
description = labelDetails['Description'] description = labelDetails['Description']
else: else:
description = 'Label from git p4' description = 'Label from git p4'
@ -2285,7 +2285,7 @@ class P4Sync(Command, P4UserMap):
change = int(details["change"]) change = int(details["change"])
if self.labels.has_key(change): if change in self.labels:
label = self.labels[change] label = self.labels[change]
labelDetails = label[0] labelDetails = label[0]
labelRevisions = label[1] labelRevisions = label[1]
@ -2374,7 +2374,7 @@ class P4Sync(Command, P4UserMap):
change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name) change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name)
for p in self.depotPaths]) for p in self.depotPaths])
if change.has_key('change'): if 'change' in change:
# find the corresponding git commit; take the oldest commit # find the corresponding git commit; take the oldest commit
changelist = int(change['change']) changelist = int(change['change'])
gitCommit = read_pipe(["git", "rev-list", "--max-count=1", gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
@ -2427,7 +2427,7 @@ class P4Sync(Command, P4UserMap):
for info in p4CmdList(command): for info in p4CmdList(command):
details = p4Cmd(["branch", "-o", info["branch"]]) details = p4Cmd(["branch", "-o", info["branch"]])
viewIdx = 0 viewIdx = 0
while details.has_key("View%s" % viewIdx): while "View%s" % viewIdx in details:
paths = details["View%s" % viewIdx].split(" ") paths = details["View%s" % viewIdx].split(" ")
viewIdx = viewIdx + 1 viewIdx = viewIdx + 1
# require standard //depot/foo/... //depot/bar/... mapping # require standard //depot/foo/... //depot/bar/... mapping
@ -2493,7 +2493,7 @@ class P4Sync(Command, P4UserMap):
d["options"] = ' '.join(sorted(option_keys.keys())) d["options"] = ' '.join(sorted(option_keys.keys()))
def readOptions(self, d): def readOptions(self, d):
self.keepRepoPath = (d.has_key('options') self.keepRepoPath = ('options' in d
and ('keepRepoPath' in d['options'])) and ('keepRepoPath' in d['options']))
def gitRefForBranch(self, branch): def gitRefForBranch(self, branch):
@ -2794,8 +2794,8 @@ class P4Sync(Command, P4UserMap):
settings = extractSettingsGitLog(logMsg) settings = extractSettingsGitLog(logMsg)
self.readOptions(settings) self.readOptions(settings)
if (settings.has_key('depot-paths') if ('depot-paths' in settings
and settings.has_key ('change')): and 'change' in settings):
change = int(settings['change']) + 1 change = int(settings['change']) + 1
p4Change = max(p4Change, change) p4Change = max(p4Change, change)