Beispiel #1
0
 def __init__(self, window):
     """
     Init all Variables and Popups
     :param window: QMainWindow
     :return:
     """
     super().__init__(window)
     self.window = window
     self.stagingDir = ""
     self.fileDir = ""
     self.fileExt = ""
     self.fileName = ""
     self.lastMod = ""
     self.author = ""
     self.UploadPopupWidget = QDialog(window, QtCore.Qt.WindowStaysOnTopHint)
     self.UploadPopup = IOStatusPopup(self.UploadPopupWidget, "Hochladen")
Beispiel #2
0
    def download(self, filename):
        """
        Download File and save to Directory defined in config
        :param filename: Name of the File to be downloaded
        :return: None
        """
        PopupWidget = QtGui.QDialog(self.window, QtCore.Qt.WindowStaysOnTopHint)
        Popup = IOStatusPopup(PopupWidget, "Herunterladen")
        Popup.setLabelText("Finde Dateien...")
        Popup.setButtonEnabled(False)
        PopupWidget.show()

        DLpath = self.configHandler.getAttribute("Download Dir")
        if DLpath == "" or " ":
            DLpath ="./downloaded"
            self.configHandler.setAttribute("Download Dir", "./downloaded")
        if not os.path.exists(DLpath):
            os.makedirs(DLpath)
        os.chdir(DLpath)
        Popup.setProgress(50)
        Popup.setLabelText("Lade Dateien Herunter...")
        with open(filename, "wb") as file:
            file.write(self._dlContent(filename))
        Popup.setProgress(100)
        Popup.setLabelText("Fertig!")
        Popup.setButtonEnabled(True)
Beispiel #3
0
class UploadMenu(TabBase):
    def __init__(self, window):
        """
        Init all Variables and Popups
        :param window: QMainWindow
        :return:
        """
        super().__init__(window)
        self.window = window
        self.stagingDir = ""
        self.fileDir = ""
        self.fileExt = ""
        self.fileName = ""
        self.lastMod = ""
        self.author = ""
        self.UploadPopupWidget = QDialog(window, QtCore.Qt.WindowStaysOnTopHint)
        self.UploadPopup = IOStatusPopup(self.UploadPopupWidget, "Hochladen")

    def setupUi(self, MainWindow):
        """
        Connct all Events
        :param MainWindow: QMainWindow on which to draw
        :return:
        """
        super().setupUi(MainWindow)
        self.SelectFileBtn.pressed.connect(self.selectFile)
        self.UploadBtn.pressed.connect(self.upload)
        self.UploadBtn.setEnabled(False)

    def selectFile(self):
        """
        Get User Input from File selector
        Get Default from Settings
        Get File Meta
        :return:
        """
        # Chose File
        os.chdir(self.path)
        self.fileDir = QFileDialog.getOpenFileName(self.window)[0]
        if self.fileDir != "":
            self.UploadBtn.setEnabled(True)
            # Show Default
            self.CommentsTxt.setText(self.ConfigHandler.getAttribute("Default Desc"))  # Defined in FileTransfer.py
            self.AuthorTxt.setText(self.ConfigHandler.getAttribute("Default Author"))

            # show File Dir
            self.FileSelectTxt.setText(self.fileDir)

            # Get File Extension and Name
            self.fileExt = self.fileDir[self.fileDir.rfind("."):]
            self.fileName = self.fileDir[self.fileDir.rfind("/") + 1:self.fileDir.rfind(".")]

            # Show File Name
            self.NameTxt.setText(self.fileName.capitalize())

            # Get Last Edit Date
            self.lastMod = os.stat(self.fileDir)[8]
            self.DateTxt.setText(str(time.asctime(time.localtime(self.lastMod))))

            self.stagingDir = self.path + "/staging/"
            if not os.path.exists(self.stagingDir):
                os.makedirs(self.stagingDir)


    def upload(self):
        """
        Stage File for Upload
        Pass files to Uploader
        :return:
        """
        if self.fileDir != "":
            # Init Popup
            self.UploadPopupWidget.show()
            self.UploadPopup.setLabelText("Dateien Vorbereiten...")

            self.inputName = self.NameTxt.text()
            self.lastMod = self.DateTxt.text()
            self.author = self.AuthorTxt.text()
            self.desc = self.CommentsTxt.toPlainText()
            self.fileselect = self.FileSelectTxt.text()
            self.fullFile = self.fileName + self.fileExt
            # Create Meta File
            fileMeta = MetaData(self.inputName, self.stagingDir, self.fullFile, self.lastMod, self.author, self.desc)
            fileMeta.createMetaFile()

            # Copy File to Staging Area
            shutil.copy(self.fileDir, self.stagingDir)
            os.rename(self.stagingDir + self.fullFile, self.inputName + self.fileExt)

            # Set Upload Progress
            self.UploadPopup.setProgress(50)
            self.UploadPopup.setLabelText("Dateien Hochladen...")

            # File all Files
            upfileLoc = self.stagingDir + self.fullFile
            upMetaLoc = self.fileName + ".meta"

            # Init Uploader
            upfile = Uploader(self.fullFile, self.stagingDir)
            upMeta = Uploader(self.fileName + ".meta", self.stagingDir)

            # Send Post Requests
            fileResult = upfile.sendPost()
            metaResult = upMeta.sendPost()

            # Remove Staged Files
            os.remove(upfileLoc)
            os.remove(upMetaLoc)

            # Set Upload Progress
            self.UploadPopup.setProgress(100)
            if fileResult is True and metaResult is True:
                self.UploadPopup.setLabelText("Fertig!")
            else:
                self.UploadPopup.setLabelText("Fehler!")

            # Clear All Inputs
            self.CommentsTxt.setText("")
            self.NameTxt.setText("")
            self.AuthorTxt.setText("")
            self.FileSelectTxt.setText("")
            self.DateTxt.setText("")
            self.fileDir = ""
            self.fileExt = ""
            self.fileName = ""
            self.lastMod = ""
            self.fullFile = ""
            self.inputName = ""
            self.UploadBtn.setEnabled(False)

            # Reset Current Dir
            os.chdir(self.fileDir + "\\..\\")
        else:
            QtGui.QMessageBox.warning(self.window, "Fehler", "Keine Datei Ausgewählt", QtGui.QMessageBox.Ok)