コード例 #1
0
ファイル: gui.py プロジェクト: sketchfab/minecraft-exporter
    def start_upload(self):
        # get area
        minx = int(self.editXMin.text())
        maxx = int(self.editXMax.text())
        miny = max(0, int(self.editYMin.text()))
        maxy = min(255, int(self.editYMax.text()))
        minz = int(self.editZMin.text())
        maxz = int(self.editZMax.text())

        self.editYMin.setText(str(miny))
        self.editYMax.setText(str(maxy))

        if (maxx-minx)*(maxz-minz) > minecraft.max_size[0] * minecraft.max_size[1]:
            QtGui.QMessageBox.information(self, "Area limits", "The exporter's area size is limited to %sx%s.\nPlease specify a smaller x and/or z range.")
            return

        progress = QtGui.QProgressDialog("Uploading...", "Cancel", 0, 100, self)
        progress.setWindowTitle("Sketchfab upload")
        progress.setWindowModality(QtCore.Qt.WindowModal)
        progress.show()
        self.settings.setValue("account/token", self.editToken.text())

        params = {
            "area": {
                "x": [minx, maxx],
                "y": [miny, maxy],
                "z": [minz, maxz]
            },
            "dimension": self.currentDimension[1]
        }
        filename, dirname = minecraft.create_zip_file(self.currentWorld[1], params)
        print(filename)

        token = str(self.editToken.text())
        if not token:
            QtGui.QMessageBox.information(self, "Sketchfab token", "You need to specify your sketchfab api token.\nIt can be found on your dashboard.")
            return

        self.manager, self.reply = minecraft.upload(
            fileModel=filename,
            title=self.currentWorld[0],
            description="Minecraft %s" % (self.currentDimension[0]),
            tags="minecraft",
            token=token
        )

        def upload_finished():
            if not progress.wasCanceled():
                http_response = self.reply.readAll()
                print(http_response)
                data = json.loads(str(http_response))
                success = data['success']
                result = data['result']
                if success:
                    id = result["id"]
                    QtGui.QDesktopServices.openUrl(QtCore.QUrl("%s/show/%s" % (minecraft.sketchfab_url, id)))
                else:
                    QtGui.QMessageBox.critical(self, "Upload sketchfab error", json.dumps(result))

                print(result)
                progress.close()

        def upload_error():
            progress.cancel()
            rawData = str(self.reply.readAll())
            print(rawData)
            if rawData:
                try:
                    data = json.loads(rawData)
                    if data and "success" in data and not data["success"]:
                        QtGui.QMessageBox.critical(self, "Upload error", data["error"])
                        return
                except:
                    pass
            QtGui.QMessageBox.critical(self, "Upload network error", self.reply.errorString())
            progress.close()
            self.reply = None

        def upload_progress(value, max):
            progress.setValue(value)
            progress.setMaximum(max + 1)
            if value == max:
                progress.setLabelText('Processing...')

        def upload_canceled():
            self.reply = None

        def ssl_errors(err_list):
            for err in err_list:
                print(err.errorString())
            self.reply.ignoreSslErrors()

        self.reply.finished.connect(upload_finished)
        self.reply.error.connect(upload_error)
        self.reply.uploadProgress.connect(upload_progress)
        self.reply.sslErrors.connect(ssl_errors)

        progress.canceled.connect(upload_canceled)
コード例 #2
0
ファイル: gui.py プロジェクト: isabella232/minecraft-exporter
    def start_upload(self):
        # get area
        minx = int(self.editXMin.text())
        maxx = int(self.editXMax.text())
        miny = max(0, int(self.editYMin.text()))
        maxy = min(255, int(self.editYMax.text()))
        minz = int(self.editZMin.text())
        maxz = int(self.editZMax.text())

        self.editYMin.setText(str(miny))
        self.editYMax.setText(str(maxy))

        if (maxx - minx) * (
                maxz - minz) > minecraft.max_size[0] * minecraft.max_size[1]:
            QtGui.QMessageBox.information(
                self, "Area limits",
                "The exporter's area size is limited to %sx%s.\nPlease specify a smaller x and/or z range."
            )
            return

        progress = QtGui.QProgressDialog("Uploading...", "Cancel", 0, 100,
                                         self)
        progress.setWindowTitle("Sketchfab upload")
        progress.setWindowModality(QtCore.Qt.WindowModal)
        progress.show()
        self.settings.setValue("account/token", self.editToken.text())

        params = {
            "area": {
                "x": [minx, maxx],
                "y": [miny, maxy],
                "z": [minz, maxz]
            },
            "dimension": self.currentDimension[1]
        }
        filename, dirname = minecraft.create_zip_file(self.currentWorld[1],
                                                      params)
        print(filename)

        token = str(self.editToken.text())
        if not token:
            QtGui.QMessageBox.information(
                self, "Sketchfab token",
                "You need to specify your sketchfab api token.\nIt can be found on your dashboard."
            )
            return

        self.manager, self.reply = minecraft.upload(
            fileModel=filename,
            title=self.currentWorld[0],
            description="Minecraft %s" % (self.currentDimension[0]),
            tags="minecraft",
            token=token)

        def upload_finished():
            if not progress.wasCanceled():
                http_response = self.reply.readAll()
                print(http_response)
                data = json.loads(str(http_response))
                success = data['success']
                result = data['result']
                if success:
                    id = result["id"]
                    QtGui.QDesktopServices.openUrl(
                        QtCore.QUrl("%s/show/%s" %
                                    (minecraft.sketchfab_url, id)))
                else:
                    QtGui.QMessageBox.critical(self, "Upload sketchfab error",
                                               json.dumps(result))

                print(result)
                progress.close()

        def upload_error():
            progress.cancel()
            rawData = str(self.reply.readAll())
            print(rawData)
            if rawData:
                try:
                    data = json.loads(rawData)
                    if data and "success" in data and not data["success"]:
                        QtGui.QMessageBox.critical(self, "Upload error",
                                                   data["error"])
                        return
                except:
                    pass
            QtGui.QMessageBox.critical(self, "Upload network error",
                                       self.reply.errorString())
            progress.close()
            self.reply = None

        def upload_progress(value, max):
            progress.setValue(value)
            progress.setMaximum(max + 1)
            if value == max:
                progress.setLabelText('Processing...')

        def upload_canceled():
            self.reply = None

        def ssl_errors(err_list):
            for err in err_list:
                print(err.errorString())
            self.reply.ignoreSslErrors()

        self.reply.finished.connect(upload_finished)
        self.reply.error.connect(upload_error)
        self.reply.uploadProgress.connect(upload_progress)
        self.reply.sslErrors.connect(ssl_errors)

        progress.canceled.connect(upload_canceled)
