Exemple #1
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")
    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
Exemple #3
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)
Exemple #4
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)
Exemple #5
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) )
Exemple #6
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)
Exemple #7
0
 def cmd_list(self):
     """List remote data"""
     parser = argparse.ArgumentParser(description='List remote data')
     parser.add_argument('path', type=str, default=str(pl.Path.home))
     args = parser.parse_args(sys.argv[2:])
     Log.Debug(f"Ask list for {args.path}")
     ret = self.__backend.listRessource(args.path)
     for x in ret:
         print(x)
    def removeRessource(self, path: str, on_remote=False):
        p = fullPath(path)
        if on_remote and self.__client.exists(p):
            self.__client.remove(p)

        if str(p) not in self.__config.data_to_save:
            Log.Error(
                "You try to delete file which is not in the webdav_backup registry"
            )
            return
        self.__config.data_to_save.remove(str(p))
        self.__config.save()
Exemple #9
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)
Exemple #10
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")