Add support for persistent profile data deletion
This commit is contained in:
parent
d8d54d88d1
commit
2174123e6c
4 changed files with 23 additions and 12 deletions
|
@ -96,6 +96,9 @@ python3 main.py profile enable -i 4
|
|||
|
||||
# Enable (ignore state conflicts and/or potential security issues).
|
||||
python3 main.py profile enable -i 4 -f
|
||||
|
||||
# Enable (delete any existing profile data on beforehand).
|
||||
python3 main.py profile enable -i 4 -p
|
||||
```
|
||||
|
||||
#### Disable Profile
|
||||
|
|
|
@ -34,7 +34,7 @@ class ProfileController:
|
|||
profile_observer.notify('created', profile)
|
||||
|
||||
@staticmethod
|
||||
def enable(profile: Union[SessionProfile, SystemProfile], force: bool = False, profile_observer: ProfileObserver = None, application_version_observer: ApplicationVersionObserver = None, connection_observer: ConnectionObserver = None):
|
||||
def enable(profile: Union[SessionProfile, SystemProfile], force: bool = False, pristine: bool = False, profile_observer: ProfileObserver = None, application_version_observer: ApplicationVersionObserver = None, connection_observer: ConnectionObserver = None):
|
||||
|
||||
from core.controllers.ConnectionController import ConnectionController
|
||||
|
||||
|
@ -45,6 +45,9 @@ class ProfileController:
|
|||
else:
|
||||
ProfileController.disable(profile)
|
||||
|
||||
if pristine:
|
||||
profile.delete_data()
|
||||
|
||||
if profile.is_session_profile():
|
||||
|
||||
application_version = profile.application_version
|
||||
|
@ -114,7 +117,7 @@ class ProfileController:
|
|||
def destroy(profile: Union[SessionProfile, SystemProfile], profile_observer: ProfileObserver = None):
|
||||
|
||||
ProfileController.disable(profile)
|
||||
Profile.delete(profile)
|
||||
profile.delete()
|
||||
|
||||
if profile_observer is not None:
|
||||
profile_observer.notify('destroyed', profile)
|
||||
|
|
|
@ -48,6 +48,14 @@ class BaseProfile:
|
|||
def is_system_profile(self):
|
||||
return type(self).__name__ == 'SystemProfile'
|
||||
|
||||
def delete_data(self):
|
||||
shutil.rmtree(BaseProfile.__get_data_path(self.id))
|
||||
|
||||
def delete(self):
|
||||
|
||||
shutil.rmtree(BaseProfile.__get_config_path(self.id))
|
||||
shutil.rmtree(BaseProfile.__get_data_path(self.id))
|
||||
|
||||
@staticmethod
|
||||
def find_by_id(id: int):
|
||||
|
||||
|
@ -134,12 +142,6 @@ class BaseProfile:
|
|||
text_io_wrapper = open(BaseProfile.__get_config_path(profile.id) + '/config.json', 'w')
|
||||
text_io_wrapper.write(config_file_contents)
|
||||
|
||||
@staticmethod
|
||||
def delete(profile):
|
||||
|
||||
shutil.rmtree(BaseProfile.__get_config_path(profile.id))
|
||||
shutil.rmtree(BaseProfile.__get_data_path(profile.id))
|
||||
|
||||
@staticmethod
|
||||
def __get_config_path(id: int):
|
||||
return Constants.SP_PROFILE_CONFIG_HOME + '/' + str(id)
|
||||
|
|
11
main.py
11
main.py
|
@ -46,6 +46,9 @@ if __name__ == '__main__':
|
|||
profile_observer.subscribe('disabled', lambda event: pprint.pp((event.subject, 'Disabled')) if event.meta.get('explicitly') else None)
|
||||
profile_observer.subscribe('enabled', lambda event: pprint.pp((event.subject, 'Enabled')))
|
||||
|
||||
pristine_parser = argparse.ArgumentParser(add_help=False)
|
||||
pristine_parser.add_argument('--pristine', '-p', action='store_true')
|
||||
|
||||
safe_parser = argparse.ArgumentParser(add_help=False)
|
||||
safe_parser.add_argument('--force', '-f', action='store_true')
|
||||
|
||||
|
@ -83,7 +86,7 @@ if __name__ == '__main__':
|
|||
|
||||
profile_subparsers.add_parser('destroy', parents=[profile_base_parser, safe_parser])
|
||||
|
||||
profile_subparsers.add_parser('enable', parents=[profile_base_parser, safe_parser])
|
||||
profile_subparsers.add_parser('enable', parents=[profile_base_parser, pristine_parser, safe_parser])
|
||||
profile_subparsers.add_parser('disable', parents=[profile_base_parser, safe_parser])
|
||||
|
||||
get_parser = main_subparsers.add_parser('get')
|
||||
|
@ -160,7 +163,7 @@ if __name__ == '__main__':
|
|||
if profile is not None:
|
||||
|
||||
try:
|
||||
ProfileController.enable(profile, arguments.force, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
ProfileController.enable(profile, force=arguments.force, pristine=arguments.pristine, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
|
||||
except (InvalidSubscriptionError, MissingSubscriptionError) as exception:
|
||||
|
||||
|
@ -208,7 +211,7 @@ if __name__ == '__main__':
|
|||
else:
|
||||
raise RuntimeError('The subscription could not be activated. Please try again later.')
|
||||
|
||||
ProfileController.enable(profile, force=arguments.force, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
ProfileController.enable(profile, force=arguments.force, pristine=arguments.pristine, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
|
||||
elif manage_subscription_input == '2':
|
||||
|
||||
|
@ -220,7 +223,7 @@ if __name__ == '__main__':
|
|||
if subscription is not None:
|
||||
|
||||
ProfileController.attach_subscription(profile, subscription)
|
||||
ProfileController.enable(profile, arguments.force, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
ProfileController.enable(profile, force=arguments.force, pristine=arguments.pristine, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer)
|
||||
|
||||
else:
|
||||
|
||||
|
|
Loading…
Reference in a new issue