Compare commits
1 Commits
master
...
configure-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
77592fb78b |
1
main.py
1
main.py
@ -27,6 +27,7 @@ class SeafileUploader():
|
||||
self.parentWidget = 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_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_location.widget_location.pathEdit.connect("textChanged(QString)", self.locationUpdate)
|
||||
self.settingsDialog.group_location.widget_location.libraryEditDrop.connect("currentIndexChanged(QString)", self.locationUpdate)
|
||||
|
@ -4,7 +4,6 @@ import requests
|
||||
class SeafileClient:
|
||||
|
||||
def __init__(self,server,username,password=None,token=None):
|
||||
self.session = requests.Session()
|
||||
self.server = server
|
||||
self.token = token
|
||||
self.login = (username,password)
|
||||
@ -14,7 +13,7 @@ class SeafileClient:
|
||||
|
||||
def ping(self):
|
||||
try:
|
||||
return self.session.get("%s/ping" % self.api_endpoint()).text == "pong"
|
||||
return requests.get("%s/ping" % self.api_endpoint()).text == "pong"
|
||||
except:
|
||||
return False
|
||||
|
||||
@ -22,7 +21,7 @@ class SeafileClient:
|
||||
def obtain_token(self):
|
||||
user,passw = self.login
|
||||
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()
|
||||
if "non_field_errors" in json:
|
||||
print json["non_field_errors"]
|
||||
@ -33,12 +32,11 @@ class SeafileClient:
|
||||
|
||||
def authorize(self):
|
||||
self.token = self.obtain_token()
|
||||
self.session.headers.update({'Authorization': "Token %s" % self.token.token})
|
||||
return self.token != False
|
||||
|
||||
#curl -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/
|
||||
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
|
||||
libraries=[]
|
||||
for lib in resp.json():
|
||||
@ -50,7 +48,6 @@ class SeafileLibrary:
|
||||
|
||||
def __init__(self,client,id,name,owner):
|
||||
self.client = client
|
||||
self.session = self.client.session
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.owner = owner
|
||||
@ -62,11 +59,11 @@ class SeafileLibrary:
|
||||
def obtain_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()
|
||||
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]
|
||||
|
||||
#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)},
|
||||
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
|
||||
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:
|
||||
json = resp.json()
|
||||
return SeafileFile(self,path,json['id'],json['size'])
|
||||
@ -91,12 +88,11 @@ class SeafileFile:
|
||||
self.id = id
|
||||
self.path = path
|
||||
self.library = library
|
||||
self.session = self.library.session
|
||||
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/
|
||||
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'},
|
||||
data = {'p': self.path}
|
||||
)
|
||||
@ -105,7 +101,7 @@ class SeafileFile:
|
||||
def update(self,file):
|
||||
def obtain_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]
|
||||
directory, name = os.path.split(self.path)
|
||||
return self.library.upload(file,name,directory,obtain_link())
|
||||
|
154
settings.ui
154
settings.ui
@ -6,10 +6,16 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>437</width>
|
||||
<height>475</height>
|
||||
<width>500</width>
|
||||
<height>589</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Seafile - Settings</string>
|
||||
</property>
|
||||
@ -78,6 +84,40 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QGroupBox" name="group_location">
|
||||
<property name="enabled">
|
||||
@ -89,6 +129,12 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@ -104,56 +150,62 @@
|
||||
<property name="title">
|
||||
<string>Location</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="widget_location" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>391</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,1,1,1">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Library</string>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_location" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="libraryEditDrop"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>279</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Screenshots Folder</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="pathEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Library</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="libraryEditDrop"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>279</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Screenshots Folder</string>
|
||||
</property>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user