Compare commits

..

1 Commits

Author SHA1 Message Date
shim_
77592fb78b added configure option for processors 2018-05-10 18:55:27 +02:00
3 changed files with 112 additions and 63 deletions

View File

@ -27,6 +27,7 @@ class SeafileUploader():
self.parentWidget = parentWidget self.parentWidget = parentWidget
self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget)
self.settingsDialog.group_account.widget_loggedIn.loginButton.connect("clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.loginButton.connect("clicked()", self.startAuthenticationProcess)
self.settingsDialog.group_processor.widget_processor.configureButton.connect("clicked()", self.processor.configure(self.settingsDialog))
#self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) #self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited)
self.settingsDialog.group_location.widget_location.pathEdit.connect("textChanged(QString)", self.locationUpdate) self.settingsDialog.group_location.widget_location.pathEdit.connect("textChanged(QString)", self.locationUpdate)
self.settingsDialog.group_location.widget_location.libraryEditDrop.connect("currentIndexChanged(QString)", self.locationUpdate) self.settingsDialog.group_location.widget_location.libraryEditDrop.connect("currentIndexChanged(QString)", self.locationUpdate)

View File

@ -4,7 +4,6 @@ import requests
class SeafileClient: class SeafileClient:
def __init__(self,server,username,password=None,token=None): def __init__(self,server,username,password=None,token=None):
self.session = requests.Session()
self.server = server self.server = server
self.token = token self.token = token
self.login = (username,password) self.login = (username,password)
@ -14,7 +13,7 @@ class SeafileClient:
def ping(self): def ping(self):
try: try:
return self.session.get("%s/ping" % self.api_endpoint()).text == "pong" return requests.get("%s/ping" % self.api_endpoint()).text == "pong"
except: except:
return False return False
@ -22,7 +21,7 @@ class SeafileClient:
def obtain_token(self): def obtain_token(self):
user,passw = self.login user,passw = self.login
try: try:
req=self.session.post("%s/auth-token/" % self.api_endpoint(), data = {'username': user, 'password': passw }) req=requests.post("%s/auth-token/" % self.api_endpoint(), data = {'username': user, 'password': passw })
json = req.json() json = req.json()
if "non_field_errors" in json: if "non_field_errors" in json:
print json["non_field_errors"] print json["non_field_errors"]
@ -33,12 +32,11 @@ class SeafileClient:
def authorize(self): def authorize(self):
self.token = self.obtain_token() self.token = self.obtain_token()
self.session.headers.update({'Authorization': "Token %s" % self.token.token})
return self.token != False return self.token != False
#curl -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/ #curl -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/
def libraries(self): def libraries(self):
resp=self.session.get("%s/repos/" % self.api_endpoint(), headers = {'Authorization': "Token %s" % self.token.token, 'Accept': 'application/json; indent=4' }) resp=requests.get("%s/repos/" % self.api_endpoint(), headers = {'Authorization': "Token %s" % self.token.token, 'Accept': 'application/json; indent=4' })
if not resp.status_code == 200: return if not resp.status_code == 200: return
libraries=[] libraries=[]
for lib in resp.json(): for lib in resp.json():
@ -50,7 +48,6 @@ class SeafileLibrary:
def __init__(self,client,id,name,owner): def __init__(self,client,id,name,owner):
self.client = client self.client = client
self.session = self.client.session
self.id = id self.id = id
self.name = name self.name = name
self.owner = owner self.owner = owner
@ -62,11 +59,11 @@ class SeafileLibrary:
def obtain_link(): def obtain_link():
#curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/upload-link/ #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/upload-link/
print "%s/upload-link" % self.api_endpoint() print "%s/upload-link" % self.api_endpoint()
quoted = self.session.get("%s/upload-link" % self.api_endpoint(), headers = {'Authorization': "Token %s" % self.client.token.token,}).text quoted = requests.get("%s/upload-link" % self.api_endpoint(), headers = {'Authorization': "Token %s" % self.client.token.token,}).text
return quoted[1:-1] return quoted[1:-1]
#curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -F file=@test.txt -F filename=test.txt -F parent_dir=/ http://cloud.seafile.com:8082/upload-api/73c5d117-3bcf-48a0-aa2a-3f48d5274ae3 #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -F file=@test.txt -F filename=test.txt -F parent_dir=/ http://cloud.seafile.com:8082/upload-api/73c5d117-3bcf-48a0-aa2a-3f48d5274ae3
resp = self.session.post(link or obtain_link() , resp = requests.post(link or obtain_link() ,
files={'file': (file_name,open(file, 'rb')), 'parent_dir': directory, 'target_file': "%s/%s" % (directory,file_name)}, files={'file': (file_name,open(file, 'rb')), 'parent_dir': directory, 'target_file': "%s/%s" % (directory,file_name)},
headers = {'Authorization': "Token %s" % self.client.token.token,} headers = {'Authorization': "Token %s" % self.client.token.token,}
) )
@ -76,7 +73,7 @@ class SeafileLibrary:
#curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/detail/?p=/foo.c #curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/detail/?p=/foo.c
def file_info(self,path): def file_info(self,path):
resp=self.session.get("%s/file/detail/?p=%s" % (self.api_endpoint(),path), headers = {'Authorization': "Token %s" % self.token.token, 'Accept': 'application/json; indent=4' }) resp=requests.get("%s/file/detail/?p=%s" % (self.api_endpoint(),path), headers = {'Authorization': "Token %s" % self.token.token, 'Accept': 'application/json; indent=4' })
if resp.status_code == 200: if resp.status_code == 200:
json = resp.json() json = resp.json()
return SeafileFile(self,path,json['id'],json['size']) return SeafileFile(self,path,json['id'],json['size'])
@ -91,12 +88,11 @@ class SeafileFile:
self.id = id self.id = id
self.path = path self.path = path
self.library = library self.library = library
self.session = self.library.session
self.size = size self.size = size
#curl -v -X PUT -d "p=/foo.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/afc3b694-7d4c-4b8a-86a4-89c9f3261b12/file/shared-link/ #curl -v -X PUT -d "p=/foo.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/afc3b694-7d4c-4b8a-86a4-89c9f3261b12/file/shared-link/
def share(self): def share(self):
resp = self.session.put("%s/repos/%s/file/shared-link/" % (self.library.client.api_endpoint(),self.library.id), resp = requests.put("%s/repos/%s/file/shared-link/" % (self.library.client.api_endpoint(),self.library.id),
headers = {'Authorization': "Token %s" % self.library.client.token.token, 'Accept': 'application/json; indent=4'}, headers = {'Authorization': "Token %s" % self.library.client.token.token, 'Accept': 'application/json; indent=4'},
data = {'p': self.path} data = {'p': self.path}
) )
@ -105,7 +101,7 @@ class SeafileFile:
def update(self,file): def update(self,file):
def obtain_link(): def obtain_link():
#curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/upload-link/ #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/upload-link/
quoted = self.session.get("%s/update-link" % self.library.api_endpoint(), headers = {'Authorization': "Token %s" % self.library.client.token.token,}).text quoted = requests.get("%s/update-link" % self.library.api_endpoint(), headers = {'Authorization': "Token %s" % self.library.client.token.token,}).text
return quoted[1:-1] return quoted[1:-1]
directory, name = os.path.split(self.path) directory, name = os.path.split(self.path)
return self.library.upload(file,name,directory,obtain_link()) return self.library.upload(file,name,directory,obtain_link())

View File

@ -6,10 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>437</width> <width>500</width>
<height>475</height> <height>589</height>
</rect> </rect>
</property> </property>
<property name="maximumSize">
<size>
<width>500</width>
<height>600</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Seafile - Settings</string> <string>Seafile - Settings</string>
</property> </property>
@ -78,6 +84,40 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="group_processor">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Processor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QWidget" name="widget_processor" native="true">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QComboBox" name="processorsDrop"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="configureButton">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="group_location"> <widget class="QGroupBox" name="group_location">
<property name="enabled"> <property name="enabled">
@ -89,6 +129,12 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>300</height>
</size>
</property>
<property name="baseSize"> <property name="baseSize">
<size> <size>
<width>0</width> <width>0</width>
@ -104,56 +150,62 @@
<property name="title"> <property name="title">
<string>Location</string> <string>Location</string>
</property> </property>
<widget class="QWidget" name="widget_location" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="geometry"> <item>
<rect> <widget class="QWidget" name="widget_location" native="true">
<x>20</x> <property name="sizePolicy">
<y>20</y> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>391</width> <horstretch>0</horstretch>
<height>101</height> <verstretch>0</verstretch>
</rect> </sizepolicy>
</property> </property>
<property name="sizePolicy"> <property name="maximumSize">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <size>
<horstretch>0</horstretch> <width>16777215</width>
<verstretch>0</verstretch> <height>300</height>
</sizepolicy> </size>
</property> </property>
<property name="layoutDirection"> <property name="layoutDirection">
<enum>Qt::LeftToRight</enum> <enum>Qt::LeftToRight</enum>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,1,1,1"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Library</string>
</property> </property>
</widget> <item>
</item> <widget class="QLabel" name="label_5">
<item> <property name="text">
<widget class="QComboBox" name="libraryEditDrop"/> <string>Library</string>
</item> </property>
<item> </widget>
<widget class="QLabel" name="label_4"> </item>
<property name="maximumSize"> <item>
<size> <widget class="QComboBox" name="libraryEditDrop"/>
<width>279</width> </item>
<height>16777215</height> <item>
</size> <widget class="QLabel" name="label_4">
</property> <property name="maximumSize">
<property name="text"> <size>
<string>Screenshots Folder</string> <width>279</width>
</property> <height>16777215</height>
</widget> </size>
</item> </property>
<item> <property name="text">
<widget class="QLineEdit" name="pathEdit"/> <string>Screenshots Folder</string>
</item> </property>
</layout> </widget>
</widget> </item>
<item>
<widget class="QLineEdit" name="pathEdit"/>
</item>
</layout>
<zorder>libraryEditDrop</zorder>
<zorder>label_5</zorder>
<zorder>label_4</zorder>
<zorder>pathEdit</zorder>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>