Ejemplo n.º 1
0
 def upload(self, screenshot, name):
     self.loadSettings()
     #Make sure we have a up to date token
     if not self.uploadAnon:
         try:
             self.imgur.refresh_access_token()
         except Exception as e:
             ScreenCloud.setError("Failed to refresh imgur access token. " +
                                  e.message)
             return False
     #Save to a temporary file
     timestamp = time.time()
     try:
         tmpFilename = QDesktopServices.storageLocation(
             QDesktopServices.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     except AttributeError:
         from PythonQt.QtCore import QStandardPaths  #fix for Qt5
         tmpFilename = QStandardPaths.writableLocation(
             QStandardPaths.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
     #Upload!
     try:
         uploaded_image = self.imgur.upload_image(
             tmpFilename, title=ScreenCloud.formatFilename(name, False))
     except Exception as e:
         ScreenCloud.setError("Failed to upload to imgur. " + e.message)
         return False
     if self.copyLink:
         if self.copyDirectLink:
             ScreenCloud.setUrl(uploaded_image.link)
         else:
             ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id)
     return True
Ejemplo n.º 2
0
	def upload(self, screenshot, name):
		self.loadSettings()
		#Save to a temporary file
		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Connect to server
		transport = paramiko.Transport((self.host, self.port))
		if self.authMethod == "Password":
			try:
				transport.connect(username = self.username, password = self.password)
			except paramiko.AuthenticationException:
				ScreenCloud.setError("Authentication failed (password)")
				return False
		else:
			try:
				private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase)
				transport.connect(username=self.username, pkey=private_key)
			except paramiko.AuthenticationException:
				ScreenCloud.setError("Authentication failed (key)")
				return False
		sftp = paramiko.SFTPClient.from_transport(transport)
		try:
			sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name))
		except IOError:
			ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.")
			return False
		sftp.close()
		transport.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Ejemplo n.º 3
0
    def upload(self, screenshot, name):
        self.loadSettings()
        if self.loggedIn:
            self.client.auth_provider.refresh_token()
        #Save to temporary file
        timestamp = time.time()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        #Workaround to get id of app folder
        import requests, json
        endpoint = "https://api.onedrive.com/v1.0/drives/me/special/approot"
        headers = {
            "Authorization": "Bearer " + self.client.auth_provider.access_token
        }
        response = requests.get(endpoint, headers=headers).json()
        appfolder_id = response["id"]
        #Upload
        uploaded_item = self.client.item(drive='me', id=appfolder_id).children[
            ScreenCloud.formatFilename(name)].upload(tmpFilename)
        print(uploaded_item, " ".join(dir(uploaded_item)), str(uploaded_item),
              uploaded_item.id, uploaded_item.image)
        if self.copyLink:
            permission = self.client.item(
                id=uploaded_item.id).create_link("view").post()
            ScreenCloud.setUrl(permission.link.web_url)

        return True
Ejemplo n.º 4
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        f = open(tmpFilename, 'rb')
        response = self.client.files_upload(
            f, '/' + ScreenCloud.formatFilename(name))
        f.close()
        os.remove(tmpFilename)
        if self.copy_link:
            share = self.client.sharing_create_shared_link(
                '/' + ScreenCloud.formatFilename(name), short_url=True)
            ScreenCloud.setUrl(share.url)

        return True
Ejemplo n.º 5
0
    def upload(self, screenshot, name):
        self.loadSettings()

        name = id_generator()

        timestamp = time.time()
        tmpFilename = QDesktopServices.storageLocation(
            QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(
                str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        ftp = ftplib.FTP()
        ftp.connect(self.host, self.port)
        ftp.login(self.username, self.password)
        f = open(tmpFilename, 'rb')
        try:
            ftp.cwd(self.folder)
        except ftplib.error_perm as err:
            ScreenCloud.setError(err.message)
            return False
        try:
            ftp.storbinary('STOR ' + name, f)
        except ftplib.error_perm as err:
            ScreenCloud.setError(err.message)
            return False
        ftp.quit()
        f.close()
        if self.url:
            ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
        return True
Ejemplo n.º 6
0
    def upload(self, screenshot, name):
        self.loadSettings()
        # Save to a temporary file
        timestamp = time.time()
        try:
            tmpFilename = (
                QDesktopServices.storageLocation(QDesktopServices.TempLocation)
                + "/"
                + ScreenCloud.formatFilename(str(timestamp))
            )
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  # fix for Qt5

            tmpFilename = (
                QStandardPaths.writableLocation(QStandardPaths.TempLocation)
                + "/"
                + ScreenCloud.formatFilename(str(timestamp))
            )
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        # Connect to server
        try:
            transport = paramiko.Transport((self.host, self.port))
        except Exception as e:
            ScreenCloud.setError(e.message)
            return False
        if self.authMethod == "Password":
            try:
                transport.connect(username=self.username, password=self.password)
            except paramiko.AuthenticationException:
                ScreenCloud.setError("Authentication failed (password)")
                return False
        else:
            try:
                private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase)
                transport.connect(username=self.username, pkey=private_key)
            except paramiko.AuthenticationException:
                ScreenCloud.setError("Authentication failed (key)")
                return False
            except paramiko.SSHException as e:
                ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message)
                return False
            except Exception as e:
                ScreenCloud.setError("Unknown error: " + e.message)
                return False
        sftp = paramiko.SFTPClient.from_transport(transport)
        try:
            sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name))
        except IOError:
            ScreenCloud.setError(
                "Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions."
            )
            return False
        sftp.close()
        transport.close()
        if self.url:
            ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
        return True
Ejemplo n.º 7
0
 def upload(self, screenshot, name):
     self.loadSettings()
     #Save to a temporary file
     timestamp = time.time()
     try:
         tmpFilename = QDesktopServices.storageLocation(
             QDesktopServices.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     except AttributeError:
         from PythonQt.QtCore import QStandardPaths  #fix for Qt5
         tmpFilename = QStandardPaths.writableLocation(
             QStandardPaths.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
     #Connect to server
     try:
         transport = paramiko.Transport((self.host, self.port))
     except Exception as e:
         ScreenCloud.setError(e.message)
         return False
     if self.authMethod == "Password":
         try:
             transport.connect(username=self.username,
                               password=self.password)
         except paramiko.AuthenticationException:
             ScreenCloud.setError("Authentication failed (password)")
             return False
     else:
         try:
             private_key = paramiko.RSAKey.from_private_key_file(
                 self.keyfile, password=self.passphrase)
             transport.connect(username=self.username, pkey=private_key)
         except paramiko.AuthenticationException:
             ScreenCloud.setError("Authentication failed (key)")
             return False
         except paramiko.SSHException as e:
             ScreenCloud.setError("Error while connecting to " + self.host +
                                  ":" + str(self.port) + ". " + e.message)
             return False
         except Exception as e:
             ScreenCloud.setError("Unknown error: " + e.message)
             return False
     sftp = paramiko.SFTPClient.from_transport(transport)
     try:
         sftp.put(tmpFilename,
                  self.folder + "/" + ScreenCloud.formatFilename(name))
     except IOError:
         ScreenCloud.setError("Failed to write " + self.folder + "/" +
                              ScreenCloud.formatFilename(name) +
                              ". Check permissions.")
         return False
     sftp.close()
     transport.close()
     if self.url:
         ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
     return True
Ejemplo n.º 8
0
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f)
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.share('/' + ScreenCloud.formatFilename(name))
			ScreenCloud.setUrl(share['url'])

		return True
Ejemplo n.º 9
0
	def upload(self, screenshot, name):
		self.loadSettings()
		#Make sure we have a up to date token
		if not self.uploadAnon:
			try:
				self.imgur.refresh_access_token()
			except Exception as e:
				ScreenCloud.setError("Failed to refresh imgur access token. " + e.message)
				return False
		#Save to a temporary file
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Upload!
		try:
			uploaded_image = self.imgur.upload_image(tmpFilename, title=ScreenCloud.formatFilename(name, False))
		except Exception as e:
			ScreenCloud.setError("Failed to upload to imgur. " + e.message)
			return False
		if self.copyLink:
			if self.copyDirectLink:
				ScreenCloud.setUrl(uploaded_image.link)
			else:
				ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id)
		return True
Ejemplo n.º 10
0
	def upload(self, screenshot, name):
		self.loadSettings()

		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		ftp = ftplib.FTP()
		ftp.connect(self.host, self.port)
		ftp.login(self.username, self.password)
		f = open(tmpFilename, 'rb')
		try:
			ftp.cwd(self.folder)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		try:
			ftp.storbinary('STOR ' + name, f)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		ftp.quit()
		f.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Ejemplo n.º 11
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()

        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))

        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        try:
            oc = nextcloud.Client(self.url)
            oc.login(self.username, self.password)

            remotePath = ""

            if self.remotePath:
                remotePath = self.remotePath

                try:
                    oc.file_info(remotePath)
                except Exception:
                    oc.mkdir(remotePath)

            uploaded_image = oc.put_file(
                remotePath + "/" + ScreenCloud.formatFilename(name, False),
                tmpFilename)

            if self.copyLink:
                link_info = oc.share_file_with_link(
                    remotePath + "/" + ScreenCloud.formatFilename(name, False))
                share_link = link_info.get_link()

                if self.copyDirectLink:
                    share_link = share_link + "/download"

                ScreenCloud.setUrl(share_link)
            return True
        except Exception as e:
            ScreenCloud.setError("Failed to upload to NextCloud. " + e.message)
            return False
