From 4a6533e1c906c71adf2c4a46d0a40385d5807319 Mon Sep 17 00:00:00 2001 From: copper Date: Tue, 31 May 2022 13:04:34 +0800 Subject: [PATCH] fix base dir --- ECD.py | 7 ++++++- build.bat | 3 ++- log.txt | 4 ++++ rscder/utils/setting.py | 16 +++++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ECD.py b/ECD.py index 03e9abc..7b1db83 100644 --- a/ECD.py +++ b/ECD.py @@ -1,7 +1,12 @@ +import os +os.environ['PROJ_LIB'] = os.path.join(os.path.dirname(__file__), 'share/proj') +os.environ['GDAL_DATA'] = os.path.join(os.path.dirname(__file__), 'share') +os.environ['ECD_BASEDIR'] = os.path.dirname(__file__) +BASE_DIR = os.path.dirname(__file__) from rscder import MulStart import logging -logging.basicConfig(level=logging.INFO, filename='log.txt', filemode='w', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') +logging.basicConfig(level=logging.INFO, filename=os.path.join(BASE_DIR, 'log.txt'), filemode='a', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') if __name__ == '__main__': diff --git a/build.bat b/build.bat index 5e9fb44..3af2c0c 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,5 @@ -nuitka ECD.py --standalone --plugin-enable=qt-plugins --plugin-enable=numpy --show-progress --include-package=qgis --plugin-enable=pylint-warnings --output-dir=package --windows-icon-from-ico=logo.ico --no-pyi-file --follow-import-to=rscder --include-package=osgeo --include-package=PyQtAds +nuitka ECD.py --standalone --plugin-enable=pyqt5 --include-qt-plugins=sensible,styles --plugin-enable=numpy --show-progress --include-package=qgis --output-dir=package --windows-icon-from-ico=logo.ico +xcopy /Y icons/* package/ECD.dist/ @REM nuitka keygen.py --standalone --plugin-enable=qt-plugins --plugin-enable=numpy --show-progress --plugin-enable=pylint-warnings --output-dir=package --windows-disable-console --windows-icon-from-ico=logo.ico --no-pyi-file diff --git a/log.txt b/log.txt index 14e9d01..2906b78 100644 --- a/log.txt +++ b/log.txt @@ -2,3 +2,7 @@ 2022-05-28 21:40:04,316 - root - INFO - remain_days: 186 2022-05-28 21:40:05,077 - root - INFO - lic data:2022-12-01 00:00:00 2022-05-28 21:40:05,077 - root - INFO - remain_days: 186 +2022-05-31 13:03:21,977 - root - INFO - lic data:2022-12-01 00:00:00 +2022-05-31 13:03:21,997 - root - INFO - remain_days: 183 +2022-05-31 13:03:23,512 - root - INFO - lic data:2022-12-01 00:00:00 +2022-05-31 13:03:23,512 - root - INFO - remain_days: 183 diff --git a/rscder/utils/setting.py b/rscder/utils/setting.py index f268413..4c890a4 100644 --- a/rscder/utils/setting.py +++ b/rscder/utils/setting.py @@ -4,7 +4,7 @@ from typing import Tuple from PyQt5.QtCore import QSettings from rscder.utils.license import LicenseHelper import yaml - +BASE_DIR = os.environ['ECD_BASEDIR'] class Settings(QSettings): def __init__(self, key): @@ -23,7 +23,7 @@ class Settings(QSettings): @property def root(self): - _r = './plugins' + _r = os.path.join(BASE_DIR, '/plugins') if not os.path.exists(_r): os.makedirs(_r) return _r @@ -105,10 +105,11 @@ class Settings(QSettings): @property def end_date(self): - if not os.path.exists('lic/license.lic'): + lic_path = os.path.join(BASE_DIR, 'lic', 'license.lic') + if not os.path.exists(lic_path): return datetime.now() - with open('lic/license.lic', 'r') as f: + with open(lic_path, 'r') as f: lic = f.read()[::-1] lic_helper = LicenseHelper() @@ -124,10 +125,11 @@ class Settings(QSettings): @property def license(self): - if not os.path.exists('lic/license.lic'): + lic_path =os.path.join(BASE_DIR, 'lic', 'license.lic') + if not os.path.join(lic_path): return False - with open('lic/license.lic', 'r') as f: + with open(lic_path, 'r') as f: lic = f.read()[::-1] lic_helper = LicenseHelper() @@ -144,7 +146,7 @@ class Settings(QSettings): @property def root(self): with Settings(Settings.General.PRE) as s: - return s.value('root', './') + return s.value('root', BASE_DIR) @property def auto_save(self):