Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/usr/bin/python3 | |
| import os.path | |
| import sys | |
| import yaml | |
| PKGNAME = "config-example" | |
| MSG_FILE = os.path.join(os.environ["SNAP_APP_DATA_PATH"], "message") | |
| def get_config(): | |
| config = { | |
| "config": { | |
| PKGNAME: {}, | |
| } | |
| } | |
| if not os.path.exists(MSG_FILE): | |
| return config | |
| with open(MSG_FILE) as fp: | |
| msg = fp.read() | |
| config["config"]["config-example"]["msg"] = msg | |
| return config | |
| def set_config(): | |
| config = yaml.load(sys.stdin) | |
| if not config: | |
| return | |
| msg = config.get("config", {}).get(PKGNAME, {}).get("msg", "") | |
| if msg: | |
| with open(MSG_FILE, "w") as fp: | |
| fp.write(msg) | |
| if __name__ == "__main__": | |
| set_config() | |
| config = get_config() | |
| yaml.dump(config, stream=sys.stdout, default_flow_style=False) |