From bd436246897f8a54167b0f7ebe5cf4af6cf70a43 Mon Sep 17 00:00:00 2001
From: Ahmed Bilal Khalid <ahmedbilal96@gmail.com>
Date: Thu, 29 Aug 2019 22:51:43 +0500
Subject: [PATCH] a

---
 app/api.py    |  2 +-
 app/file.py   |  1 +
 app/helper.py | 13 +++++++++++++
 app/host.py   |  3 ++-
 app/image.py  |  3 ++-
 5 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/app/api.py b/app/api.py
index a1bdcec..57e5ebc 100644
--- a/app/api.py
+++ b/app/api.py
@@ -70,5 +70,5 @@ def setup(path, auth_name, auth_seed, auth_realm,
     )
     shutil.copytree(src=os.path.join(repo_name, "etcd3_wrapper"),
            dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"))
-    
+    op.add(PipenvOperation.create, path=repo_name, site_packages=True)
     op.add(PipenvOperation.install, path=repo_name)
diff --git a/app/file.py b/app/file.py
index a60b676..4e82c50 100644
--- a/app/file.py
+++ b/app/file.py
@@ -47,6 +47,7 @@ def setup(path, base_dir, file_prefix, etcd_url, etcd_password):
         url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
     )
 
+    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
     op_result.add(PipenvOperation.install, path=repo_name)
 
     # Write Crontab entry
diff --git a/app/helper.py b/app/helper.py
index f766247..d91ca74 100644
--- a/app/helper.py
+++ b/app/helper.py
@@ -67,6 +67,19 @@ class GitOperation(object):
 
 
 class PipenvOperation(object):
+    @staticmethod
+    def create(path=".", site_packages=False):
+        if site_packages:
+            command = f"pipenv --site-packages --python 3.7"
+        else:
+            command = "pipenv --python 3.7"
+        try:
+            output = subprocess.check_output(command.split(), cwd=path)
+        except subprocess.CalledProcessError as e:
+            return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
+        else:
+            return Result(output, ResultType.success)
+    
     @staticmethod
     def install(path=".", package_name=None):
         if package_name:
diff --git a/app/host.py b/app/host.py
index c006e2e..4a1c663 100644
--- a/app/host.py
+++ b/app/host.py
@@ -60,5 +60,6 @@ def setup(path, ssh_username, ssh_key_path, ssh_key_pass, etcd_url, etcd_passwor
     
     shutil.copytree(src=os.path.join(repo_name, "etcd3_wrapper"),
            dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"))
-
+   
+    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
     op_result.add(PipenvOperation.install, path=repo_name)
diff --git a/app/image.py b/app/image.py
index 30397e7..8702659 100644
--- a/app/image.py
+++ b/app/image.py
@@ -45,7 +45,8 @@ def setup(path, base_dir, etcd_url, etcd_password):
         path=repo_name,
         url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
     )
-
+    
+    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
     op_result.add(PipenvOperation.install, path=repo_name)
 
     # Write Crontab entry