I have a multiple functions that basically trigger a shell and run some commands . They all share similar shell setup code blocks .
What is a pythonic way to abstract repetitive shell setup code in the following example ?
My proposed solution was to use a setup decorator , are there other efficient options ?
'''
def status():
shell = setup_shell()
with shell.run_shell():
wait_shell_timeout(shell)
shell.initial_setup()
shell.get_stuff()
shell.status()
def restore(module_name):
shell = setup_shell()
with shell.run_shell():
wait_shell_timeout(shell)
shell.initial_setup()
shell.get_stuff()
shell.restore(module_name)
def update(module_name):
shell = setup_shell()
with shell.run_shell():
wait_shell_timeout(shell)
shell.initial_setup()
shell.get_stuff()
shell.update(module_name)
'''
Aucun commentaire:
Enregistrer un commentaire