2019-11-01 23:31:40 +00:00
|
|
|
import logging
|
|
|
|
import shutil
|
|
|
|
from pathlib import Path
|
|
|
|
|
2019-11-05 21:10:42 +00:00
|
|
|
import yaml
|
|
|
|
|
2019-11-01 23:31:40 +00:00
|
|
|
# gui home paths
|
|
|
|
HOME_PATH = Path.home().joinpath(".coretk")
|
|
|
|
BACKGROUNDS_PATH = HOME_PATH.joinpath("backgrounds")
|
|
|
|
CUSTOM_EMANE_PATH = HOME_PATH.joinpath("custom_emane")
|
|
|
|
CUSTOM_SERVICE_PATH = HOME_PATH.joinpath("custom_services")
|
|
|
|
ICONS_PATH = HOME_PATH.joinpath("icons")
|
|
|
|
MOBILITY_PATH = HOME_PATH.joinpath("mobility")
|
|
|
|
XML_PATH = HOME_PATH.joinpath("xml")
|
|
|
|
CONFIG_PATH = HOME_PATH.joinpath("gui.yaml")
|
|
|
|
|
|
|
|
# local paths
|
|
|
|
LOCAL_ICONS_PATH = Path(__file__).parent.joinpath("icons").absolute()
|
|
|
|
LOCAL_BACKGROUND_PATH = Path(__file__).parent.joinpath("backgrounds").absolute()
|
|
|
|
|
|
|
|
|
2019-11-05 21:10:42 +00:00
|
|
|
class IndentDumper(yaml.Dumper):
|
|
|
|
def increase_indent(self, flow=False, indentless=False):
|
|
|
|
return super().increase_indent(flow, False)
|
|
|
|
|
|
|
|
|
2019-11-01 23:31:40 +00:00
|
|
|
def check_directory():
|
|
|
|
if HOME_PATH.exists():
|
|
|
|
logging.info("~/.coretk exists")
|
|
|
|
return
|
|
|
|
logging.info("creating ~/.coretk")
|
|
|
|
HOME_PATH.mkdir()
|
|
|
|
BACKGROUNDS_PATH.mkdir()
|
|
|
|
CUSTOM_EMANE_PATH.mkdir()
|
|
|
|
CUSTOM_SERVICE_PATH.mkdir()
|
|
|
|
ICONS_PATH.mkdir()
|
|
|
|
MOBILITY_PATH.mkdir()
|
|
|
|
XML_PATH.mkdir()
|
|
|
|
for image in LOCAL_ICONS_PATH.glob("*"):
|
|
|
|
new_image = ICONS_PATH.joinpath(image.name)
|
|
|
|
shutil.copy(image, new_image)
|
|
|
|
for background in LOCAL_BACKGROUND_PATH.glob("*"):
|
|
|
|
new_background = BACKGROUNDS_PATH.joinpath(background.name)
|
|
|
|
shutil.copy(background, new_background)
|
|
|
|
with CONFIG_PATH.open("w") as f:
|
2019-11-05 21:10:42 +00:00
|
|
|
yaml.dump(
|
|
|
|
{"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}]},
|
|
|
|
f,
|
|
|
|
Dumper=IndentDumper,
|
|
|
|
default_flow_style=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def read_config():
|
|
|
|
with CONFIG_PATH.open("r") as f:
|
|
|
|
return yaml.load(f, Loader=yaml.SafeLoader)
|