Don't use instances of complex types as a default value in args
This can produce unexpected buthurt (at least for me).
Cause python has super strange behavior in this case.
E.g.
def a(t=[]):
t.append(1)
print(t)
a() # prints [1]
a() # prints [1, 1]
Change-Id: Ie5287dd4c958d2d1ccaf98486b9522a2d2c18724
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index eeb175f..1de6147 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -82,7 +82,8 @@
pass
-def run_command(cmd, status=False, env={}):
+def run_command(cmd, status=False, env=None):
+ env = env or {}
cmd_list = shlex.split(str(cmd))
newenv = os.environ
newenv.update(env)
@@ -97,25 +98,29 @@
return out.strip()
-def run_command_status(cmd, env={}):
+def run_command_status(cmd, env=None):
+ env = env or {}
return run_command(cmd, True, env)
-def git_command(repo_dir, sub_cmd, env={}):
+def git_command(repo_dir, sub_cmd, env=None):
+ env = env or {}
git_dir = os.path.join(repo_dir, '.git')
cmd = "git --git-dir=%s --work-tree=%s %s" % (git_dir, repo_dir, sub_cmd)
status, _ = run_command(cmd, True, env)
return status
-def git_command_output(repo_dir, sub_cmd, env={}):
+def git_command_output(repo_dir, sub_cmd, env=None):
+ env = env or {}
git_dir = os.path.join(repo_dir, '.git')
cmd = "git --git-dir=%s --work-tree=%s %s" % (git_dir, repo_dir, sub_cmd)
status, out = run_command(cmd, True, env)
return (status, out)
-def fetch_config(project, remote_url, repo_path, env={}):
+def fetch_config(project, remote_url, repo_path, env=None):
+ env = env or {}
# Poll for refs/meta/config as gerrit may not have written it out for
# us yet.
for x in range(10):
@@ -178,7 +183,8 @@
return status != 0
-def push_acl_config(project, remote_url, repo_path, gitid, env={}):
+def push_acl_config(project, remote_url, repo_path, gitid, env=None):
+ env = env or {}
cmd = "commit -a -m'Update project config.' --author='%s'" % gitid
status = git_command(repo_path, cmd)
if status != 0: