Skip to content

Commit 670fb45

Browse files
committed
new api class + documentation
1 parent bee1ec5 commit 670fb45

File tree

12 files changed

+1434
-689
lines changed

12 files changed

+1434
-689
lines changed

Diff for: module/Api.py

+725
Large diffs are not rendered by default.

Diff for: module/PyFile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ def toDbDict(self):
176176
}
177177
}
178178

179-
@lock
180179
def abortDownload(self):
181180
"""abort pyfile if possible"""
182181
while self.id in self.m.core.threadManager.processingIds():
@@ -186,8 +185,9 @@ def abortDownload(self):
186185
sleep(0.1)
187186

188187
self.abort = False
189-
if hasattr(self, "plugin") and self.plugin and self.plugin.req:
188+
if self.hasPlugin() and self.plugin.req:
190189
self.plugin.req.abortDownloads()
190+
191191
self.release()
192192

193193
def finishIfDone(self):

Diff for: module/cli/ManageFiles.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
from Handler import Handler
2525
from printer import *
2626

27-
from module.remote.thriftbackend.thriftgen.pyload.Pyload import PackageData, PackageDoesNotExists
27+
from module.Api import Destination, PackageData
2828

2929
class ManageFiles(Handler):
3030
""" possibility to manage queue/collector """
3131

3232
def init(self):
33-
self.target = 1 #queue and collector are swapped
33+
self.target = Destination.Queue
3434
self.pos = 0 #position in queue
3535
self.package = -1 #choosen package
3636
self.mode = "" # move/delete/restart
@@ -155,7 +155,7 @@ def getPackages(self):
155155
if self.cache and self.time + 2 < time():
156156
return self.cache
157157

158-
if self.target == 1:
158+
if self.target == Destination.Queue:
159159
data = self.client.getQueue()
160160
else:
161161
data = self.client.getCollector()

Diff for: module/remote/ThriftBackend.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from module.remote.RemoteManager import BackendBase
2121

22-
from thriftbackend.Handler import Handler
2322
from thriftbackend.Processor import Processor
2423
from thriftbackend.Protocol import ProtocolFactory
2524
from thriftbackend.Socket import ServerSocket
@@ -30,8 +29,7 @@
3029

3130
class ThriftBackend(BackendBase):
3231
def setup(self, host, port):
33-
handler = Handler(self)
34-
processor = Processor(handler)
32+
processor = Processor(self.core.api)
3533

3634
key = None
3735
cert = None

