示例#1
0
def _upgrade_magic_folder_config(basedir):
    """
    Helper that upgrades from single-magic-folder-only configs to
    multiple magic-folder configuration style (in YAML)
    """
    config_fname = os.path.join(basedir, "tahoe.cfg")
    config = configutil.get_config(config_fname)

    collective_fname = os.path.join(basedir, "private", "collective_dircap")
    upload_fname = os.path.join(basedir, "private", "magic_folder_dircap")
    magic_folders = {
        u"default": {
            u"directory": config.get("magic_folder", "local.directory").decode("utf-8"),
            u"collective_dircap": fileutil.read(collective_fname),
            u"upload_dircap": fileutil.read(upload_fname),
            u"poll_interval": int(config.get("magic_folder", "poll_interval")),
        },
    }
    fileutil.move_into_place(
        source=os.path.join(basedir, "private", "magicfolderdb.sqlite"),
        dest=os.path.join(basedir, "private", "magicfolder_default.sqlite"),
    )
    save_magic_folders(basedir, magic_folders)
    config.remove_option("magic_folder", "local.directory")
    config.remove_option("magic_folder", "poll_interval")
    configutil.write_config(os.path.join(basedir, 'tahoe.cfg'), config)
    fileutil.remove_if_possible(collective_fname)
    fileutil.remove_if_possible(upload_fname)
示例#2
0
 def save(self, data):
     """
     Serialize the given data as JSON into the state-path
     :returns: None
     """
     tmpfile = self._path.siblingExtension(".tmp")
     _dump_json_to_file(data, tmpfile)
     fileutil.move_into_place(tmpfile.path, self._path.path)
     return None
示例#3
0
 def save_state(self):
     lcpi = self.last_complete_prefix_index
     if lcpi == -1:
         last_complete_prefix = None
     else:
         last_complete_prefix = self.prefixes[lcpi]
     self.state["last-complete-prefix"] = last_complete_prefix
     tmpfile = self.statefile + ".tmp"
     with open(tmpfile, "wb") as f:
         pickle.dump(self.state, f)
     fileutil.move_into_place(tmpfile, self.statefile)
示例#4
0
 def save_state(self):
     lcpi = self.last_complete_prefix_index
     if lcpi == -1:
         last_complete_prefix = None
     else:
         last_complete_prefix = self.prefixes[lcpi]
     self.state["last-complete-prefix"] = last_complete_prefix
     tmpfile = self.statefile + ".tmp"
     f = open(tmpfile, "wb")
     pickle.dump(self.state, f)
     f.close()
     fileutil.move_into_place(tmpfile, self.statefile)
示例#5
0
 def save_state(self):
     lcpi = self.last_complete_prefix_index
     if lcpi == -1:
         last_complete_prefix = None
     else:
         last_complete_prefix = self.prefixes[lcpi]
     self.state["last-complete-prefix"] = last_complete_prefix
     tmpfile = self.statefile + ".tmp"
     with open(tmpfile, "wb") as f:
         # Newer protocols won't work in Python 2; when it is dropped,
         # protocol v4 can be used (added in Python 3.4).
         pickle.dump(self.state, f, protocol=2)
     fileutil.move_into_place(tmpfile, self.statefile)
示例#6
0
def add_line_to_aliasfile(aliasfile, alias, cap):
    # we use os.path.exists, rather than catching EnvironmentError, to avoid
    # clobbering the valuable alias file in case of spurious or transient
    # filesystem errors.
    if os.path.exists(aliasfile):
        with codecs.open(aliasfile, "r", "utf-8") as f:
            aliases = f.read()
        if not aliases.endswith("\n"):
            aliases += "\n"
    else:
        aliases = ""
    aliases += "%s: %s\n" % (alias, cap)
    with codecs.open(aliasfile + ".tmp", "w", "utf-8") as f:
        f.write(aliases)
    fileutil.move_into_place(aliasfile + ".tmp", aliasfile)
示例#7
0
def add_line_to_aliasfile(aliasfile, alias, cap):
    # we use os.path.exists, rather than catching EnvironmentError, to avoid
    # clobbering the valuable alias file in case of spurious or transient
    # filesystem errors.
    if os.path.exists(aliasfile):
        f = codecs.open(aliasfile, "r", "utf-8")
        aliases = f.read()
        f.close()
        if not aliases.endswith("\n"):
            aliases += "\n"
    else:
        aliases = ""
    aliases += "%s: %s\n" % (alias, cap)
    f = codecs.open(aliasfile+".tmp", "w", "utf-8")
    f.write(aliases)
    f.close()
    move_into_place(aliasfile+".tmp", aliasfile)