Esempio n. 1
0
    def set_config(self, section, option, value):
        """
        Set a config option in a section and re-write the tahoe.cfg file

        :param str section: The name of the section in which to set the
            option.

        :param str option: The name of the option to set.

        :param str value: The value of the option.

        :raise UnescapedHashError: If the option holds a fURL and there is a
            ``#`` in the value.
        """
        if option.endswith(".furl") and "#" in value:
            raise UnescapedHashError(section, option, value)

        copied_config = configutil.copy_config(self.config)
        configutil.set_config(copied_config, section, option, value)
        configutil.validate_config(
            self._config_fname,
            copied_config,
            self.valid_config_sections,
        )
        if self.config_path is not None:
            configutil.write_config(self.config_path, copied_config)
        self.config = copied_config
Esempio n. 2
0
    def test_config_utils(self):
        tahoe_cfg = self.create_tahoe_cfg("""\
[node]
nickname = client-0
web.port = adopt-socket:fd=5
[storage]
enabled = false
""")

        # test that at least one option was read correctly
        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "client-0")

        # test that set_config can mutate an existing option
        configutil.set_config(config, "node", "nickname", "Alice!")
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "Alice!")

        # test that set_config can set a new option
        descriptor = "Twas brillig, and the slithy toves Did gyre and gimble in the wabe"
        configutil.set_config(config, "node", "descriptor", descriptor)
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "descriptor"), descriptor)
Esempio n. 3
0
def save_magic_folders(node_directory, folders):
    fileutil.write_atomically(
        os.path.join(node_directory, u"private", u"magic_folders.yaml"),
        yamlutil.safe_dump({u"magic-folders": folders}),
    )

    config = configutil.get_config(os.path.join(node_directory, u"tahoe.cfg"))
    configutil.set_config(config, "magic_folder", "enabled", "True")
    configutil.write_config(os.path.join(node_directory, u"tahoe.cfg"), config)
Esempio n. 4
0
 def created(_):
     config_path = join(node_dir, 'tahoe.cfg')
     config = get_config(config_path)
     set_config(
         config,
         u'node',
         u'log_gatherer.furl',
         flog_gatherer.decode("utf-8"),
     )
     write_config(FilePath(config_path), config)
Esempio n. 5
0
def join(options):
    fields = options.invite_code.split(INVITE_SEPARATOR)
    if len(fields) != 2:
        raise usage.UsageError("Invalid invite code.")
    magic_readonly_cap, dmd_write_cap = fields

    dmd_cap_file = os.path.join(options["node-directory"], u"private",
                                u"magic_folder_dircap")
    collective_readcap_file = os.path.join(options["node-directory"],
                                           u"private", u"collective_dircap")
    magic_folder_db_file = os.path.join(options["node-directory"], u"private",
                                        u"magicfolderdb.sqlite")

    if os.path.exists(dmd_cap_file) or os.path.exists(
            collective_readcap_file) or os.path.exists(magic_folder_db_file):
        print >> options.stderr, (
            "\nThis client has already joined a magic folder."
            "\nUse the 'tahoe magic-folder leave' command first.\n")
        return 1

    fileutil.write(dmd_cap_file, dmd_write_cap)
    fileutil.write(collective_readcap_file, magic_readonly_cap)

    config = configutil.get_config(
        os.path.join(options["node-directory"], u"tahoe.cfg"))
    configutil.set_config(config, "magic_folder", "enabled", "True")
    configutil.set_config(config, "magic_folder", "local.directory",
                          options.local_dir.encode('utf-8'))
    configutil.set_config(config, "magic_folder", "poll_interval",
                          options.get("poll-interval", "60"))
    configutil.write_config(
        os.path.join(options["node-directory"], u"tahoe.cfg"), config)
    return 0
Esempio n. 6
0
    def read_config(self):
        self.error_about_old_config_files()
        self.config = ConfigParser.SafeConfigParser()

        tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg")
        try:
            self.config = configutil.get_config(tahoe_cfg)
        except EnvironmentError:
            if os.path.exists(tahoe_cfg):
                raise

        cfg_tubport = self.get_config("node", "tub.port", "")
        if not cfg_tubport:
            # For 'tub.port', tahoe.cfg overrides the individual file on
            # disk. So only read self._portnumfile if tahoe.cfg doesn't
            # provide a value.
            try:
                file_tubport = fileutil.read(self._portnumfile).strip()
                configutil.set_config(self.config, "node", "tub.port", file_tubport)
            except EnvironmentError:
                if os.path.exists(self._portnumfile):
                    raise
    def test_config_utils(self):
        self.basedir = "cli/ConfigUtilTests/test-config-utils"
        self.set_up_grid(oneshare=True)
        tahoe_cfg = os.path.join(self.get_clientdir(i=0), "tahoe.cfg")

        # test that at least one option was read correctly
        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "client-0")

        # test that set_config can mutate an existing option
        configutil.set_config(config, "node", "nickname", "Alice!")
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "Alice!")

        # test that set_config can set a new option
        descriptor = "Twas brillig, and the slithy toves Did gyre and gimble in the wabe"
        configutil.set_config(config, "node", "descriptor", descriptor)
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "descriptor"), descriptor)
Esempio n. 8
0
def join(options):
    fields = options.invite_code.split(INVITE_SEPARATOR)
    if len(fields) != 2:
        raise usage.UsageError("Invalid invite code.")
    magic_readonly_cap, dmd_write_cap = fields

    dmd_cap_file = os.path.join(options["node-directory"], u"private", u"magic_folder_dircap")
    collective_readcap_file = os.path.join(options["node-directory"], u"private", u"collective_dircap")
    magic_folder_db_file = os.path.join(options["node-directory"], u"private", u"magicfolderdb.sqlite")

    if os.path.exists(dmd_cap_file) or os.path.exists(collective_readcap_file) or os.path.exists(magic_folder_db_file):
        print >>options.stderr, ("\nThis client has already joined a magic folder."
                                 "\nUse the 'tahoe magic-folder leave' command first.\n")
        return 1

    fileutil.write(dmd_cap_file, dmd_write_cap)
    fileutil.write(collective_readcap_file, magic_readonly_cap)

    config = configutil.get_config(os.path.join(options["node-directory"], u"tahoe.cfg"))
    configutil.set_config(config, "magic_folder", "enabled", "True")
    configutil.set_config(config, "magic_folder", "local.directory", options.local_dir.encode('utf-8'))
    configutil.write_config(os.path.join(options["node-directory"], u"tahoe.cfg"), config)
    return 0
