From 072b65bbdf6e76070c01f95d467f2d3c522fa306 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Sat, 3 Apr 2021 01:12:31 -0600 Subject: [PATCH 1/8] fix bad_dir check, and make warning louder --- installinstallmacos.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index 21b2929..d18afc0 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -531,15 +531,18 @@ def main(): sys.exit('This command requires root (to install packages), so please ' 'run again with sudo or as root.') + home_dir = os.path.expanduser("~") current_dir = os.getcwd() - if os.path.expanduser("~") in current_dir: - bad_dirs = ['Documents', 'Desktop', 'Downloads', 'Library'] - for bad_dir in bad_dirs: - if bad_dir in os.path.split(current_dir): - print('Running this script from %s may not work as expected. ' - 'If this does not run as expected, please run again from ' - 'somewhere else, such as /Users/Shared.' - % current_dir, file=sys.stderr) + bad_dirs = ['Documents', 'Desktop', 'Downloads', 'Library'] + for bad_dir in bad_dirs: + if home_dir + os.path.sep + bad_dir in current_dir: + print('*********************************************************', file=sys.stderr) + print('*** Running this script from %s may not work as expected.' % current_dir, file=sys.stderr) + print('*** If this does not run as expected, please run again from', file=sys.stderr) + print('*** somewhere else, such as /Users/Shared.', file=sys.stderr) + print('*********************************************************', file=sys.stderr) + else: + print('bad_dir %s not in current_dir %s' % (home_dir + os.path.sep + bad_dir, current_dir)) if args.catalogurl: su_catalog_url = args.catalogurl From 217e987a584e26fb63740a5582330e61a3736631 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Sat, 3 Apr 2021 01:18:04 -0600 Subject: [PATCH 2/8] remove debug print --- installinstallmacos.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index d18afc0..daffeaf 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -541,8 +541,6 @@ def main(): print('*** If this does not run as expected, please run again from', file=sys.stderr) print('*** somewhere else, such as /Users/Shared.', file=sys.stderr) print('*********************************************************', file=sys.stderr) - else: - print('bad_dir %s not in current_dir %s' % (home_dir + os.path.sep + bad_dir, current_dir)) if args.catalogurl: su_catalog_url = args.catalogurl From aeaa732a6f7597828fb1d884902fc83bfd2755b4 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Sat, 3 Apr 2021 01:23:06 -0600 Subject: [PATCH 3/8] make more readable --- installinstallmacos.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index daffeaf..d9b8fb6 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -533,9 +533,10 @@ def main(): home_dir = os.path.expanduser("~") current_dir = os.getcwd() - bad_dirs = ['Documents', 'Desktop', 'Downloads', 'Library'] - for bad_dir in bad_dirs: - if home_dir + os.path.sep + bad_dir in current_dir: + bad_subdirs = ['Documents', 'Desktop', 'Downloads', 'Library'] + for bad_subdir in bad_subdirs: + bad_dir = home_dir + os.path.sep + bad_subdir + if bad_dir in current_dir: print('*********************************************************', file=sys.stderr) print('*** Running this script from %s may not work as expected.' % current_dir, file=sys.stderr) print('*** If this does not run as expected, please run again from', file=sys.stderr) From 55779df5a2921aff5a7ed004e2f845c6d743f305 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Mon, 24 May 2021 12:46:33 -0600 Subject: [PATCH 4/8] use os.path.join --- installinstallmacos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index d9b8fb6..0a92efc 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -535,7 +535,7 @@ def main(): current_dir = os.getcwd() bad_subdirs = ['Documents', 'Desktop', 'Downloads', 'Library'] for bad_subdir in bad_subdirs: - bad_dir = home_dir + os.path.sep + bad_subdir + bad_dir = os.path.join(home_dir, bad_subdir) if bad_dir in current_dir: print('*********************************************************', file=sys.stderr) print('*** Running this script from %s may not work as expected.' % current_dir, file=sys.stderr) From 90dd3b9bc296f1cc5d14ddb36f1877d391764a53 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Mon, 24 May 2021 12:53:45 -0600 Subject: [PATCH 5/8] Fix some pylint warnings --- installinstallmacos.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index 0a92efc..e522f46 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -460,7 +460,7 @@ def os_installer_product_info(catalog, workdir, ignore_cache=False): product_info[product_key]['title'] = dist_info.get('title_from_dist') if not product_info[product_key]['version']: product_info[product_key]['version'] = dist_info.get('VERSION') - + return product_info @@ -538,7 +538,8 @@ def main(): bad_dir = os.path.join(home_dir, bad_subdir) if bad_dir in current_dir: print('*********************************************************', file=sys.stderr) - print('*** Running this script from %s may not work as expected.' % current_dir, file=sys.stderr) + print('*** Running this script from %s may not work as expected.' % current_dir, + file=sys.stderr) print('*** If this does not run as expected, please run again from', file=sys.stderr) print('*** somewhere else, such as /Users/Shared.', file=sys.stderr) print('*********************************************************', file=sys.stderr) From 4f32302c8d8bdf601294e64002ae58bd3ba052ad Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Tue, 25 May 2021 00:16:43 -0600 Subject: [PATCH 6/8] Address comments --- installinstallmacos.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index e522f46..bab5988 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -285,7 +285,7 @@ def replicate_url(full_url, print("Downloading %s..." % full_url) need_download = False try: - output = subprocess.check_output(curl_cmd) + _ = subprocess.check_output(curl_cmd) except subprocess.CalledProcessError as err: if not resumed or not err.output.isdigit(): raise ReplicationError(err) @@ -537,12 +537,12 @@ def main(): for bad_subdir in bad_subdirs: bad_dir = os.path.join(home_dir, bad_subdir) if bad_dir in current_dir: - print('*********************************************************', file=sys.stderr) - print('*** Running this script from %s may not work as expected.' % current_dir, - file=sys.stderr) - print('*** If this does not run as expected, please run again from', file=sys.stderr) - print('*** somewhere else, such as /Users/Shared.', file=sys.stderr) - print('*********************************************************', file=sys.stderr) + print('*********************************************************\n' + '*** Running this script from %s may not work as expected.\n' + '*** If this does not run as expected, please run again\n' + '*** from somewhere else, such as /Users/Shared.\n' + '*********************************************************' + % current_dir, file=sys.stderr) if args.catalogurl: su_catalog_url = args.catalogurl From 999029544be629b77cbb0ebfb779e04353a3639b Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Tue, 25 May 2021 00:21:34 -0600 Subject: [PATCH 7/8] use startswith instead of in --- installinstallmacos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index bab5988..63f8030 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -536,7 +536,7 @@ def main(): bad_subdirs = ['Documents', 'Desktop', 'Downloads', 'Library'] for bad_subdir in bad_subdirs: bad_dir = os.path.join(home_dir, bad_subdir) - if bad_dir in current_dir: + if current_dir.startswith(bad_dir): print('*********************************************************\n' '*** Running this script from %s may not work as expected.\n' '*** If this does not run as expected, please run again\n' From ea4ae17cd1362b7d1f573af6fc16f059dc8d73ae Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Wed, 26 May 2021 12:27:29 -0600 Subject: [PATCH 8/8] revert to avoid future conflict --- installinstallmacos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index 63f8030..80133f9 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -285,7 +285,7 @@ def replicate_url(full_url, print("Downloading %s..." % full_url) need_download = False try: - _ = subprocess.check_output(curl_cmd) + output = subprocess.check_output(curl_cmd) except subprocess.CalledProcessError as err: if not resumed or not err.output.isdigit(): raise ReplicationError(err)