# 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"))
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"])
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"))
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)