Ejemplo n.º 12
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()
        tmpFilename = QDesktopServices.storageLocation(
            QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(
                str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        f = open(tmpFilename, 'rb')
        response = self.client.put_file('/' + ScreenCloud.formatFilename(name),
                                        f)
        f.close()
        os.remove(tmpFilename)
        if self.copy_link:
            share = self.client.share('/' + ScreenCloud.formatFilename(name))
            ScreenCloud.setUrl(share['url'])

        return True
Ejemplo n.º 13
0
	def upload(self, screenshot, name):
		self.loadSettings()
		f = QFile(self.folder + "/" + ScreenCloud.formatFilename(name))
		f.open(QIODevice.WriteOnly)
		if not f.isWritable():
			ScreenCloud.setError("File " + f.fileName() + " is not writable!")
			return False
		screenshot.save(f, ScreenCloud.getScreenshotFormat())
		f.close()
		return True
Ejemplo n.º 14
0
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f)
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.share('/' + ScreenCloud.formatFilename(name), False)
			ScreenCloud.setUrl(share['url'].replace('dl=0', 'raw=1'))

		return True
Ejemplo n.º 15
0
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.files_upload(f, '/' + ScreenCloud.formatFilename(name))
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.sharing_create_shared_link('/' + ScreenCloud.formatFilename(name), short_url=True)
			ScreenCloud.setUrl(share.url)

		return True
Ejemplo n.º 16
0
 def upload(self, screenshot, name):
     self.loadSettings()
     f = QFile(self.folder + "/" + ScreenCloud.formatFilename(name))
     f.open(QIODevice.WriteOnly)
     if not f.isWritable():
         ScreenCloud.setError("File " + f.fileName() + " is not writable!")
         return False
     screenshot.save(f, ScreenCloud.getScreenshotFormat())
     f.close()
     return True
Ejemplo n.º 17
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()

        try:
            tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))

        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        try:
            oc = owncloud.Client(self.url)
            oc.login(self.username, self.password)

            remotePath = ""

            if self.remotePath:
                remotePath = self.remotePath

                try:
                    oc.file_info(remotePath)
                except Exception:
                    oc.mkdir(remotePath)

            uploaded_image = oc.put_file(remotePath + "/" + ScreenCloud.formatFilename(name, False), tmpFilename)

            if self.copyLink:
                link_info = oc.share_file_with_link(remotePath + "/" + ScreenCloud.formatFilename(name, False))
                share_link = link_info.get_link()

                if self.copyDirectLink:
                    share_link = share_link + "/download"

                ScreenCloud.setUrl(share_link)
            return True
        except Exception as e:
            ScreenCloud.setError("Failed to upload to OwnCloud. " + e.message)
            return False
Ejemplo n.º 18
0
    def upload(self, screenshot, name):
        self.loadSettings()
        tmpFilename = QStandardPaths.writableLocation(
            QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(
                str(time.time()))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        data = {"name": name}
        files = {"file": open(tmpFilename, "rb")}

        try:
            response = requests.post("https://uguu.se/api.php?d=upload-tool",
                                     data=data,
                                     files=files)
            response.raise_for_status()
            if self.copyLink:
                ScreenCloud.setUrl(response.text)
        except RequestException as e:
            ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message)
            return False

        return True
Ejemplo n.º 19
0
    def upload(self, screenshot, name):
        self.loadSettings()
        tmpFilename = (
            QDesktopServices.storageLocation(QDesktopServices.TempLocation)
            + "/"
            + ScreenCloud.formatFilename(str(time.time()))
        )
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        data = {"name": name}
        files = {"file": open(tmpFilename, "rb")}

        try:
            response = requests.post("https://uguu.se/api.php?d=upload-tool", data=data, files=files)
            response.raise_for_status()
            if self.copyLink:
                ScreenCloud.setUrl(response.text)
        except RequestException as e:
            ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message)
            return False

        return True
Ejemplo n.º 20
0
 def getFilename(self):
     return ScreenCloud.formatFilename("screenshot")
