diff --git a/__main__.py b/__main__.py index 0cca332..ec43a35 100644 --- a/__main__.py +++ b/__main__.py @@ -14,13 +14,24 @@ along with this program. If not, see . """ from pynps.cli import cli_main -from pynps.functions import is_interactive + +# external +import os, sys, inspect + +def get_script_dir(follow_symlinks=True): + if getattr(sys, 'frozen', False): # py2exe, PyInstaller, cx_Freeze + path = os.path.abspath(sys.executable) + else: + path = inspect.getabsfile(get_script_dir) + if follow_symlinks: + path = os.path.realpath(path) + return os.path.dirname(path) def main(): #if is_interactive() == False: if True: # runs on tty - cli_main() + cli_main(maindir=get_script_dir()) else: # TODO: call cmd file pass diff --git a/pynps/cli/cli.py b/pynps/cli/cli.py index 7355b4d..9799dd3 100644 --- a/pynps/cli/cli.py +++ b/pynps/cli/cli.py @@ -22,18 +22,18 @@ #external imports from uuid import uuid4 as id_gen -def cli_main(): +def cli_main(maindir): """implement pynps cli interface""" if get_system() == 'Linux': CONFIGFOLDER = f"{os.getenv('HOME')}/.config/pyNPS" config_file = f"{CONFIGFOLDER}/settings.ini" elif get_system() == 'Windows': - CONFIGFOLDER = f"{get_script_dir()}/pynps_config/" + CONFIGFOLDER = f"{maindir}/pynps_config/" config_file = f"{CONFIGFOLDER}/settings.ini" else: CONFIGFOLDER = "" - config_file = "" + config_file = "" # create conf file if os.path.isfile(config_file) == False: @@ -67,10 +67,10 @@ def cli_main(): sys.exit(1) # making vars - DBFOLDER = fix_folder_syntax(config['pyNPS']['databasefolder']) - DLFOLDER = fix_folder_syntax(config['pyNPS']['downloadfolder']) - PKG2ZIP = fix_folder_syntax(config['BinaryLocations']['pkg2zip_location']) - WGET = fix_folder_syntax(config['BinaryLocations']['wget_location']) + DBFOLDER = fix_folder_syntax(config['pyNPS']['databasefolder'], maindir) + DLFOLDER = fix_folder_syntax(config['pyNPS']['downloadfolder'], maindir) + PKG2ZIP = fix_folder_syntax(config['BinaryLocations']['pkg2zip_location'], maindir) + WGET = fix_folder_syntax(config['BinaryLocations']['wget_location'], maindir) # tests existence of pkg2zip PKG2ZIP = check_pkg2zip(PKG2ZIP, CONFIGFOLDER) diff --git a/pynps/functions/functions.py b/pynps/functions/functions.py index 1f03c39..87c56fa 100644 --- a/pynps/functions/functions.py +++ b/pynps/functions/functions.py @@ -582,7 +582,7 @@ def runner( list, cwd): return process -def fix_folder_syntax(folder): +def fix_folder_syntax(folder, maindir): """this function is used to fix slashes in the directories provided by the user's settings.ini""" @@ -594,7 +594,7 @@ def fix_folder_syntax(folder): # parsing ./ if new_folder.startswith("./"): - new_folder = f"{get_script_dir()}/{new_folder[2:]}" + new_folder = f"{maindir}/{new_folder[2:]}" return new_folder