tahoe-lafs/src/allmydata/web/magic_folder.py

47 lines
1.4 KiB
Python
Raw Normal View History

import simplejson
2016-06-21 21:47:24 +00:00
from allmydata.web.common import TokenOnlyWebApi
2016-05-23 20:48:07 +00:00
class MagicFolderWebApi(TokenOnlyWebApi):
"""
I provide the web-based API for Magic Folder status etc.
"""
def __init__(self, client):
2016-05-23 20:48:07 +00:00
TokenOnlyWebApi.__init__(self, client)
self.client = client
2016-05-23 20:48:07 +00:00
def post_json(self, req):
req.setHeader("content-type", "application/json")
data = []
try:
for item in self.client._magic_folder.uploader.get_status():
d = dict(
path=item.relpath_u,
status=item.status_history()[-1][0],
kind='upload',
)
for (status, ts) in item.status_history():
d[status + '_at'] = ts
d['percent_done'] = item.progress.progress
data.append(d)
for item in self.client._magic_folder.downloader.get_status():
d = dict(
path=item.relpath_u,
status=item.status_history()[-1][0],
kind='download',
)
for (status, ts) in item.status_history():
d[status + '_at'] = ts
d['percent_done'] = item.progress.progress
data.append(d)
except Exception as e:
data.append({
"error": str(e),
})
return simplejson.dumps(data)