def handleUploadWorkSpace(self):
        """
        This function takes care of the session when you upload a workspace(.lexos) file

        Args:
            None

        Returns:
            None
        """
        # save .lexos file
        savePath = os.path.join(constants.UPLOAD_FOLDER,
                                constants.WORKSPACE_DIR)
        savefile = os.path.join(savePath, str(self.nextID) + '.zip')
        try:
            os.makedirs(savePath)
        except:
            pass
        f = open(savefile, 'wb')
        f.write(request.data)
        f.close()

        # clean the session folder
        shutil.rmtree(session_manager.session_folder())

        # extract the zip
        with zipfile.ZipFile(savefile) as zf:
            zf.extractall(savePath)
        NewSessionPath = os.path.join(savePath, constants.WORKSPACE_UPLOAD_DIR)
        general_functions.copydir(NewSessionPath,
                                  session_manager.session_folder())

        # remove temp
        os.remove(savefile)
        shutil.rmtree(savePath)
Exemple #2
0
    def handleUploadWorkSpace(self):
        """
        this function take care of the session when you upload a .lexos file

        """
        # save .lexos file
        savePath = os.path.join(constants.UPLOAD_FOLDER, constants.WORKSPACE_DIR)
        savefile = os.path.join(savePath, str(self.nextID) + '.zip')
        try:
            os.makedirs(savePath)
        except:
            pass
        f = open(savefile, 'wb')
        f.write(request.data)
        f.close()

        # clean the session folder
        shutil.rmtree(session_functions.session_folder())

        # extract the zip
        with zipfile.ZipFile(savefile) as zf:
            zf.extractall(savePath)
        NewSessionPath = os.path.join(savePath, constants.WORKSPACE_UPLOAD_DIR)
        general_functions.copydir(NewSessionPath, session_functions.session_folder())

        # remove temp
        os.remove(savefile)
        shutil.rmtree(savePath)
    def zipWorkSpace(self):
        """
        Sends a zip file containing a pickel file of the session and the session folder.

        Args:
            fileName: Name to assign to the zipped file.

        Returns:
            the path of the zipped workspace
        """
        # initialize the save path
        savepath = os.path.join(constants.UPLOAD_FOLDER,
                                constants.WORKSPACE_DIR)
        id = str(self.nextID % 10000)  # take the last 4 digit
        workspacefilepath = os.path.join(
            constants.UPLOAD_FOLDER, id + '_' + constants.WORKSPACE_FILENAME)

        # remove unnecessary content in the workspace
        try:
            shutil.rmtree(
                os.path.join(session_manager.session_folder(),
                             constants.RESULTS_FOLDER))
            # attempt to remove result folder(CSV matrix that kind of crap)
        except:
            pass

        # move session folder to work space folder
        try:
            os.remove(
                workspacefilepath
            )  # try to remove previous workspace in order to resolve conflict
        except:
            pass
        try:
            shutil.rmtree(
                savepath)  # empty the save path in order to resolve conflict
        except:
            pass
        general_functions.copydir(session_manager.session_folder(), savepath)

        # save session in the work space folder
        session_manager.save(savepath)

        # zip the dir
        zipf = zipfile.ZipFile(workspacefilepath, 'w')
        general_functions.zipdir(savepath, zipf)
        zipf.close()
        # remove the original dir
        shutil.rmtree(savepath)

        return workspacefilepath
Exemple #4
0
    def handleUploadWorkSpace(self):
        """
        This function takes care of the session when you upload a workspace(.lexos) file

        Args:
            None

        Returns:
            None
        """
        # save .lexos file
        savePath = os.path.join(constants.UPLOAD_FOLDER,
                                constants.WORKSPACE_DIR)
        savefile = os.path.join(savePath, str(self.nextID) + '.zip')
        try:
            os.makedirs(savePath)
        except:
            pass
        f = open(savefile, 'wb')
        f.write(request.data)
        f.close()

        # clean the session folder
        shutil.rmtree(session_manager.session_folder())

        # extract the zip
        upload_session_path = os.path.join(
            constants.UPLOAD_FOLDER,
            str(self.nextID) + '_upload_work_space_folder')
        with zipfile.ZipFile(savefile) as zf:
            zf.extractall(upload_session_path)
        general_functions.copydir(upload_session_path,
                                  session_manager.session_folder())

        # remove temp
        shutil.rmtree(savePath)
        shutil.rmtree(upload_session_path)

        try:
            # if there is no file content folder make one.
            # this dir will be lost during download(zip) if your original file content folder does not contain anything.
            os.makedirs(
                os.path.join(session_manager.session_folder(),
                             constants.FILECONTENTS_FOLDER))
        except (WindowsError, OSError) as e:
            pass
Exemple #5
0
    def zipWorkSpace(self):
        """
        Sends a zip file containing a pickel file of the session and the session folder.

        Args:
            fileName: Name to assign to the zipped file.

        Returns:
            the path of the zipped workspace
        """
        # initialize the save path
        savepath = os.path.join(constants.UPLOAD_FOLDER, constants.WORKSPACE_DIR)
        id = str(self.nextID % 10000)  # take the last 4 digit
        workspacefilepath = os.path.join(constants.UPLOAD_FOLDER, id + '_' + constants.WORKSPACE_FILENAME)

        # remove unnecessary content in the workspace
        try:
            shutil.rmtree(os.path.join(session_manager.session_folder(), constants.RESULTS_FOLDER))
            # attempt to remove result folder(CSV matrix that kind of crap)
        except:
            pass

        # move session folder to work space folder
        try:
            os.remove(workspacefilepath)  # try to remove previous workspace in order to resolve conflict
        except:
            pass
        try:
            shutil.rmtree(savepath)  # empty the save path in order to resolve conflict
        except:
            pass
        general_functions.copydir(session_manager.session_folder(), savepath)

        # save session in the work space folder
        session_manager.save(savepath)

        # zip the dir
        zipf = zipfile.ZipFile(workspacefilepath, 'w')
        general_functions.zipdir(savepath, zipf)
        zipf.close()
        # remove the original dir
        shutil.rmtree(savepath)

        return workspacefilepath
Exemple #6
0
    def handleUploadWorkSpace(self):
        """
        This function takes care of the session when you upload a workspace(.lexos) file

        Args:
            None

        Returns:
            None
        """
        # save .lexos file
        savePath = os.path.join(constants.UPLOAD_FOLDER, constants.WORKSPACE_DIR)
        savefile = os.path.join(savePath, str(self.nextID) + '.zip')
        try:
            os.makedirs(savePath)
        except:
            pass
        f = open(savefile, 'wb')
        f.write(request.data)
        f.close()

        # clean the session folder
        shutil.rmtree(session_manager.session_folder())

        # extract the zip
        upload_session_path = os.path.join(constants.UPLOAD_FOLDER, str(self.nextID) + '_upload_work_space_folder')
        with zipfile.ZipFile(savefile) as zf:
            zf.extractall(upload_session_path)
        general_functions.copydir(upload_session_path, session_manager.session_folder())

        # remove temp
        shutil.rmtree(savePath)
        shutil.rmtree(upload_session_path)

        try:
            # if there is no file content folder make one.
            # this dir will be lost during download(zip) if your original file content folder does not contain anything.
            os.makedirs(os.path.join(session_manager.session_folder(), constants.FILECONTENTS_FOLDER))
        except (WindowsError, OSError) as e:
            pass