增加命令行执行。

This commit is contained in:
facat 2020-11-14 13:44:35 +08:00
parent 9784bce362
commit 452c582590
5 changed files with 86 additions and 10 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# created by virtualenv automatically
__pycache__
Scripts
.idea
Lib
pyvenv.cfg

61
cli.py Normal file
View File

@ -0,0 +1,61 @@
import click
from generate_ta import generate_ta_from_D
from file_object import TaFileObject
@click.group()
def cli():
pass
# 注意d_files和s_files中文件名的顺序
@click.command()
@click.option("--s_files", help="s文件。以;分割")
@click.option("--d_files", help="d文件。以;分割")
@click.option("--ta_file", help="生成的Ta文件")
def generate_ta_file(s_files: str, d_files: str, ta_file: str):
s_files_list = s_files.split(",")
d_files_list = d_files.split(",")
generate_ta_from_D(ta_file, s_files_list, d_files_list)
print("生成Ta文件:{ta_file}".format(ta_file=ta_file))
pass
# 将Ta文件里程同步到S文件中
@click.command()
@click.option("--s_files", help="s文件。以;分割")
@click.option("--ta_file", help="Ta文件")
def sync_all_tower_mileage_to_s(s_files: str, ta_file: str):
s_files_list = s_files.split(",")
ta_object = TaFileObject(ta_file, s_files_list)
ta_object.sync_all_tower_mileage_to_s()
print('同步TA文件中里程到S文件')
# 将Ta文件塔高同步到S文件中
@click.command()
@click.option("--s_files", help="s文件。以;分割")
@click.option("--ta_file", help="Ta文件")
def sync_all_tower_height_from_TA_to_S(s_files: str, ta_file: str):
s_files_list = s_files.split(",")
ta_object = TaFileObject(ta_file, s_files_list)
ta_object.sync_all_tower_height_from_TA_to_S(prompt=False)
print('同步TA文件中塔高到S文件')
# @click.command()
# @click.option('--count', default=1, help='Number of greetings.')
# @click.option('--name', prompt='Your name',
# help='The person to greet.')
# def hello(count, name):
# """Simple program that greets NAME for a total of COUNT times."""
# for x in range(count):
# click.echo('Hello %s!' % name)
cli.add_command(generate_ta_file)
cli.add_command(sync_all_tower_mileage_to_s)
cli.add_command(sync_all_tower_height_from_TA_to_S)
if __name__ == "__main__":
cli()

View File

@ -41,6 +41,7 @@ class SFileObject:
def _save_backup(self, back_file_path):
shutil.copy(self.file_path, back_file_path)
# 将数据按行写入S数据文件
def write(self, target_file_path):
(file_name, ext) = get_file_name_with_extention(self.file_path)
src_file_dir = get_directory(self.file_path)
@ -91,7 +92,7 @@ class SFileAsSingle:
self._s_files = s_files
# 考虑不同位置处出现塔号的情况
# 打开一次S文件
# 这个函数需要打开一次S文件
def has(self, tower_number) -> [(SFileObject, int)]:
s_file = self._s_files
ret = []
@ -203,7 +204,7 @@ class TaFileObject:
ta_new_contents = self._read(self._file_path)
new_mileage_dic = {}
for ta_entry in ta_new_contents:
if len(ta_entry)>2:
if len(ta_entry) > 2:
tower_number = ta_entry[0]
new_tower_mileage = float(ta_entry[2])
new_mileage_dic[tower_number] = new_tower_mileage
@ -225,8 +226,11 @@ class TaFileObject:
# )
# )
def sync_all_tower_height_from_TA_to_S(self):
enter_string = input("Will synchronize all height from TA to S. Enter AH2S:\n")
def sync_all_tower_height_from_TA_to_S(self, prompt=True):
if prompt:
enter_string = input(
"Will synchronize all height from TA to S. Enter AH2S:\n"
)
if enter_string.lower() != "ah2s":
return
ta_content = self._read(self._file_path)

View File

@ -43,7 +43,7 @@ def prepare_TA_entry_without_altitude(SFiles):
visited_tower_number[tower_number] = 0
else:
continue
mileage = int(S_entry[1]) + last_S_mileage
mileage = int(float(S_entry[1])) + last_S_mileage
_entry["mileage"] = mileage
tower_height = float(S_entry[7])
_entry["tower_height"] = tower_height

11
main.py
View File

@ -1,6 +1,7 @@
import generate_ta
from file_object import TaFileObject, DFileAsSingle
from file_object import DFileObject
import gui
if __name__ == "__main__1":
SFile = [
@ -21,9 +22,13 @@ if __name__ == "__main__1":
if __name__ == "__main__":
SFile = [r"d:\道亨排位\流程测试\S034.DAT"]
DFile = [r"d:\道亨排位\流程测试\D034.TXT", r"d:\道亨排位\流程测试\D038.TXT"]
ta_object = TaFileObject(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile)
d_file_object = DFileObject(r"d:\道亨排位\流程测试\D034.TXT")
ta_object = TaFileObject(r"d:\道亨排位\流程测试\流程测试.TA", SFile)
# ta_object.start()
# d_file_object = DFileObject(r"d:\道亨排位\流程测试\D034.TXT")
# d_as_single = DFileAsSingle(DFile)
# print(d_as_single.get_altitude(1956+13))
generate_ta.generate_ta_from_D(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile, DFile)
# generate_ta.generate_ta_from_D(r"d:\道亨排位\流程测试\流程测试.TA", SFile, DFile)
ta_object.sync_all_tower_mileage_to_s()
# app=gui.app()
# app.main_loop()
print("Finished.")