123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import os
- from configparser import ConfigParser
- from pathlib import Path
- # 获取当前脚本所在的目录
- current_path = Path(__file__).resolve().parent
- # 获取当前脚本所在的项目根目录
- root_path = 'D:\\flightinfo\\DATABASE'
- #root_path = 'D:\\flightinfo\\DATABASE'
- ini_path = os.path.join(root_path,'config.ini')
- print("项目根目录路径:", root_path)
- print(os.path.join(root_path,'config.ini'))
- def readConfig():
- config = ConfigParser()
- config.read(ini_path)
- if config.has_section('DBserver'):
- print(config.get('DBserver', 'host'))
- def writeConfig():
- config = ConfigParser()
- config.add_section('DBserver')
- config.set('DBserver', 'local_host','localhost')
- config.set('DBserver', 'local_port','9527')
- config.set('DBserver', 'online_host','222.209.89.138')
- config.set('DBserver', 'online_port','9527')
- config.set('DBserver', 'flightDB4','flightDB4')
- with open(ini_path, 'w') as configfile:
- config.write(configfile)
- def Server_Class():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('Server_Class'):
- path = "天府综合平台一期:" + config.get('Server_Class', "Class")
- else:
- path = "无重要标记"
- print('Not found Server_Class')
- return path
- def Main_Sever():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('Main_Sever'):
- path = config.get('Main_Sever', "MainSever")
- database = config.get('Main_Sever', "MainDatabase") if config.has_option('Main_Sever', "MainDatabase") else path
- else:
- path = ""
- database = ""
- print('Not found Main_Sever')
- return path, database
- def NO_TPIS():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('NO_TPIS'):
- ACNO = config.get('NO_TPIS', "ACNO").split(",")
- else:
- ACNO = []
- print('Not found Main_Sever')
- return ACNO
- def DBServer():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- local_host = config.get('DBserver', 'local_host')
- local_port = config.get('DBserver', 'local_port')
- local_user = "user1" #config.get('DBserver', 'local_user')
- local_password = "a123456s" #config.get('DBserver', 'local_password')
- online_host = config.get('DBserver', 'online_host')
- online_port = config.get('DBserver', 'online_port')
- online_user = "user1" #config.get('DBserver', 'online_user')
- online_password = "a123456s" #config.get('DBserver', 'online_password')
- else:
- local_host = None
- local_port = None
- local_user = None
- local_password = None
- online_host = None
- online_port = None
- online_user = None
- online_password = None
- print('Not found DBserver')
- return local_host, local_port, local_user, local_password, online_host, online_port, online_user,online_password
- def MesgTime():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('Mesg_Time'):
- APZBZ = int(config.get('Mesg_Time', 'APZBZ'))
- JJZBZ = int(config.get('Mesg_Time', 'JJZBZ'))
- ESZBZ = int(config.get('Mesg_Time', 'ESZBZ'))
- APGR = int(config.get('Mesg_Time', 'APGR'))
- JJGR = int(config.get('Mesg_Time', 'JJGR'))
- ESGR = int(config.get('Mesg_Time', 'ESGR'))
- APPG = int(config.get('Mesg_Time', 'APPG'))
- JJPG = int(config.get('Mesg_Time', 'JJPG'))
- ESPG = int(config.get('Mesg_Time', 'ESPG'))
- else:
- APZBZ = 100
- JJZBZ = 40
- ESZBZ = 40
- APGR = 105
- JJGR = 45
- ESGR = 45
- APPG = 120
- JJPG = 45
- ESPG = 55
- print('Not found Mesg_Time')
- return APZBZ, JJZBZ, ESZBZ, APGR, JJGR, ESGR,APPG,JJPG,ESPG
- def flightDB4():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- database = config.get('DBserver', 'flightDB4')
- else:
- database = None
- print('Not found flightDB4')
- return database
- def flightDB():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- database = config.get('DBserver', 'flightDB')
- else:
- database = None
- print('Not found flightDB')
- return database
- def loginDB():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- database = config.get('DBserver', 'loginDB')
- else:
- database = None
- print('Not found loginDB')
- return database
- def databasefileDB():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- database = config.get('DBserver', 'databasefileDB')
- else:
- database = None
- print('Not found fileDB')
- return database
- def UsesrLoginDatabase():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DBserver'):
- database = config.get('DBserver', 'UserLoginDatabase')
- else:
- database = None
- print('Not found UserLoginDatabase')
- return database
- def FilePath(name):
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('FilePath'):
- path = config.get('FilePath', name)
- else:
- path = None
- print('Not found FilePath')
- return path
- def DataTransferMode():
- config = ConfigParser()
- config.read(ini_path, encoding='utf-8')
- if config.has_section('DataTransferMode'):
- try:
- flightDataTransfer = int(config.get('DataTransferMode', 'flightDataTransfer'))
- displayDataTransfer = int(config.get('DataTransferMode', 'displayDataTransfer'))
- except:
- flightDataTransfer = 0
- displayDataTransfer = 0
- else:
- flightDataTransfer = 0
- displayDataTransfer = 0
- print('Not found PdfSavePathUrl')
- return flightDataTransfer,displayDataTransfer
|