]> Softwares of Agnibho - medscript.git/commitdiff
Partial merge from flatpak branch
authorAgnibho Mondal <mondal@agnibho.com>
Fri, 8 Sep 2023 17:33:38 +0000 (23:03 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Fri, 8 Sep 2023 17:33:38 +0000 (23:03 +0530)
config.py
filehandler.py

index aff86905f28bb435516e940d7dc43741bee6a159..51794359e8c28eee386807565dc42782b30ff2e4 100644 (file)
--- 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 <https://www.gnu.org/licenses/>.
 
-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"))
index 498d2998f8faef7ec980c9a1f292da740594bf71..b80da90300ffa1c9cf042473b4e78cceded8d6c6 100644 (file)
@@ -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)