Ejemplo n.º 21
0
    def upload(self, screenshot, name):
        Headers = {"User-Agent": "ScreenCloud-Cloudup"}

        try:
            FilePath = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time()))
            screenshot.save(QFile(FilePath), ScreenCloud.getScreenshotFormat())

            # Has a stream been specified or should we create on?
            if self.Stream:
                Stream = self.Stream
            else:
                # Create stream
                s = requests.post("https://api.cloudup.com/1/streams?access_token=" + self.Key, data = {"title": name}, headers = Headers)
                c = s.json()

                Stream = c["id"]

            # Create item inside the stream
            i = requests.post("https://api.cloudup.com/1/items?access_token=" + self.Key, data = {"filename": FilePath, "stream_id": Stream}, headers = Headers)
            j = json.loads(i.text)

            # Upload
            requests.post(j["s3_url"], files = {"file": open(FilePath, "rb")}, data = {
                "key": j["s3_key"],
                "acl": "public-read",
                "policy": j["s3_policy"],
                "signature": j["s3_signature"],
                "AWSAccessKeyId": j["s3_access_key"],

                "Content-Type": "image/png",
                "Content-Length": os.path.getsize(FilePath)
            }, headers = Headers)

            # Completion signal
            requests.patch("https://api.cloudup.com/1/items/" + j["id"] + "?access_token=" + self.Key, json.dumps({u"complete": True}), headers = {
                "Content-Type": "application/json",
                "User-Agent": "ScreenCloud-Cloudup"
            })

            # Does the user want the Cloudup item link?
            if self.copyCloudup:
                ScreenCloud.setUrl(j["url"])

            # Does the user want the direct link?
            if self.copyDirect:
                ScreenCloud.setUrl(j["direct_url"])
        except requests.exceptions.RequestException as E:
            ScreenCloud.setError("Failued to upload to Cloudup: " + E.message)
            return False

        return True
Ejemplo n.º 22
0
 def getFilename(self):
     return ScreenCloud.formatFilename(str(time()))
Ejemplo n.º 23
0
 def getFilename(self):
     # Random string (uuid4) that we split (-) for to take last section (4)
     rnd = str(uuid.uuid4())
     rndspl = rnd.split('-')
     rnstr = rndspl[4]
     return ScreenCloud.formatFilename(rnstr)
Ejemplo n.º 24
0
 def getFilename(self):
     return ScreenCloud.formatFilename(self.Format)
Ejemplo n.º 25
0
 def getFilename(self):
     return ScreenCloud.formatFilename('Screenshot')
Ejemplo n.º 26
0
 def getFilename(self):
     # Random string (uuid4) that we split (-) for to take last section (4)
     rnd = str(uuid.uuid4())
     rndspl = rnd.split("-")
     rnstr = rndspl[4]
     return ScreenCloud.formatFilename(rnstr)
Ejemplo n.º 27
0
	def upload(self, screenshot, name):
		self.loadSettings()
		url = self.url_address

		if not url.startswith('http'):
			ScreenCloud.setError('Invalid url!')
			return False

		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		reply = requests.post(url,
							  files={'image': open(tmpFilename, 'rb')}
							  ).json()

		try:
			ScreenCloud.setUrl(reply['href'])
		except Exception as e:
			ScreenCloud.setError("Could not upload to: " + self.url_address + "\nError: " + e.message)
			return False
		return True
Ejemplo n.º 28
0
	def getFilename(self):
		self.loadSettings()
		name = uuid.uuid4().hex
		return ScreenCloud.formatFilename(name[:16])
Ejemplo n.º 29
0
	def getFilename(self):
		timestamp = time.time()
		return ScreenCloud.formatFilename(str(timestamp))
Ejemplo n.º 30
0
	def upload(self, screenshot, name):
		self.loadSettings()
		#Save to a temporary file
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Connect to server
		try:
			sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			sock.connect((self.host, self.port))
			session = Session()
			session.handshake(sock)
		except Exception as e:
			ScreenCloud.setError(e.message)
			return False
		if self.authMethod == "Password":
			try:
				session.userauth_password(self.username, self.password)
			except ssh2.exceptions.AuthenticationError:
				ScreenCloud.setError("Authentication failed (password)")
				return False
		else:
			try:
				session.userauth_publickey_fromfile(self.username, self.keyfile, passphrase=self.passphrase)
			except ssh2.exceptions.AuthenticationError:
				ScreenCloud.setError("Authentication failed (key)")
				return False
			except Exception as e:
				ScreenCloud.setError("Unknown error: " + e.message)
				return False
		sftp = session.sftp_init()
		mode = LIBSSH2_SFTP_S_IRUSR | \
			LIBSSH2_SFTP_S_IWUSR | \
			LIBSSH2_SFTP_S_IRGRP | \
			LIBSSH2_SFTP_S_IROTH
		f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE
		try:
			try:
				sftp.opendir(self.folder)
			except ssh2.exceptions.SFTPError:
				sftp.mkdir(self.folder, mode | LIBSSH2_SFTP_S_IXUSR)
			(filepath, filename) = os.path.split(ScreenCloud.formatFilename(name))
			if len(filepath):
				for folder in filepath.split("/"):
					try:
						sftp.mkdir(folder)
					except IOError:
						pass
			source = tmpFilename
			destination = self.folder + "/" + ScreenCloud.formatFilename(filename)
			with open(source, 'rb') as local_fh, sftp.open(destination, f_flags, mode) as remote_fh:
				for data in local_fh:
					remote_fh.write(data)
		except IOError:
			ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.")
			return False
		sock.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Ejemplo n.º 31
