Exemplo n.º 1
0
    def saveData(self, path: list) -> bool:
        status = True
        new_file = True
        if len(path) == 1 and path[0] == "all":
            path = self.__config.data_to_save
            new_file = False

        for p in path:
            pok = fullPath(p)
            if not self.__client.remoteIsUpToDate(pok):
                self.__client.save(pok)

        ## Add new file in config.data_to_save
        if new_file:
            count = 0
            for p in path:
                pok = fullPath(p)
                if pok not in self.__config.data_to_save:
                    self.__config.data_to_save.append(str(pok))
                    count += 1
            if count > 0:
                self.__config.save()
                Log.Info(f"{count} new ressources added in the remote storage")

        return status
Exemplo n.º 2
0
 def cmd_restore(self):
     """Restore data from the remote server"""
     parser = argparse.ArgumentParser(
         description='Restore data from the remote server')
     parser.add_argument('path', type=str)
     args = parser.parse_args(sys.argv[2:])
     Log.Info(f'Ask to restore {args.path}')
     self.__backend.restoreData(args.path)
Exemplo n.º 3
0
 def cmd_save(self):
     """Save local data to remote server"""
     parser = argparse.ArgumentParser(
         description='Save local data to remote server')
     parser.add_argument('path', type=str, nargs="*", default=['all'])
     args = parser.parse_args(sys.argv[2:])
     Log.Info(f'Ask to save {args.path}')
     self.__backend.saveData(args.path)
Exemplo n.º 4
0
    def save(self, path: pl.Path):

        if not self.exists(path.parent):
            Log.Info(f"The path {path.parent} doesn't exists on the remote storage we create it ")
            self.remote_mkdirp( path.parent )

        remote_path = self.remotePath( path )
        self.__client.upload_async(str(remote_path), str(path) )
Exemplo n.º 5
0
 def cmd_config(self):
     """Modify configuration information"""
     parser = argparse.ArgumentParser(
         description='Restore data from the remote server')
     parser.add_argument('key', type=str)
     parser.add_argument("value", type=str)
     args = parser.parse_args(sys.argv[2:])
     Log.Info(f'Ask to change config {args.key} = {args.value}')
     self.__backend.updateConfig(args.key, args.value)
Exemplo n.º 6
0
    def connect(self, credential: Credential):
        opts = {"webdav_hostname": credential.url, 
        "webdav_login": credential.login,
        "webdav_password": credential.password}

        try:
            self.__client = wclient.Client(opts)
            Log.Info("Connection established with the remote storage")
        except:
            Log.Error("Failed to connet to your webdav storage. Verify your configuration")
Exemplo n.º 7
0
 def cmd_rm(self):
     """ Remove file """
     parser = argparse.ArgumentParser(description='Remove file')
     parser.add_argument(
         "-r",
         "--remote",
         action="store_true",
         help='Remove the backup of this file on the webdav server',
         default=False)
     parser.add_argument('path', type=str)
     args = parser.parse_args(sys.argv[2:])
     Log.Info(f'Ask to remove {args.path}')
     self.__backend.removeRessource(args.path, on_remote=args.remote)
Exemplo n.º 8
0
 def restore(self, path: pl.Path):
     remote_path = self.remotePath( path )
     self.__client.download_sync(str(remote_path), str(path))
     Log.Info(f"The file {path} has been succesfully restored")