Diff for: module/remote/thriftbackend/Handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _convertConfigFormat(self, c):
3434
item = ConfigItem()
3535
item.name = key
3636
item.description = data["desc"]
37-
item.value = str(data["value"]) if type(data["value"]) not in (str, unicode) else data["value"]
37+
item.value = str(data["value"]) if type(data["value"]) != basestring else data["value"]
3838
item.type = data["type"]
3939
items.append(item)
4040
section.items = items
@@ -59,7 +59,7 @@ def setConfigValue(self, category, option, value, section):
5959
- value
6060
- section
6161
"""
62-
self.serverMethods.set_conf_val(category, option, value, section)
62+
pass
6363

6464
def getConfig(self):
6565
c = self.serverMethods.get_config()

Diff for: module/remote/thriftbackend/pyload.thrift

+21-26
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ enum DownloadStatus {
2929
}
3030

3131
enum Destination {
32-
Queue,
33-
Collector
32+
Collector,
33+
Queue
3434
}
3535

3636
enum ElementType {
@@ -62,7 +62,7 @@ struct ServerStatus {
6262
2: i16 active,
6363
3: i16 queue,
6464
4: i16 total,
65-
5: i32 speed,
65+
5: i64 speed,
6666
6: bool download,
6767
7: bool reconnect
6868
}
@@ -104,19 +104,8 @@ struct PackageData {
104104
6: Destination dest,
105105
7: i16 order,
106106
8: Priority priority,
107-
9: list<FileData> links
108-
}
109-
110-
struct PackageInfo {
111-
1: PackageID pid,
112-
2: string name,
113-
3: string folder,
114-
4: string site,
115-
5: string password,
116-
6: Destination dest,
117-
7: i16 order,
118-
8: Priority priority,
119-
9: list<FileID> links
107+
9: optional list<FileID> fids,
108+
10: optional list<FileData> links
120109
}
121110

122111
struct CaptchaTask {
@@ -221,18 +210,26 @@ service Pyload {
221210
ResultID checkOnlineStatus(1: LinkList urls),
222211
map<PluginName, list<OnlineStatus>> pollResults(1: ResultID rid),
223212

224-
//downloads
213+
// downloads - information
225214
list<DownloadInfo> statusDownloads(),
226-
PackageID addPackage(1: string name, 2: LinkList links, 3: Destination dest),
227215
PackageData getPackageData(1: PackageID pid) throws (1: PackageDoesNotExists e),
216+
PackageData getPackageInfo(1: PackageID pid) throws (1: PackageDoesNotExists e),
228217
FileData getFileData(1: FileID fid) throws (1: FileDoesNotExists e),
229-
void deleteFiles(1: list<FileID> fids),
230-
void deletePackages(1: list<PackageID> pids),
231-
list<PackageInfo> getQueue(),
232-
list<PackageInfo> getCollector(),
218+
list<PackageData> getQueue(),
219+
list<PackageData> getCollector(),
233220
list<PackageData> getQueueData(),
234221
list<PackageData> getCollectorData(),
222+
map<i16, PackageID> getPackageOrder(1: Destination destination),
223+
map<i16, FileID> getFileOrder(1: PackageID pid)
224+
225+
// downloads - adding/deleting
226+
PackageID addPackage(1: string name, 2: LinkList links, 3: Destination dest),
235227
void addFiles(1: PackageID pid, 2: LinkList links),
228+
void uploadContainer(1: string filename, 2: binary data),
229+
void deleteFiles(1: list<FileID> fids),
230+
void deletePackages(1: list<PackageID> pids),
231+
232+
// downloads - modifying
236233
void pushToQueue(1: PackageID pid),
237234
void pullFromQueue(1: PackageID pid),
238235
void restartPackage(1: PackageID pid),
@@ -242,15 +239,13 @@ service Pyload {
242239
void stopDownloads(1: list<FileID> fids),
243240
void setPackageName(1: PackageID pid, 2: string name),
244241
void movePackage(1: Destination destination, 2: PackageID pid),
245-
void uploadContainer(1: string filename, 2: binary data),
246242
void setPriority(1: PackageID pid, 2: Priority priority)
247243
void orderPackage(1: PackageID pid, 2: i16 position),
248244
void orderFile(1: FileID fid, 2: i16 position),
249-
void setPackageData(1: PackageID pid, 2: map<string, string> data),
245+
void setPackageData(1: PackageID pid, 2: map<string, string> data) throws (1: PackageDoesNotExists e),
250246
void deleteFinished(),
251247
void restartFailed(),
252-
map<i16, PackageID> getPackageOrder(1: Destination destination),
253-
map<i16, FileID> getFileOrder(1: PackageID pid)
248+
254249

255250
//captcha
256251
bool isCaptchaWaiting(),

Diff for: module/remote/thriftbackend/thriftgen/pyload/Pyload-remote

+49-42
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
4444
print ' ResultID checkOnlineStatus(LinkList urls)'
4545
print ' pollResults(ResultID rid)'
4646
print ' statusDownloads()'
47-
print ' PackageID addPackage(string name, LinkList links, Destination dest)'
4847
print ' PackageData getPackageData(PackageID pid)'
48+
print ' PackageData getPackageInfo(PackageID pid)'
4949
print ' FileData getFileData(FileID fid)'
50-
print ' void deleteFiles( fids)'
51-
print ' void deletePackages( pids)'
5250
print ' getQueue()'
5351
print ' getCollector()'
5452
print ' getQueueData()'
5553
print ' getCollectorData()'
54+
print ' getPackageOrder(Destination destination)'
55+
print ' getFileOrder(PackageID pid)'
56+
print ' PackageID addPackage(string name, LinkList links, Destination dest)'
5657
print ' void addFiles(PackageID pid, LinkList links)'
58+
print ' void uploadContainer(string filename, string data)'
59+
print ' void deleteFiles( fids)'
60+
print ' void deletePackages( pids)'
5761
print ' void pushToQueue(PackageID pid)'
5862
print ' void pullFromQueue(PackageID pid)'
5963
print ' void restartPackage(PackageID pid)'
@@ -63,15 +67,12 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
6367
print ' void stopDownloads( fids)'
6468
print ' void setPackageName(PackageID pid, string name)'
6569
print ' void movePackage(Destination destination, PackageID pid)'
66-
print ' void uploadContainer(string filename, string data)'
6770
print ' void setPriority(PackageID pid, Priority priority)'
6871
print ' void orderPackage(PackageID pid, i16 position)'
6972
print ' void orderFile(FileID fid, i16 position)'
7073
print ' void setPackageData(PackageID pid, data)'
7174
print ' void deleteFinished()'
7275
print ' void restartFailed()'
73-
print ' getPackageOrder(Destination destination)'
74-
print ' getFileOrder(PackageID pid)'
7576
print ' bool isCaptchaWaiting()'
7677
print ' CaptchaTask getCaptchaTask(bool exclusive)'
7778
print ' string getCaptchaTaskStatus(TaskID tid)'
@@ -264,35 +265,23 @@ elif cmd == 'statusDownloads':
264265
sys.exit(1)
265266
pp.pprint(client.statusDownloads())
266267

267-
elif cmd == 'addPackage':
268-
if len(args) != 3:
269-
print 'addPackage requires 3 args'
270-
sys.exit(1)
271-
pp.pprint(client.addPackage(args[0],eval(args[1]),eval(args[2]),))
272-
273268
elif cmd == 'getPackageData':
274269
if len(args) != 1:
275270
print 'getPackageData requires 1 args'
276271
sys.exit(1)
277272
pp.pprint(client.getPackageData(eval(args[0]),))
278273

279-
elif cmd == 'getFileData':
280-
if len(args) != 1:
281-
print 'getFileData requires 1 args'
282-
sys.exit(1)
283-
pp.pprint(client.getFileData(eval(args[0]),))
284-
285-
elif cmd == 'deleteFiles':
274+
elif cmd == 'getPackageInfo':
286275
if len(args) != 1:
287-
print 'deleteFiles requires 1 args'
276+
print 'getPackageInfo requires 1 args'
288277
sys.exit(1)
289-
pp.pprint(client.deleteFiles(eval(args[0]),))
278+
pp.pprint(client.getPackageInfo(eval(args[0]),))
290279

291-
elif cmd == 'deletePackages':
280+
elif cmd == 'getFileData':
292281
if len(args) != 1:
293-
print 'deletePackages requires 1 args'
282+
print 'getFileData requires 1 args'
294283
sys.exit(1)
295-
pp.pprint(client.deletePackages(eval(args[0]),))
284+
pp.pprint(client.getFileData(eval(args[0]),))
296285

297286
elif cmd == 'getQueue':
298287
if len(args) != 0:
@@ -318,12 +307,48 @@ elif cmd == 'getCollectorData':
318307
sys.exit(1)
319308
pp.pprint(client.getCollectorData())
320309

310+
elif cmd == 'getPackageOrder':
311+
if len(args) != 1:
312+
print 'getPackageOrder requires 1 args'
313+
sys.exit(1)
314+
pp.pprint(client.getPackageOrder(eval(args[0]),))
315+
316+
elif cmd == 'getFileOrder':
317+
if len(args) != 1:
318+
print 'getFileOrder requires 1 args'
319+
sys.exit(1)
320+
pp.pprint(client.getFileOrder(eval(args[0]),))
321+
322+
elif cmd == 'addPackage':
323+
if len(args) != 3:
324+
print 'addPackage requires 3 args'
325+
sys.exit(1)
326+
pp.pprint(client.addPackage(args[0],eval(args[1]),eval(args[2]),))
327+
321328
elif cmd == 'addFiles':
322329
if len(args) != 2:
323330
print 'addFiles requires 2 args'
324331
sys.exit(1)
325332
pp.pprint(client.addFiles(eval(args[0]),eval(args[1]),))
326333

334+
elif cmd == 'uploadContainer':
335+
if len(args) != 2:
336+
print 'uploadContainer requires 2 args'
337+
sys.exit(1)
338+
pp.pprint(client.uploadContainer(args[0],args[1],))
339+
340+
elif cmd == 'deleteFiles':
341+
if len(args) != 1:
342+
print 'deleteFiles requires 1 args'
343+
sys.exit(1)
344+
pp.pprint(client.deleteFiles(eval(args[0]),))
345+
346+
elif cmd == 'deletePackages':
347+
if len(args) != 1:
348+
print 'deletePackages requires 1 args'
349+
sys.exit(1)
350+
pp.pprint(client.deletePackages(eval(args[0]),))
351+
327352
elif cmd == 'pushToQueue':
328353
if len(args) != 1:
329354
print 'pushToQueue requires 1 args'
@@ -378,12 +403,6 @@ elif cmd == 'movePackage':
378403
sys.exit(1)
379404
pp.pprint(client.movePackage(eval(args[0]),eval(args[1]),))
380405

381-
elif cmd == 'uploadContainer':
382-
if len(args) != 2:
383-
print 'uploadContainer requires 2 args'
384-
sys.exit(1)
385-
pp.pprint(client.uploadContainer(args[0],args[1],))
386-
387406
elif cmd == 'setPriority':
388407
if len(args) != 2:
389408
print 'setPriority requires 2 args'
@@ -420,18 +439,6 @@ elif cmd == 'restartFailed':
420439
sys.exit(1)
421440
pp.pprint(client.restartFailed())
422441

423-
elif cmd == 'getPackageOrder':
424-
if len(args) != 1:
425-
print 'getPackageOrder requires 1 args'
426-
sys.exit(1)
427-
pp.pprint(client.getPackageOrder(eval(args[0]),))
428-
429-
elif cmd == 'getFileOrder':
430-
if len(args) != 1:
431-
print 'getFileOrder requires 1 args'
432-
sys.exit(1)
433-
pp.pprint(client.getFileOrder(eval(args[0]),))
434-
435442
elif cmd == 'isCaptchaWaiting':
436443
if len(args) != 0:
437444
print 'isCaptchaWaiting requires 0 args'

0 commit comments

Comments
 (0)