Esempio n. 9
0
    def read_config(self):
        self.error_about_old_config_files()
        self.config = ConfigParser.SafeConfigParser()

        tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg")
        try:
            self.config = configutil.get_config(tahoe_cfg)
        except EnvironmentError:
            if os.path.exists(tahoe_cfg):
                raise

        cfg_tubport = self.get_config("node", "tub.port", "")
        if not cfg_tubport:
            # For 'tub.port', tahoe.cfg overrides the individual file on
            # disk. So only read self._portnumfile if tahoe.cfg doesn't
            # provide a value.
            try:
                file_tubport = fileutil.read(self._portnumfile).strip()
                configutil.set_config(self.config, "node", "tub.port",
                                      file_tubport)
            except EnvironmentError:
                if os.path.exists(self._portnumfile):
                    raise
    def test_config_utils(self):
        self.basedir = "cli/ConfigUtilTests/test-config-utils"
        self.set_up_grid()
        tahoe_cfg = os.path.join(self.get_clientdir(i=0), "tahoe.cfg")

        # test that at least one option was read correctly
        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "client-0")

        # test that set_config can mutate an existing option
        configutil.set_config(config, "node", "nickname", "Alice!")
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "nickname"), "Alice!")

        # test that set_config can set a new option
        descriptor = "Twas brillig, and the slithy toves Did gyre and gimble in the wabe"
        configutil.set_config(config, "node", "descriptor", descriptor)
        configutil.write_config(tahoe_cfg, config)

        config = configutil.get_config(tahoe_cfg)
        self.failUnlessEqual(config.get("node", "descriptor"), descriptor)
Esempio n. 11
0
 def created(_):
     config_path = join(node_dir, 'tahoe.cfg')
     config = get_config(config_path)
     set_config(config, 'node', 'log_gatherer.furl', flog_gatherer)
     write_config(config_path, config)
Esempio n. 12
0
def _create_node(reactor,
                 tahoe_venv,
                 request,
                 base_dir,
                 introducer_furl,
                 flog_gatherer,
                 name,
                 web_port,
                 storage=True,
                 magic_text=None,
                 needed=2,
                 happy=3,
                 total=4):
    """
    Helper to create a single node, run it and return the instance
    spawnProcess returned (ITransport)
    """
    node_dir = join(base_dir, name)
    if web_port is None:
        web_port = ''
    if not exists(node_dir):
        print("creating", node_dir)
        mkdir(node_dir)
        done_proto = _ProcessExitedProtocol()
        args = [
            'create-node',
            '--nickname',
            name,
            '--introducer',
            introducer_furl,
            '--hostname',
            'localhost',
            '--listen',
            'tcp',
            '--webport',
            web_port,
            '--shares-needed',
            "{}".format(needed),
            '--shares-happy',
            "{}".format(happy),
            '--shares-total',
            "{}".format(total),
            '--helper',
        ]
        if not storage:
            args.append('--no-storage')
        args.append(node_dir)

        _tahoe_runner(done_proto, reactor, tahoe_venv, request, args)
        yield done_proto.done

        if flog_gatherer:
            config_path = join(node_dir, 'tahoe.cfg')
            config = get_config(config_path)
            set_config(config, 'node', 'log_gatherer.furl', flog_gatherer)
            write_config(config_path, config)

    magic_text = "client running"
    action_fields = {
        "action_type": u"integration:tahoe-node:service",
        "node": name,
    }
    process = yield run_tahoe_service(reactor, request, action_fields,
                                      magic_text, tahoe_venv, node_dir)
    returnValue(process)
Esempio n. 13
0
 def created(_):
     config_path = join(node_dir, 'tahoe.cfg')
     config = get_config(config_path)
     set_config(config, 'node', 'log_gatherer.furl', flog_gatherer)
     write_config(config_path, config)