mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 23:02:25 +00:00
Add magic-folder indicator to main welcome page
This doesn't reveal very much information, but does tell you if magic-folder is currently working and if not it will indicate when the last attempt to do a remote scan was.
This commit is contained in:
parent
a6920d9799
commit
8a33fc612a
@ -124,6 +124,7 @@ class Client(node.Node, pollmixin.PollMixin):
|
||||
node.Node.__init__(self, basedir)
|
||||
# All tub.registerReference must happen *after* we upcall, since
|
||||
# that's what does tub.setLocation()
|
||||
self._magic_folder = None
|
||||
self.started_timestamp = time.time()
|
||||
self.logSource="Client"
|
||||
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
|
||||
|
@ -2,6 +2,7 @@
|
||||
import sys, os
|
||||
import os.path
|
||||
from collections import deque
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
from twisted.internet import defer, reactor, task
|
||||
@ -22,6 +23,7 @@ from allmydata.util.progress import PercentProgress
|
||||
from allmydata.util.encodingutil import listdir_filepath, to_filepath, \
|
||||
extend_filepath, unicode_from_filepath, unicode_segments_from, \
|
||||
quote_filepath, quote_local_unicode_path, quote_output, FilenameEncodingError
|
||||
from allmydata.util.time_format import format_time
|
||||
from allmydata.immutable.upload import FileName, Data
|
||||
from allmydata import magicfolderdb, magicpath
|
||||
|
||||
@ -80,7 +82,18 @@ class MagicFolder(service.MultiService):
|
||||
|
||||
self.uploader = Uploader(client, local_path_u, db, upload_dirnode, pending_delay, clock)
|
||||
self.downloader = Downloader(client, local_path_u, db, collective_dirnode,
|
||||
upload_dirnode.get_readonly_uri(), clock, self.uploader.is_pending, umask)
|
||||
upload_dirnode.get_readonly_uri(), clock, self.uploader.is_pending, umask,
|
||||
self.set_public_status)
|
||||
self._public_status = (False, ['Magic folder has not yet started'])
|
||||
|
||||
def get_public_status(self):
|
||||
"""
|
||||
For the web UI, basically.
|
||||
"""
|
||||
return self._public_status
|
||||
|
||||
def set_public_status(self, status, *messages):
|
||||
self._public_status = (status, messages)
|
||||
|
||||
def startService(self):
|
||||
# TODO: why is this being called more than once?
|
||||
@ -717,7 +730,8 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
scan_interval = 3
|
||||
|
||||
def __init__(self, client, local_path_u, db, collective_dirnode,
|
||||
upload_readonly_dircap, clock, is_upload_pending, umask):
|
||||
upload_readonly_dircap, clock, is_upload_pending, umask,
|
||||
status_reporter):
|
||||
QueueMixin.__init__(self, client, local_path_u, db, 'downloader', clock, delay=self.scan_interval)
|
||||
|
||||
if not IDirectoryNode.providedBy(collective_dirnode):
|
||||
@ -731,6 +745,7 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
self._upload_readonly_dircap = upload_readonly_dircap
|
||||
self._is_upload_pending = is_upload_pending
|
||||
self._umask = umask
|
||||
self._status_reporter = status_reporter
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def start_downloading(self):
|
||||
@ -748,6 +763,11 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
last_try = format_time(datetime.fromtimestamp(self._clock.seconds()).timetuple())
|
||||
self._status_reporter(
|
||||
False, "Initial scan has failed",
|
||||
"Last tried at %s" % last_try,
|
||||
)
|
||||
twlog.msg("Magic Folder failed initial scan: %s" % (e,))
|
||||
yield task.deferLater(self._clock, self.scan_interval, lambda: None)
|
||||
|
||||
@ -837,6 +857,8 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
scan_batch[relpath_u] += [(file_node, metadata)]
|
||||
else:
|
||||
scan_batch[relpath_u] = [(file_node, metadata)]
|
||||
last_try = format_time(datetime.fromtimestamp(self._clock.seconds()).timetuple())
|
||||
self._status_reporter(True, 'Magic folder is working', 'Last attempt: %s' % last_try)
|
||||
|
||||
d.addCallback(scan_listing)
|
||||
d.addBoth(self._logcb, "end of _scan_remote_dmd")
|
||||
@ -892,9 +914,15 @@ class Downloader(QueueMixin, WriteFileMixin):
|
||||
x = None
|
||||
try:
|
||||
x = yield self._scan(None)
|
||||
self._status_reporter(True, 'Magic folder is working')
|
||||
except Exception as e:
|
||||
twlog.msg("Remote scan failed: %s" % (e,))
|
||||
self._log("_scan failed: %s" % (repr(e),))
|
||||
last_try = format_time(datetime.fromtimestamp(self._clock.seconds()).timetuple())
|
||||
self._status_reporter(
|
||||
False, 'Remote scan has failed: %s' % str(e),
|
||||
'Last attempted at %s' % last_try,
|
||||
)
|
||||
defer.returnValue(x)
|
||||
|
||||
def _scan(self, ign):
|
||||
|
@ -224,6 +224,7 @@ class FakeClient(Client):
|
||||
# don't upcall to Client.__init__, since we only want to initialize a
|
||||
# minimal subset
|
||||
service.MultiService.__init__(self)
|
||||
self._magic_folder = None
|
||||
self.all_contents = {}
|
||||
self.nodeid = "fake_nodeid"
|
||||
self.nickname = u"fake_nickname \u263A"
|
||||
|
@ -186,6 +186,25 @@ class Root(rend.Page):
|
||||
def data_my_nickname(self, ctx, data):
|
||||
return self.client.nickname
|
||||
|
||||
def render_magic_folder(self, ctx, data):
|
||||
if self.client._magic_folder is None:
|
||||
return T.p()
|
||||
|
||||
(ok, messages) = self.client._magic_folder.get_public_status()
|
||||
|
||||
if ok:
|
||||
ctx.fillSlots("magic_folder_status", "yes")
|
||||
ctx.fillSlots("magic_folder_status_alt", "working")
|
||||
else:
|
||||
ctx.fillSlots("magic_folder_status", "no")
|
||||
ctx.fillSlots("magic_folder_status_alt", "not working")
|
||||
|
||||
status = T.ul()
|
||||
for msg in messages:
|
||||
status[T.li[str(msg)]]
|
||||
|
||||
return ctx.tag[status]
|
||||
|
||||
def render_services(self, ctx, data):
|
||||
ul = T.ul()
|
||||
try:
|
||||
|
@ -159,6 +159,14 @@
|
||||
</div><!--/span-->
|
||||
</div><!--/row-->
|
||||
</div>
|
||||
|
||||
<div n:render="magic_folder" class="row-fluid">
|
||||
<h2>
|
||||
<div class="status-indicator"><img><n:attr name="src">img/connected-<n:slot name="magic_folder_status" />.png</n:attr><n:attr name="alt"><n:slot name="magic_folder_status_alt" /></n:attr></img></div>
|
||||
Magic Folder
|
||||
</h2>
|
||||
</div><!--/row-->
|
||||
|
||||
<div class="row-fluid">
|
||||
<h2>
|
||||
Connected to <span n:render="string" n:data="connected_storage_servers" />
|
||||
|
Loading…
Reference in New Issue
Block a user