From 764406d64966a027a742193aa426b5936910217c Mon Sep 17 00:00:00 2001 From: Ashish Bijlani Date: Tue, 18 Oct 2022 15:43:38 -0500 Subject: [PATCH] Rename config to '.packj.yaml' for consistent usage Signed-off-by: Ashish Bijlani --- .dockerignore | 1 - packj/config.yaml => .packj.yaml | 0 MANIFEST.in | 2 +- main.py | 4 ++-- packj/main.py | 14 +++----------- setup.py | 26 +++++++++++++------------- 6 files changed, 19 insertions(+), 28 deletions(-) rename packj/config.yaml => .packj.yaml (100%) diff --git a/.dockerignore b/.dockerignore index b7492dc..6673344 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,5 @@ **/__pycache__ **/.DS_Store **/.*.swp -**/.packj.yaml **/sandbox/strace **/sandbox/*.so diff --git a/packj/config.yaml b/.packj.yaml similarity index 100% rename from packj/config.yaml rename to .packj.yaml diff --git a/MANIFEST.in b/MANIFEST.in index e71ccdd..d360ab2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include packj/config.yaml +include packj/.packj.yaml include packj/audit/config/astgen_javascript_smt.config include packj/audit/config/astgen_python_smt.config include packj/audit/config/astgen_ruby_smt.config diff --git a/main.py b/main.py index 07b176b..80f177c 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import re import sys -from packj.main import main_wrapper +from packj.main import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) - sys.exit(main_wrapper()) + sys.exit(main()) diff --git a/packj/main.py b/packj/main.py index 74231b6..5de4284 100644 --- a/packj/main.py +++ b/packj/main.py @@ -10,7 +10,7 @@ print('\n*** WARNING *** Please use Python 3! Exiting.') exit(1) -def main(config:str): +def main(config:str='.packj.yaml'): try: # parse command line args from packj.options import Options @@ -21,6 +21,8 @@ def main(config:str): assert args, 'Failed to get cmdline args!' # configuration file + if not os.path.exists(config): + config = os.path.expanduser(os.path.join('~', f'{config}')) assert os.path.exists(config), f'No {config} file found' # audit request @@ -36,13 +38,3 @@ def main(config:str): except Exception as e: print(str(e)) exit(1) - -def bin_wrapper(): - config = '.packj.yaml' - if not os.path.exists(config): - config = os.path.expanduser(os.path.join('~', os.path.join('.packj', 'config.yaml'))) - return main(config) - -def main_wrapper(): - config = os.path.join(os.path.dirname(__file__), 'config.yaml') - return main(config) diff --git a/setup.py b/setup.py index 0c11a98..4566c1f 100644 --- a/setup.py +++ b/setup.py @@ -37,20 +37,20 @@ def setup_sandbox(build_dir): if make_process.returncode: raise Exception(f'Failed to install sandbox:\n{stderr}') -def copy_config(): - src_path = os.path.join('packj', 'config.yaml') - dst_path = os.path.expanduser(os.path.join('~', f'.{src_path}')) +def copy_config(config='.packj.yaml'): + path = os.path.expanduser(os.path.join('~', f'{config}')) try: - shutil.rmtree(os.path.dirname(dst_path)) + os.remove(path) except: pass - os.mkdir(os.path.dirname(dst_path)) - shutil.copy(src_path, dst_path) + shutil.copy(config, path) -def remove_config(): - dst_path = os.path.expanduser(os.path.join('~', '.packj')) - if os.path.exists(dst_path): - shutil.rmtree(dst_path) +def remove_config(config='.packj.yaml'): + path = os.path.expanduser(os.path.join('~', f'{config}')) + try: + os.remove(path) + except: + pass class custom_install(install): def run(self): @@ -76,9 +76,9 @@ def run(self): 'packj.audit.proto' : ['ruby/*.rb'], }, data_files = [ - (os.path.expanduser(os.path.join('~','.packj')), ['packj/config.yaml']), + (os.path.expanduser(os.path.join('~','.packj.yaml')), ['.packj.yaml']), ], - version = '0.10', + version = '0.11', license='GNU AGPLv3', description = 'Packj flags "risky" open-source packages in your software supply chain', long_description=long_description, @@ -96,7 +96,7 @@ def run(self): requires_dist=REQUIREMENTS, entry_points = { 'console_scripts': [ - 'packj=packj.main:bin_wrapper', + 'packj=packj.main:main', ], }, cmdclass = {