processor settings sor
This commit is contained in:
parent
ee5db19d8e
commit
fb89f1946b
37
main.py
37
main.py
@ -3,8 +3,10 @@ import time
|
|||||||
from PythonQt.QtCore import QFile, QSettings
|
from PythonQt.QtCore import QFile, QSettings
|
||||||
from PythonQt.QtGui import QDesktopServices, QMessageBox
|
from PythonQt.QtGui import QDesktopServices, QMessageBox
|
||||||
from PythonQt.QtUiTools import QUiLoader
|
from PythonQt.QtUiTools import QUiLoader
|
||||||
|
from multiprocessing import Pool,Process
|
||||||
|
|
||||||
from seafapi import *
|
from seafapi import *
|
||||||
|
from processors import DefaultProcessor, EncryptedProcessor
|
||||||
###############################
|
###############################
|
||||||
## This is a temporary fix, should be removed when a newer python version is used ##
|
## This is a temporary fix, should be removed when a newer python version is used ##
|
||||||
import logging
|
import logging
|
||||||
@ -17,6 +19,8 @@ class SeafileUploader():
|
|||||||
self.loadSettings()
|
self.loadSettings()
|
||||||
self.seaf_lib = None
|
self.seaf_lib = None
|
||||||
self.libs = None
|
self.libs = None
|
||||||
|
self.pool = Pool(2)
|
||||||
|
self.processor = None
|
||||||
|
|
||||||
def showSettingsUI(self, parentWidget):
|
def showSettingsUI(self, parentWidget):
|
||||||
self.parentWidget = parentWidget
|
self.parentWidget = parentWidget
|
||||||
@ -40,7 +44,6 @@ class SeafileUploader():
|
|||||||
i=0
|
i=0
|
||||||
select = 0
|
select = 0
|
||||||
for lib in self.libs:
|
for lib in self.libs:
|
||||||
print "%s %s <-> %s%s" % (lib.name,lib.id,self.seaf_lib.name,self.seaf_lib.id)
|
|
||||||
if self.seaf_lib is not None and lib.id == self.seaf_lib.id:
|
if self.seaf_lib is not None and lib.id == self.seaf_lib.id:
|
||||||
select = i
|
select = i
|
||||||
print "set %s" % lib.name
|
print "set %s" % lib.name
|
||||||
@ -76,7 +79,8 @@ class SeafileUploader():
|
|||||||
self.access_token = SeafileToken(settings.value("auth-username", False),settings.value("auth-token", False))
|
self.access_token = SeafileToken(settings.value("auth-username", False),settings.value("auth-token", False))
|
||||||
else:
|
else:
|
||||||
self.access_token = None
|
self.access_token = None
|
||||||
self.nameFormat = settings.value("name-format", "Screenshot at %H:%M:%S")
|
self.nameFormat = settings.value("name-format", "Screenshot %Y-%m-%d %H_%M_%S")
|
||||||
|
self.upload_scheme = settings.value("upload-scheme", "regular")
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
if self.isConfigured():
|
if self.isConfigured():
|
||||||
@ -85,11 +89,16 @@ class SeafileUploader():
|
|||||||
if lib.id == self.lib_id:
|
if lib.id == self.lib_id:
|
||||||
self.seaf_lib = lib
|
self.seaf_lib = lib
|
||||||
|
|
||||||
|
self.processor = EncryptedProcessor(self.seaf_lib,self.lib_path)#DefaultProcessor(self.seaf_lib,self.lib_path)
|
||||||
|
|
||||||
def saveSettings(self):
|
def saveSettings(self):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
settings.beginGroup("uploaders")
|
settings.beginGroup("uploaders")
|
||||||
settings.beginGroup("seafile")
|
settings.beginGroup("seafile")
|
||||||
|
try:
|
||||||
self.copyLink = self.settingsDialog.linkCopyCheck.checked
|
self.copyLink = self.settingsDialog.linkCopyCheck.checked
|
||||||
|
except:
|
||||||
|
pass
|
||||||
settings.setValue("copy-link", self.copyLink)
|
settings.setValue("copy-link", self.copyLink)
|
||||||
if self.access_token is not None:
|
if self.access_token is not None:
|
||||||
settings.setValue("auth-username", self.access_token.username )
|
settings.setValue("auth-username", self.access_token.username )
|
||||||
@ -98,13 +107,15 @@ class SeafileUploader():
|
|||||||
if self.seaf_lib is not None:
|
if self.seaf_lib is not None:
|
||||||
settings.setValue("library", "%s/%s" % (self.seaf_lib.id,self.seaf_lib.name))
|
settings.setValue("library", "%s/%s" % (self.seaf_lib.id,self.seaf_lib.name))
|
||||||
settings.setValue("library-path", self.lib_path)
|
settings.setValue("library-path", self.lib_path)
|
||||||
|
settings.setValue("name-format", self.nameFormat)
|
||||||
|
settings.setValue("upload-scheme", self.upload_scheme)
|
||||||
#settings.setValue("name-format", self.settingsDialog.group_name.input_name.text)
|
#settings.setValue("name-format", self.settingsDialog.group_name.input_name.text)
|
||||||
print self.seaf_lib, self.lib_path
|
print self.seaf_lib, self.lib_path
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def isConfigured(self):
|
def isConfigured(self):
|
||||||
return self.access_token and self.seaf_url
|
return self.access_token and self.seaf_url and self.processor.is_configured()
|
||||||
|
|
||||||
def getFilename(self):
|
def getFilename(self):
|
||||||
self.loadSettings()
|
self.loadSettings()
|
||||||
@ -118,22 +129,25 @@ class SeafileUploader():
|
|||||||
return False
|
return False
|
||||||
#Save to a temporary file
|
#Save to a temporary file
|
||||||
timestamp = time.time()
|
timestamp = time.time()
|
||||||
|
def tempfile(name):
|
||||||
try:
|
try:
|
||||||
tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
|
return QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
from PythonQt.QtCore import QStandardPaths #fix for Qt5
|
from PythonQt.QtCore import QStandardPaths #fix for Qt5
|
||||||
tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
|
return QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name
|
||||||
|
|
||||||
|
tmpFilename = tempfile(ScreenCloud.formatFilename(str(timestamp)))
|
||||||
screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
|
screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
|
||||||
#Upload!
|
#Upload!
|
||||||
link=None
|
link=None
|
||||||
try:
|
if True:
|
||||||
file = self.seaf_lib.upload(tmpFilename,self.getFilename(),self.lib_path)
|
#try:
|
||||||
link = file.share()
|
link = self.processor.upload(tmpFilename,self.getFilename())
|
||||||
except Exception as e:
|
|
||||||
ScreenCloud.setError("Failed to upload to seafile. " + e.message)
|
|
||||||
return False
|
|
||||||
if self.copyLink:
|
if self.copyLink:
|
||||||
ScreenCloud.setUrl(link)
|
ScreenCloud.setUrl(link)
|
||||||
|
#except Exception as e:
|
||||||
|
# ScreenCloud.setError("Failed to upload to seafile. " + e.message)
|
||||||
|
# return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def startAuthenticationProcess(self):
|
def startAuthenticationProcess(self):
|
||||||
@ -189,3 +203,4 @@ class SeafileUploader():
|
|||||||
|
|
||||||
def nameFormatEdited(self, nameFormat):
|
def nameFormatEdited(self, nameFormat):
|
||||||
self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False))
|
self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False))
|
||||||
|
|
||||||
|
86
modules/processors.py
Normal file
86
modules/processors.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
from encryptedscreenshot import EncryptedScreenshot, Signer
|
||||||
|
import getpass, os
|
||||||
|
from PythonQt.QtGui import QInputDialog
|
||||||
|
from PythonQt.QtCore import QSettings
|
||||||
|
from seafapi import *
|
||||||
|
|
||||||
|
class Processor:
|
||||||
|
|
||||||
|
def configure(self,parent):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def is_configured(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def upload(self,file):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DefaultProcessor(Processor):
|
||||||
|
|
||||||
|
def __init__(self,seaf_lib,lib_path):
|
||||||
|
self.seaf_lib = seaf_lib
|
||||||
|
self.lib_path = lib_path
|
||||||
|
|
||||||
|
def upload(self,file,name):
|
||||||
|
return self.seaf_lib.upload(file,name,self.lib_path).share()
|
||||||
|
|
||||||
|
class EncryptedProcessor(Processor):
|
||||||
|
|
||||||
|
def __init__(self,seaf_lib,lib_path):
|
||||||
|
self.seaf_lib = seaf_lib
|
||||||
|
self.lib_path = lib_path
|
||||||
|
self.load_settings()
|
||||||
|
self.host = ""
|
||||||
|
|
||||||
|
def load_settings(self):
|
||||||
|
settings = QSettings()
|
||||||
|
settings.beginGroup("uploaders")
|
||||||
|
settings.beginGroup("seafile")
|
||||||
|
settings.beginGroup("encscreen")
|
||||||
|
self.host = settings.value("url", "")
|
||||||
|
settings.endGroup()
|
||||||
|
settings.endGroup()
|
||||||
|
settings.endGroup()
|
||||||
|
|
||||||
|
def save_settings(self):
|
||||||
|
settings = QSettings()
|
||||||
|
settings.beginGroup("uploaders")
|
||||||
|
settings.beginGroup("seafile")
|
||||||
|
settings.beginGroup("encscreen")
|
||||||
|
settings.setValue("url", self.host)
|
||||||
|
settings.endGroup()
|
||||||
|
settings.endGroup()
|
||||||
|
settings.endGroup()
|
||||||
|
|
||||||
|
def is_configured(self):
|
||||||
|
return self.host is not None and self.host != ""
|
||||||
|
|
||||||
|
def configure(self,parent):
|
||||||
|
self.host = QInputDialog.getText(parent, 'Encscreen Server Setup', 'Enter server url (ex. https://servertld/s#%id%key):', text="https://screens.shimun.net/s#%id%key")
|
||||||
|
self.save_settings()
|
||||||
|
|
||||||
|
def upload(self,file,name):
|
||||||
|
enrypted = EncryptedScreenshot({
|
||||||
|
"owner": unicode(getpass.getuser()),
|
||||||
|
"format": unicode(str(file).split('.')[-1]),
|
||||||
|
"title": unicode(name),
|
||||||
|
"timestamp": int(time.time() * 1000),
|
||||||
|
"size": os.stat(file).st_size
|
||||||
|
},signer=Signer.default())
|
||||||
|
tmpHandle = open(file + "c", 'wb')
|
||||||
|
tmpHandle.write(enrypted.assemble(file))
|
||||||
|
tmpHandle.close()
|
||||||
|
seaf_file = self.seaf_lib.upload(file + "c",name + ".enc",self.lib_path)
|
||||||
|
if not seaf_file:
|
||||||
|
return
|
||||||
|
seaf_link = seaf_file.share()
|
||||||
|
if seaf_link:
|
||||||
|
id = str(seaf_link).split('/')[-2]
|
||||||
|
return self.host.replace('%id', id).replace('%key',"%s" % enrypted.password)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user