Exemple #1
0
 def update(self, venv_id, name, description, source_path):
     result = True
     try:
         data = {}
         need_update = False
         if name:
             data["name"] = name
         if description:
             data["description"] = description
         if os.path.exists(source_path) and os.path.isfile(source_path):
             sha1 = file_sha1sum(source_path)
             data["sha1"] = sha1
             LOG.debug("sha1: %s, %s", sha1, type(sha1))
             venv_path = self.make_venv_version_path(venv_id, sha1)
             if os.path.exists(venv_path):
                 shutil.rmtree(venv_path)
             os.makedirs(venv_path)
             shutil.copy2(source_path, os.path.join(venv_path,
                                                    "venv.tar.gz"))
             os.remove(source_path)
             need_update = True
         if data or need_update:
             success = Venvs.instance().update(venv_id, data)
             if success:
                 if "sha1" in data:
                     description = "" if "description" not in data else data[
                         "description"]
                     VenvHistory.instance().add(venv_id,
                                                data["sha1"],
                                                description=description)
             else:
                 result = False
     except Exception as e:
         LOG.exception(e)
     return result
Exemple #2
0
 def create(self, name, description, source_path):
     sha1 = file_sha1sum(source_path)
     LOG.debug("sha1: %s, %s", sha1, type(sha1))
     venv_id = Venvs.instance().add(name, sha1, description=description)
     venv_path = self.make_venv_version_path(venv_id, sha1)
     self.ldfs.delete_directory(venv_path)
     self.ldfs.create_file(source_path,
                           os.path.join(venv_path, "venv.zip"),
                           replica=1)
     os.remove(source_path)
     VenvHistory.instance().add(venv_id, sha1, description=description)
     return venv_id
Exemple #3
0
 def create(self, name, description, source_path):
     sha1 = file_sha1sum(source_path)
     LOG.debug("sha1: %s, %s", sha1, type(sha1))
     venv_id = Venvs.instance().add(name, sha1, description=description)
     venv_path = self.make_venv_version_path(venv_id, sha1)
     if os.path.exists(venv_path):
         shutil.rmtree(venv_path)
     os.makedirs(venv_path)
     shutil.copy2(source_path, os.path.join(venv_path, "venv.tar.gz"))
     os.remove(source_path)
     VenvHistory.instance().add(venv_id, sha1, description=description)
     return venv_id
Exemple #4
0
 def delete(self, venv_id):
     result = False
     try:
         success = Venvs.instance().delete(venv_id)
         if success:
             VenvHistory.instance().delete_by_venv_id(venv_id)
             venv_path = self.make_venv_path(venv_id)
             self.ldfs.delete_directory(venv_path)
             LOG.debug("remove ldfs directory: %s", venv_path)
             result = True
     except Exception as e:
         LOG.exception(e)
     return result
Exemple #5
0
 def delete(self, venv_id):
     result = False
     try:
         success = Venvs.instance().delete(venv_id)
         if success:
             VenvHistory.instance().delete_by_venv_id(venv_id)
             venv_path = self.make_venv_path(venv_id)
             if os.path.exists(venv_path):
                 shutil.rmtree(venv_path)
                 LOG.debug("remove directory: %s", venv_path)
             result = True
     except Exception as e:
         LOG.exception(e)
     return result
Exemple #6
0
 def delete_history(self, history_id, venv_id):
     result = False
     try:
         history = VenvHistory.instance().delete_by_history_id_venv_id(
             history_id, venv_id)
         if history and history is not None:
             filters = VenvHistory.instance().parse_filters({
                 "venv_id":
                 history["venv_id"],
                 "sha1":
                 history["sha1"]
             })
             num = VenvHistory.instance().count(filters)
             if num == 0:
                 venv_path = self.make_venv_version_path(
                     history["venv_id"], history["sha1"])
                 self.ldfs.delete_directory(venv_path)
                 LOG.debug("remove ldfs directory: %s", venv_path)
         result = True
     except Exception as e:
         LOG.exception(e)
     return result
Exemple #7
0
 def info_history(self, history_id, venv_id=""):
     return VenvHistory.instance().get(history_id, venv_id=venv_id)
Exemple #8
0
 def list_history(self, offset, limit, filters={}):
     return VenvHistory.instance().list(offset=offset,
                                        limit=limit,
                                        filters=filters)