Browse Source

Merge branch 'release/0.3.0'

liuyuqi-dellpc 1 year ago
parent
commit
ee1b57cfb3
4 changed files with 18 additions and 3 deletions
  1. 3 0
      .gitignore
  2. 2 1
      client.py
  3. 4 2
      fgh/config.py
  4. 9 0
      fgh/utils/frozen_dir.py

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+*.pyc
+
+.env

+ 2 - 1
client.py

@@ -9,6 +9,7 @@
 
 import os,sys,re
 import argparse
+from fgh.utils.frozen_dir import get_app_path
 
 class Client:
     help_str ="""
@@ -32,7 +33,7 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
 
     def read_config(self):
         import dotenv
-        current_dir = os.getcwd()
+        current_dir = get_app_path()
         dotenv.load_dotenv(os.path.join(current_dir, '.env'))
         fgit_host = os.getenv('FGH_HOST')
         try:

+ 4 - 2
fgh/config.py

@@ -7,11 +7,13 @@
 @Desc    :   config
 """
 
-import os
+import os, sys
 from dotenv import load_dotenv
+from fgh.utils.frozen_dir import get_app_path
 
 if os.path.exists('.env'):
-    load_dotenv('.env', verbose=True)
+    app_path =  get_app_path()
+    load_dotenv(os.path.join(app_path, '.env'), verbose=True)
 
 class BaseConfig:
     ''' 基础配置 '''

+ 9 - 0
fgh/utils/frozen_dir.py

@@ -0,0 +1,9 @@
+import sys  
+import os  
+   
+def get_app_path() -> str:  
+    """Returns the base application path."""  
+    if hasattr(sys, 'frozen'):  
+        # Handles PyInstaller  
+        return os.path.dirname(sys.executable)  #使用 pyinstaller 打包后的 exe 目录  
+    return os.path.dirname(os.path.dirname(os.path.dirname(__file__))) # 没打包前的py目录