コード例 #3
0
ファイル: cli.py プロジェクト: sketchfab/minecraft-exporter
def main(options):
    if options.list is True:
        list_worlds()
        return

    if not options.world is None:
        if options.token is None:
            print("Missing sketchfab api token. You can find it on your dashboard : https://sketchfab.com/dashboard")
            return
        token = options.token

        world = minecraft.getWorldByName(options.world)
        if world is None:
            print("Can't find world %s" % (options.world))
            return

        dimension = minecraft.getDimensionById(world, int(options.dimension))
        if dimension is None:
            print("Can't find dimension %s in world %s" % (options.dimension, options.world))
            return

        area = minecraft.getDefaultArea(world)

        title = options.world
        if not options.title is None:
            title = options.title

        if not options.area is None:
            m = re.match("(-?\d+),(-?\d+),(-?\d+),(-?\d+)", options.area)
            if not m:
                print("Invalid area")
                return
            area[0][0] = int(m.group(1))
            area[1][0] = int(m.group(2))
            area[0][2] = int(m.group(3))
            area[1][2] = int(m.group(4))

        if not options.height is None:
            m = re.match("(\d+),(\d+)", options.height)
            if not m:
                print("Invalid height")
                return
            area[0][1] = int(m.group(1))
            area[1][1] = int(m.group(2))

        params = {
            "area": {"x": [area[0][0], area[1][0]], "y": [area[0][1], area[1][1]], "z": [area[0][2], area[1][2]]},
            "dimension": dimension[0],
        }
        filename, dirname = minecraft.create_zip_file(world[1], params)
        print(filename)

        state, contents = minecraft.uploadURLLIB2(
            filename=filename,
            api_key=token,
            description="Minecraft %s" % (world[0]),
            model_name=title,
            tags="minecraft",
        )
        print(contents)
        data = json.loads(contents)
        success = data["success"]

        if state is False:
            sys.exit("There was an HTTP error : %s" % (data["error"]))

        result = data["result"]

        if success is False:
            sys.exit("Error while uploading : %s" % (json.dumps(result)))

        print("Model uploaded, available at %s." % ("%s/show/%s" % (minecraft.sketchfab_url, result["id"])))
コード例 #4
0
def main(options):
    if options.list is True:
        list_worlds()
        return

    if not options.world is None:
        if options.token is None:
            print(
                "Missing sketchfab api token. You can find it on your dashboard : https://sketchfab.com/dashboard"
            )
            return
        token = options.token

        world = minecraft.getWorldByName(options.world)
        if world is None:
            print("Can't find world %s" % (options.world))
            return

        dimension = minecraft.getDimensionById(world, int(options.dimension))
        if dimension is None:
            print("Can't find dimension %s in world %s" %
                  (options.dimension, options.world))
            return

        area = minecraft.getDefaultArea(world)

        title = options.world
        if not options.title is None:
            title = options.title

        if not options.area is None:
            m = re.match("(-?\d+),(-?\d+),(-?\d+),(-?\d+)", options.area)
            if not m:
                print("Invalid area")
                return
            area[0][0] = int(m.group(1))
            area[1][0] = int(m.group(2))
            area[0][2] = int(m.group(3))
            area[1][2] = int(m.group(4))

        if not options.height is None:
            m = re.match("(\d+),(\d+)", options.height)
            if not m:
                print("Invalid height")
                return
            area[0][1] = int(m.group(1))
            area[1][1] = int(m.group(2))

        params = {
            "area": {
                "x": [area[0][0], area[1][0]],
                "y": [area[0][1], area[1][1]],
                "z": [area[0][2], area[1][2]],
            },
            "dimension": dimension[0]
        }
        filename, dirname = minecraft.create_zip_file(world[1], params)
        print(filename)

        state, contents = minecraft.uploadURLLIB2(filename=filename,
                                                  api_key=token,
                                                  description="Minecraft %s" %
                                                  (world[0]),
                                                  model_name=title,
                                                  tags="minecraft")
        print(contents)
        data = json.loads(contents)
        success = data['success']

        if state is False:
            sys.exit("There was an HTTP error : %s" % (data["error"]))

        result = data['result']

        if success is False:
            sys.exit("Error while uploading : %s" % (json.dumps(result)))

        print("Model uploaded, available at %s." %
              ("%s/show/%s" % (minecraft.sketchfab_url, result["id"])))