0
 def getFilename(self):
     return ScreenCloud.formatFilename('screenshot_%Y-%m-%d_%H-%M-%S')
Ejemplo n.º 32
0
 def getFilename(self):
     self.loadSettings()
     return ScreenCloud.formatFilename(self.nameFormat)
Ejemplo n.º 33
0
 def getFilename(self):
     timestamp = time.time()
     return ScreenCloud.formatFilename(str(timestamp))
Ejemplo n.º 34
0
 def nameFormatEdited(self, nameFormat):
     self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False))
Ejemplo n.º 35
0
 def getFilename(self):
     return fix_filename(
         ScreenCloud.formatFilename(self.name_format,
                                    custom_vars=get_rnd_dict()))
Ejemplo n.º 36
0
 def getFilename(self):
     self.loadSettings()
     return ScreenCloud.formatFilename(self.nameFormat)
Ejemplo n.º 37
0
 def nameFormatEdited(self, name_format):
     self.settingsDialog.group_screenshot.label_example.setText(
         fix_filename(
             ScreenCloud.formatFilename(name_format,
                                        custom_vars=get_rnd_dict())))
Ejemplo n.º 38
0
 def nameFormatEdited(self, nameFormat):
     self.settingsDialog.group_location.label_example.setText(
         ScreenCloud.formatFilename(nameFormat))
Ejemplo n.º 39
0
	def upload(self, screenshot, name):
		self.loadSettings()
		f = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(name)
		screenshot.save(QFile(f), ScreenCloud.getScreenshotFormat())

		now = datetime.datetime.now()
		date = "/%s/%02d/%02d" % (now.year, now.month, now.day)
		path = "/%s/%02d/%02d/%s" % (now.year, now.month, now.day, ScreenCloud.formatFilename(name))

		if self.type == "SFTP":
			transport = paramiko.Transport((self.host, self.port))
			transport.connect(username = self.username, password = self.password)

			sftp = paramiko.SFTPClient.from_transport(transport)
			try:
				sftp.chdir(os.path.normpath(self.path) + date)
			except IOError:
				sftp.mkdir(os.path.normpath(self.path) + date)

			try:
				sftp.put(f, os.path.normpath(self.path) + path)
			except IOError:
				ScreenCloud.setError("Failed to write file")
			
			sftp.close()
			transport.close()
		elif self.type == "FTP":
			ftp = ftplib.FTP()
			ftp.connect(self.host, self.port)
			ftp.login(self.username, self.password)
			
			if os.path.normpath(self.path) in ftp.nlst():
				try:
					ftp.cwd(os.path.normpath(self.path))
				except ftplib.error_perm as err:
					ScreenCloud.setError(err.message)
					return False

			year = "%02d" % now.year
			month = "%02d" % now.month
			day = "%02d" % now.day

			if year in ftp.nlst():
				ftp.cwd(year)
			else:
				ftp.mkd(year)
				ftp.cwd(year)

			if month in ftp.nlst():
				ftp.cwd(month)
			else:
				ftp.mkd(month)
				ftp.cwd(month)

			if day in ftp.nlst():
				ftp.cwd(day)
			else:
				ftp.mkd(day)
				ftp.cwd(day)

			#borrowed from screencloud ftp plugin
			fs = open(f, 'rb')
			try:
				ftp.storbinary('STOR ' + name, fs)
			except ftplib.error_perm as err:
				ScreenCloud.setError(err.message)
				return False

			ftp.quit()
			fs.close()

		url = "%s%s/%s/%s/%s" % (self.url, now.year, now.month, now.day, ScreenCloud.formatFilename(name))
		ScreenCloud.setUrl(self.url.strip("/") + path)

		return True