From 20fc5988a3e4f9f388053fa95b0294b3254f4dd2 Mon Sep 17 00:00:00 2001
From: EsGeh <SamuelGfroerer@googlemail.com>
Date: Mon, 25 Nov 2019 12:58:53 +0100
Subject: [PATCH] new ver. of psycopg2 fixes install problems, improve init
 script

---
 requirements.txt |  2 +-
 scripts/init.py  | 40 +++++++++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index 23737bc..88d075c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 Django==2.1.11
-psycopg2-binary == 2.7.7
+psycopg2-binary==2.8.4
 dj-database-url==0.5.0
 django-auth-ldap==2.0.0
 django-classy-tags==0.9.0
diff --git a/scripts/init.py b/scripts/init.py
index f706f08..6f232be 100755
--- a/scripts/init.py
+++ b/scripts/init.py
@@ -2,6 +2,7 @@
 
 from utils.settings import BASE_DIR, load_config, create_docker_env_file
 from utils.functions import exec_in_container, run
+from stop import stop
 
 from pathlib import Path
 import shlex
@@ -54,23 +55,26 @@ def install_git_dep(
     repo_name,
     repo_uri,
     repo_hash,
+    force = False,
     init_script = None
 ):
-    if (DEP_DIR / repo_name).exists():
+    # remove repo, if necessary:
+    if force and (DEP_DIR / repo_name).exists():
         shutil.rmtree( DEP_DIR / repo_name )
 
-    subprocess.check_call(
-        ["git", "clone", repo_uri, DEP_DIR / repo_name]
-    )
-    subprocess.check_call(
-        ["git", "checkout", repo_hash],
-        cwd = DEP_DIR / repo_name
-    )
-    if init_script is not None:
+    if not((DEP_DIR / repo_name).exists()):
+        subprocess.check_call(
+            ["git", "clone", repo_uri, DEP_DIR / repo_name]
+        )
         subprocess.check_call(
-            shlex.split( init_script ),
+            ["git", "checkout", repo_hash],
             cwd = DEP_DIR / repo_name
         )
+        if init_script is not None:
+            subprocess.check_call(
+                shlex.split( init_script ),
+                cwd = DEP_DIR / repo_name
+            )
 
 def init_sqldb( config ):
     # print( "env in config:" )
@@ -117,6 +121,10 @@ def init_sqldb( config ):
     parser = ArgumentParser(
         description="initialize the repository: download git deps, create directories, initialize xml database, initialize sql database"
     )
+    parser.add_argument(
+        "--force-deps",
+        action = "store_true"
+    )
     parser.add_argument(
         "--build",
         action = "store_true"
@@ -132,18 +140,21 @@ def init_sqldb( config ):
     install_git_dep(
         repo_name = "eoa-publication-model",
         repo_uri = "https://github.molgen.mpg.de/EditionOpenAccess/eoa-publication-model.git",
-        repo_hash = "d76a81feef1ebb708a90376d3f5a7eccb51807b0"
+        repo_hash = "d76a81feef1ebb708a90376d3f5a7eccb51807b0",
+        force = args.force_deps,
     )
     install_git_dep(
         repo_name = "EOASkripts",
         repo_uri = "https://github.molgen.mpg.de/EditionOpenAccess/EOASkripts.git",
-        repo_hash = "bb0d7bfc6b77bdec391886b90f3f9ad9f2025423"
+        repo_hash = "bb0d7bfc6b77bdec391886b90f3f9ad9f2025423",
+        force = args.force_deps,
     )
     install_git_dep(
         repo_name = "webdesign_platform",
         repo_uri = "https://github.molgen.mpg.de/EditionOpenAccess/webdesign_platform.git",
         repo_hash = "7a6c3f7c0db224fdcbb046df3f7edad8fefded3f",
-        init_script = "./scripts/init.sh"
+        init_script = "./scripts/init.sh",
+        force = args.force_deps,
     )
 
     create_dirs( config )
@@ -154,5 +165,8 @@ def init_sqldb( config ):
             env = config,
             build = True,
         )
+        stop(
+            env = config,
+        )
 
     init_sqldb( config )