From: Agnibho Mondal Date: Fri, 8 Sep 2023 17:33:38 +0000 (+0530) Subject: Partial merge from flatpak branch X-Git-Tag: v0.2~3 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=c04a3e6c71b1e42aa841a631be10648c2b946eed;p=medscript.git Partial merge from flatpak branch --- diff --git a/config.py b/config.py index aff8690..5179435 100644 --- a/config.py +++ b/config.py @@ -5,7 +5,7 @@ # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with MedScript. If not, see . -import argparse, json, os, sys +import argparse, json, os, sys, shutil default_config_file=os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "config", "config.json")) @@ -38,8 +38,9 @@ with open(config_file) as conf: read = json.loads(conf.read()) config = default | read + config["filename"]=args.filename -config["data_directory"]=os.path.abspath(os.path.join(real_dir, config["data_directory"])) +config["data_directory"]=os.path.abspath(os.path.join(real_dir, os.path.expanduser(config["data_directory"]))) config["document_directory"]=os.path.join(config["data_directory"], config["document_directory"]) config["preset_directory"]=os.path.join(config["data_directory"], config["preset_directory"]) config["template_directory"]=os.path.join(config["data_directory"], config["template_directory"]) @@ -57,3 +58,13 @@ else: else: config["prescriber"]=os.path.join(config["config_directory"], config["prescriber"]) print("File "+args.prescriber+" not found.") + +os.makedirs(config["data_directory"], exist_ok=True) +os.makedirs(config["document_directory"], exist_ok=True) +os.makedirs(config["prescriber_directory"], exist_ok=True) +os.makedirs(config["preset_directory"], exist_ok=True) +os.makedirs(config["template_directory"], exist_ok=True) +if not os.path.exists(os.path.join(config["prescriber_directory"], "prescriber.json")): + shutil.copyfile(os.path.abspath(os.path.join(real_dir, "data", "prescriber", "prescriber.json")), os.path.join(config["prescriber_directory"], "prescriber.json")) +if not os.path.exists(os.path.join(config["template_directory"], "default")): + shutil.copytree(os.path.abspath(os.path.join(real_dir, "data", "template", "default")), os.path.join(config["template_directory"], "default")) diff --git a/filehandler.py b/filehandler.py index 498d299..b80da90 100644 --- a/filehandler.py +++ b/filehandler.py @@ -47,12 +47,12 @@ class FileHandler(): os.makedirs(template, exist_ok=True) shutil.copytree(config["template"], template, dirs_exist_ok=True) - with ZipFile(self.file, "w") as target: + with ZipFile(self.file, "w", strict_timestamps=False) as target: for f in glob.glob(os.path.join(self.directory.name, "**" ,"*"), recursive=True): target.write(f, os.path.relpath(f, self.directory.name)) def open(self, file=None): if file is not None: self.file=file - with ZipFile(self.file, "r") as source: + with ZipFile(self.file, "r", strict_timestamps=False) as source: source.extractall(self.directory.name)