Example #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
Example #2
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
Example #3
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())

		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
Example #4
0
	def upload(self, screenshot, name):
		self.loadSettings()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename))
		try:
			command = command.encode(sys.getfilesystemencoding())
		except UnicodeEncodeError:
			ScreenCloud.setError("Invalid characters in command '" + command + "'")
			return False
		try:
			p = subprocess.Popen(command.split())
			p.wait()
			if p.returncode > 0:
				ScreenCloud.setError("Command " + command + " did not return 0")
				return False

		except OSError:
			ScreenCloud.setError("Failed to run command " + command)
			return False
			
		return True
Example #5
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
Example #6
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
Example #7
0
def getPluginDir():
    try:
        return QDesktopServices.storageLocation(
            QDesktopServices.DataLocation) + "/plugins"
    except AttributeError:
        from PythonQt.QtCore import QStandardPaths
        return QStandardPaths.writableLocation(
            QStandardPaths.DataLocation) + "/plugins"
Example #8
0
	def __init__(self):
		try:
			tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation)

		self.uil = QUiLoader()
		self.loadSettings()
Example #9
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
Example #10
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
Example #11
0
    def save(self, screenshot, name, path=None):
        path = QStandardPaths.writableLocation(QStandardPaths.TempLocation)
        path = os.path.join(path, name)

        try:
            screenshot.save(QFile(path), ScreenCloud.getScreenshotFormat())
        except Exception as e:
            raise

        return path
Example #12
0
	def __init__(self):
		try:
			tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation)

		paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log")
		self.uil = QUiLoader()
		self.loadSettings()
Example #13
0
    def __init__(self):
        try:
            tempLocation = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation)
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tempLocation = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation)

        #paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log")
        self.uil = QUiLoader()
        self.loadSettings()
Example #14
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
Example #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())

        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
Example #16
0
    def save(self, screenshot, name, path=None):
        if self.save_file and len(self.save_path) > 0:
            if os.path.isdir(self.save_path):
                path = self.save_path
            # else: # TODO: warn the user that the file could not be saved locally

        if not path:
            path = QStandardPaths.writableLocation(QStandardPaths.TempLocation)

        path = os.path.join(path, name)

        try:
            screenshot.save(QFile(path), ScreenCloud.getScreenshotFormat())
        except Exception as e:
            raise

        return path
Example #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())

		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
Example #18
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
Example #19
0
    def upload(self, screenshot, name):
        self.loadSettings()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation) + "/" + name
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation) + "/" + name
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        command = string.Formatter().vformat(self.commandFormat, (),
                                             defaultdict(str, s=tmpFilename))
        try:
            command = command.encode(sys.getfilesystemencoding())
        except UnicodeEncodeError:
            ScreenCloud.setError("Invalid characters in command '" + command +
                                 "'")
            return False
        try:
            if self.outputIsUrl:
                pipe = subprocess.PIPE
            else:
                pipe = None

            p = subprocess.Popen(command, shell=True, stdout=pipe)
            p.wait()
            if p.returncode > 0:
                ScreenCloud.setError(
                    "Command %s returned %d, but 0 was expected" %
                    (str(command), int(p.returncode)))
                return False
            elif self.outputIsUrl:
                result = bytes.decode(p.stdout.read())
                result = result.strip()
                ScreenCloud.setUrl(result)

        except OSError:
            ScreenCloud.setError("Failed to run command " + command)
            return False

        return True
Example #20
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
Example #21
0
    def upload(self, screenshot, name):
        self.loadSettings()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation) + "/" + name
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation) + "/" + name
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        base_path = os.path.dirname(os.path.realpath(__file__)) + '/'
        command = "bash " + base_path + "puush.sh " + self.apiKey + " " + tmpFilename
        try:
            command = command.encode(sys.getfilesystemencoding())
        except UnicodeEncodeError:
            ScreenCloud.setError("Invalid characters in command '" + command +
                                 "'")
            return False
        try:
            if self.outputIsUrl:
                pipe = subprocess.PIPE
            else:
                pipe = None

            p = subprocess.Popen(command, shell=True, stdout=pipe)
            p.wait()
            if p.returncode > 0:
                ScreenCloud.setError("Command " + command +
                                     " did not return 0")
                return False
            elif self.outputIsUrl:
                result = p.stdout.read()
                result = result.strip()
                ScreenCloud.setUrl(result)

        except OSError:
            ScreenCloud.setError("Failed to run command " + command)
            return False

        return True
    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
Example #23
0
	def upload(self, screenshot, name):
		self.loadSettings()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename))
		try:
			command = command.encode(sys.getfilesystemencoding())
		except UnicodeEncodeError:
			ScreenCloud.setError("Invalid characters in command '" + command + "'")
			return False
		try:
			if self.outputIsUrl:
				pipe = subprocess.PIPE
			else:
				pipe = None


			p = subprocess.Popen(command, shell=True, stdout=pipe)
			p.wait()
			if p.returncode > 0:
				ScreenCloud.setError("Command %s returned %d, but 0 was expected" % (str(command), int(p.returncode)))
				return False
			elif self.outputIsUrl:
				result = bytes.decode(p.stdout.read())
				result = result.strip()
				ScreenCloud.setUrl(result)

		except OSError:
			ScreenCloud.setError("Failed to run command " + command)
			return False

		return True
Example #24
0
def getPluginDir():
	try:
		return QDesktopServices.storageLocation(QDesktopServices.DataLocation) + "/plugins"
	except AttributeError:
		from PythonQt.QtCore import QStandardPaths
		return QStandardPaths.writableLocation(QStandardPaths.DataLocation) + "/plugins"
Example #25
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