MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / execute

Method execute

keepercommander/rsync/command.py:53–212  ·  view source on GitHub ↗
(self, params, **kwargs)

Source from the content-addressed store, hash-verified

51 return rsync_parser
52
53 def execute(self, params, **kwargs):
54 local_path = kwargs.get('local_path')
55 if not isinstance(local_path, str) or not local_path:
56 self.get_parser().print_help()
57 return
58
59 local_path = os.path.expanduser(local_path)
60 local_path = os.path.abspath(local_path)
61 local_path = os.path.join(local_path, '')
62 if os.path.exists(local_path):
63 if not os.path.isdir(local_path):
64 raise CommandError('rsync', f'Local path \"{local_path}\" is expected to be directory')
65 else:
66 os.mkdir(local_path)
67
68 should_save = False
69 rsync_info = None # type: Optional[dict]
70 rsync_info_path = os.path.join(local_path, '.rsync.json')
71 if rsync_info_path and os.path.exists(rsync_info_path):
72 if not os.path.isfile(rsync_info_path):
73 raise CommandError('rsync', f'Path \"{rsync_info_path}\" is expected to be a JSON file')
74 with open(rsync_info_path, 'r') as f:
75 rsync_info = json.load(f)
76 if not isinstance(rsync_info, dict):
77 raise CommandError('rsync', f'Path \"{rsync_info_path}\" is expected to be a JSON object')
78
79 if not rsync_info:
80 if not kwargs.get('force'):
81 answer = user_choice(f'Do you want to setup rsync storage in directory: \"{local_path}\"?', 'yn', 'n')
82 if answer.lower() == 'yes':
83 answer = 'y'
84 if answer.lower() != 'y':
85 return
86 rsync_info = {}
87 should_save = True
88
89 plugin_name = rsync_info.get('plugin')
90 arg_plugin_name = kwargs.get('plugin')
91 if not plugin_name and not arg_plugin_name:
92 raise CommandError('rsync', f'\"--plugin\" parameter is required to setup rsync')
93 elif plugin_name and arg_plugin_name:
94 # TODO warn on plugin override
95 plugin_name = arg_plugin_name
96 elif arg_plugin_name:
97 plugin_name = arg_plugin_name
98
99 try:
100 plugin_module = self.load_plugin(plugin_name)
101 except ModuleNotFoundError as e:
102 raise CommandError('rsync', f'The required module is not installed:\n\tpip install {e.name}')
103
104 if not hasattr(plugin_module, 'RSyncPlugin'):
105 raise CommandError('rsync', f'Invalid RSync Plugin \"{plugin_name}\"')
106 plugin = plugin_module.RSyncPlugin() # type: rsync.RSyncPluginBase
107 if not isinstance(plugin, rsync.RSyncPluginBase):
108 raise CommandError('rsync', f'Invalid RSync Plugin \"{plugin_name}\"')
109
110 if rsync_info.get('plugin') != plugin_name:

Callers

nothing calls this directly

Calls 15

get_parserMethod · 0.95
load_pluginMethod · 0.95
user_choiceFunction · 0.85
warningMethod · 0.80
CommandErrorClass · 0.50
getMethod · 0.45
print_helpMethod · 0.45
loadMethod · 0.45
resolve_single_recordMethod · 0.45
walkMethod · 0.45
connectMethod · 0.45
get_entriesMethod · 0.45

Tested by

no test coverage detected