Skip to content

Commit

Permalink
workaround for getting main_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
evertonstz committed Dec 16, 2019
1 parent c3857b1 commit 6794d03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
15 changes: 13 additions & 2 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. """

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
Expand Down
14 changes: 7 additions & 7 deletions pynps/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pynps/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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


Expand Down

0 comments on commit 6794d03

Please sign in to comment.