From: Gabriel Filion Date: Sat, 28 Jul 2012 04:54:12 +0000 (-0400) Subject: Remove useless code in main.py around the -d option X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=8023ad2e8a0d451b162359a94da8530c56a8c82f;p=packages%2Fb%2Fbup.git Remove useless code in main.py around the -d option While debugging another problem with BUP_DIR, I saw a part of the code that looked kinda suspicious (not in itself, but in the context of the file): 115 subcmd_env = os.environ 116 if dest_dir: 117 subcmd_env.update({"BUP_DIR" : dest_dir}) the subcmd_env variable is never used in main.py. However, when I removed that part, the -d option stopped working and bup used ~/.bup instead: so it _is_ doing what we want it to. The reason why it's working is that line 115 is actually not creating a copy of the dict, but rather simply pointing to the same dict. so the call to update() actually changes the environment for the main program, which is actually quite alright (e.g. it supercedes the environment variable and ensures that the path given to -d is inherited into subprocesses) Now the problem is that this code is very not obvious about what it does. Plus, it's a couple of useless lines that we need to maintain. Let's just remove any extraneous work and make the addition to the environment triggered by the -d option as obvious and concise as possible. Signed-off-by: Gabriel Filion Reviewed-by: Rob Browning --- diff --git a/main.py b/main.py index 5229b26..67ad011 100755 --- a/main.py +++ b/main.py @@ -78,7 +78,6 @@ except getopt.GetoptError, ex: usage('error: %s' % ex.msg) help_requested = None -dest_dir = None do_profile = False for opt in global_args: @@ -92,7 +91,7 @@ for opt in global_args: elif opt[0] in ['--profile']: do_profile = True elif opt[0] in ['-d', '--bup-dir']: - dest_dir = opt[1] + os.environ['BUP_DIR'] = opt[1] else: usage('error: unexpected option "%s"' % opt[0]) @@ -112,10 +111,6 @@ subcmd_name = subcmd[0] if not subcmd_name: usage() -subcmd_env = os.environ -if dest_dir: - subcmd_env.update({"BUP_DIR" : dest_dir}) - def subpath(s): sp = os.path.join(exepath, 'bup-%s' % s) if not os.path.exists(sp):