server: fixed running from any working directory

This commit is contained in:
Artem30801
2020-10-06 00:35:59 +03:00
parent 1d20302466
commit ab17491ab4
2 changed files with 10 additions and 10 deletions

View File

@@ -11,9 +11,8 @@ import collections
import traceback
# Add parent dir to PATH to import messaging_lib and config_lib
current_dir = (os.path.dirname(os.path.realpath(__file__)))
lib_dir = os.path.realpath(os.path.join(current_dir, '../../lib'))
sys.path.insert(0, lib_dir)
current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.realpath(os.path.join(current_dir, os.pardir, os.pardir, 'lib')))
# Import modules from lib dir
import messaging
@@ -23,7 +22,7 @@ random.seed()
now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
log_path = 'server_logs'
log_path = os.path.join(current_dir, os.pardir, "server_logs")
if not os.path.exists(log_path):
try:
os.mkdir(log_path)
@@ -38,7 +37,7 @@ ConfigOption = collections.namedtuple("ConfigOption", ["section", "option", "val
class Server(messaging.Singleton):
def __init__(self, config_path="../config/server.ini", server_id=None):
def __init__(self, config_path=os.path.join(current_dir, os.pardir, "config", "server.ini"), server_id=None):
self.id = server_id if server_id else str(random.randint(0, 9999)).zfill(4)
self.time_started = 0
@@ -373,7 +372,7 @@ if __name__ == '__main__':
level=logging.DEBUG,
format="%(asctime)s [%(name)-7.7s] [%(threadName)-19.19s] [%(levelname)-7.7s] %(message)s",
handlers=[
logging.FileHandler("server_logs/{}.log".format(now)),
logging.FileHandler(os.path.join(log_path, "{}.log".format(now))),
logging.StreamHandler()
])

View File

@@ -648,6 +648,7 @@ def set_taskbar_icon():
if __name__ == "__main__":
current_dir = os.path.dirname(os.path.realpath(__file__))
msgbox_handler = ExitMsgbox()
msgbox_handler.setLevel(logging.CRITICAL)
@@ -655,7 +656,7 @@ if __name__ == "__main__":
level=logging.INFO,
format="%(asctime)s [%(name)-7.7s] [%(threadName)-19.19s] [%(levelname)-7.7s] %(message)s",
handlers=[
logging.FileHandler("server_logs/{}.log".format(now)),
logging.FileHandler(os.path.join(current_dir, "server_logs", "{}.log".format(now))),
logging.StreamHandler(),
msgbox_handler
])
@@ -663,7 +664,7 @@ if __name__ == "__main__":
sys.excepthook = except_hook # for debugging (exceptions traceback)
app = QApplication(sys.argv)
splash_pix = QPixmap('icons/coex_splash.jpg')
splash_pix = QPixmap(os.path.join(current_dir, "icons", "coex_splash.jpg"))
splash = QSplashScreen(splash_pix)
splash.setEnabled(False)
@@ -677,7 +678,7 @@ if __name__ == "__main__":
# time.sleep(3)
app_icon = QIcon()
app_icon.addFile('icons/image.ico', QtCore.QSize(256, 256))
app_icon.addFile(os.path.join(current_dir, "icons", "image.ico"), QtCore.QSize(256, 256))
app.setWindowIcon(app_icon)
if sys.platform == 'win32':
@@ -688,7 +689,7 @@ if __name__ == "__main__":
# app.exec_()
with loop:
server = ServerQt(config_path="config/server.ini")
server = ServerQt(config_path=os.path.join(current_dir, "config", "server.ini"))
window = MainWindow(server)
Client.on_first_connect = window.new_client_connected