mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 11:16:24 +00:00
Move the complicated MagicFolder constructor
All that complexity can be part of MagicFolder itself.
This commit is contained in:
parent
ac6269dd2d
commit
8d104dab1c
@ -593,23 +593,7 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
|
||||
for (name, mf_config) in magic_folders.items():
|
||||
self.log("Starting magic_folder '{}'".format(name))
|
||||
db_filename = os.path.join(self.basedir, "private", "magicfolder_{}.sqlite".format(name))
|
||||
local_dir_config = mf_config['directory']
|
||||
try:
|
||||
poll_interval = int(mf_config["poll_interval"])
|
||||
except ValueError:
|
||||
raise ValueError("'poll_interval' option must be an int")
|
||||
|
||||
s = magic_folder.MagicFolder(
|
||||
client=self,
|
||||
upload_dircap=mf_config["upload_dircap"],
|
||||
collective_dircap=mf_config["collective_dircap"],
|
||||
local_path_u=abspath_expanduser_unicode(local_dir_config, base=self.basedir),
|
||||
dbfile=abspath_expanduser_unicode(db_filename),
|
||||
umask=mf_config["umask"],
|
||||
name=name,
|
||||
downloader_delay=poll_interval,
|
||||
)
|
||||
s = magic_folder.MagicFolder.from_config(self.basedir, mf_config)
|
||||
self._magic_folders[name] = s
|
||||
s.setServiceParent(self)
|
||||
s.startService()
|
||||
|
@ -244,6 +244,43 @@ def save_magic_folders(node_directory, folders):
|
||||
|
||||
class MagicFolder(service.MultiService):
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, client_node, config):
|
||||
"""
|
||||
Create a ``MagicFolder`` from a client node and magic-folder
|
||||
configuration.
|
||||
|
||||
:param _Client client_node: The client node the magic-folder is
|
||||
attached to.
|
||||
|
||||
:param dict config: Magic-folder configuration like that in the list
|
||||
returned by ``load_magic_folders``.
|
||||
"""
|
||||
db_filename = os.path.join(
|
||||
client_node.basedir,
|
||||
"private",
|
||||
"magicfolder_{}.sqlite".format(name),
|
||||
)
|
||||
local_dir_config = config['directory']
|
||||
try:
|
||||
poll_interval = int(config["poll_interval"])
|
||||
except ValueError:
|
||||
raise ValueError("'poll_interval' option must be an int")
|
||||
|
||||
return cls(
|
||||
client=client_node,
|
||||
upload_dircap=config["upload_dircap"],
|
||||
collective_dircap=config["collective_dircap"],
|
||||
local_path_u=abspath_expanduser_unicode(
|
||||
local_dir_config,
|
||||
base=client_node.basedir,
|
||||
),
|
||||
dbfile=abspath_expanduser_unicode(db_filename),
|
||||
umask=config["umask"],
|
||||
name=name,
|
||||
downloader_delay=poll_interval,
|
||||
)
|
||||
|
||||
def __init__(self, client, upload_dircap, collective_dircap, local_path_u, dbfile, umask,
|
||||
name, uploader_delay=1.0, clock=None, downloader_delay=60):
|
||||
precondition_abspath(local_path_u)
|
||||
|
Loading…
Reference in New Issue
Block a user