As suggested by pep8 don't compare boolean values or empty sequences
Refactoring to improve code style as suggested by pep8. - "rc" and "status" variables cannot be None beacause the process is terminated after the "run_command_status" - It's better to ignore an empty "username" Change-Id: I8a34f4ab9e05d91786ce6d62e4db96811787b633
This commit is contained in:
parent
d94e3a3431
commit
c243d80af9
|
@ -162,7 +162,7 @@ def run_command_exc(klazz, *argv, **env):
|
||||||
klazz should be derived from CommandFailed
|
klazz should be derived from CommandFailed
|
||||||
"""
|
"""
|
||||||
(rc, output) = run_command_status(*argv, **env)
|
(rc, output) = run_command_status(*argv, **env)
|
||||||
if rc != 0:
|
if rc:
|
||||||
raise klazz(rc, output, argv, env)
|
raise klazz(rc, output, argv, env)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ def run_custom_script(action):
|
||||||
returns.append((status, output, fpath))
|
returns.append((status, output, fpath))
|
||||||
|
|
||||||
for (status, output, path) in returns:
|
for (status, output, path) in returns:
|
||||||
if status is not None and status != 0:
|
if status:
|
||||||
raise CustomScriptException(status, output, [path], {})
|
raise CustomScriptException(status, output, [path], {})
|
||||||
elif output and VERBOSE:
|
elif output and VERBOSE:
|
||||||
print("script %s output is:" % (path))
|
print("script %s output is:" % (path))
|
||||||
|
@ -337,10 +337,10 @@ def set_hooks_commit_msg(remote, target_file):
|
||||||
else:
|
else:
|
||||||
(hostname, username, port, project_name) = \
|
(hostname, username, port, project_name) = \
|
||||||
parse_gerrit_ssh_params_from_git_url(remote_url)
|
parse_gerrit_ssh_params_from_git_url(remote_url)
|
||||||
if username is None:
|
if username:
|
||||||
userhost = hostname
|
|
||||||
else:
|
|
||||||
userhost = "%s@%s" % (username, hostname)
|
userhost = "%s@%s" % (username, hostname)
|
||||||
|
else:
|
||||||
|
userhost = hostname
|
||||||
# OS independent target file
|
# OS independent target file
|
||||||
scp_target_file = target_file.replace(os.sep, "/")
|
scp_target_file = target_file.replace(os.sep, "/")
|
||||||
cmd = ["scp", userhost + ":hooks/commit-msg", scp_target_file]
|
cmd = ["scp", userhost + ":hooks/commit-msg", scp_target_file]
|
||||||
|
@ -375,10 +375,10 @@ def make_remote_url(scheme, username, hostname, port, project):
|
||||||
if port is None and scheme == 'ssh':
|
if port is None and scheme == 'ssh':
|
||||||
port = 29418
|
port = 29418
|
||||||
hostport = '%s:%s' % (hostname, port) if port else hostname
|
hostport = '%s:%s' % (hostname, port) if port else hostname
|
||||||
if username is None:
|
if username:
|
||||||
return "%s://%s/%s" % (scheme, hostport, project)
|
|
||||||
else:
|
|
||||||
return "%s://%s@%s/%s" % (scheme, username, hostport, project)
|
return "%s://%s@%s/%s" % (scheme, username, hostport, project)
|
||||||
|
else:
|
||||||
|
return "%s://%s/%s" % (scheme, hostport, project)
|
||||||
|
|
||||||
|
|
||||||
def add_remote(scheme, hostname, port, project, remote, usepushurl):
|
def add_remote(scheme, hostname, port, project, remote, usepushurl):
|
||||||
|
@ -412,7 +412,7 @@ def add_remote(scheme, hostname, port, project, remote, usepushurl):
|
||||||
print("\t%s" % remote_url)
|
print("\t%s" % remote_url)
|
||||||
|
|
||||||
(status, remote_output) = run_command_status(cmd)
|
(status, remote_output) = run_command_status(cmd)
|
||||||
if status != 0:
|
if status:
|
||||||
raise CommandFailed(status, remote_output, cmd, {})
|
raise CommandFailed(status, remote_output, cmd, {})
|
||||||
|
|
||||||
if asked_for_username:
|
if asked_for_username:
|
||||||
|
|
Loading…
Reference in New Issue