diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2021-03-10 19:52:41 +0100 |
---|---|---|
committer | Philipp Maier <pmaier@sysmocom.de> | 2021-03-26 22:11:40 +0100 |
commit | 681bc7ba7242e5237afa5ebb6e90c2413dad97c8 (patch) | |
tree | 3e4db2ead4bbaaa67b3d2b5ada0a545c5d3ac574 | |
parent | 1e896f3d8cfbc3c5103a54ec8414f830aee9e5d5 (diff) |
pySim-shell: add option to execute script on startup
Add a commondline option so that the user can supply pySim-shell with a
script file name. This script then runs automatically on startup. (to
avoid ending up at the shell prompt a quit command at the end can be
used to exit after script execution)
Change-Id: I69f5224087023650340fbfee74668e1850345f54
Related: OS#4963
-rwxr-xr-x | pySim-shell.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pySim-shell.py b/pySim-shell.py index e7bb7c0..09749dc 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -49,10 +49,10 @@ from pySim.ts_31_103 import ADF_ISIM class PysimApp(cmd2.Cmd): CUSTOM_CATEGORY = 'pySim Commands' - def __init__(self, card, rs): + def __init__(self, card, rs, script = None): basic_commands = [Iso7816Commands(), UsimCommands()] super().__init__(persistent_history_file='~/.pysim_shell_history', allow_cli_args=False, - use_ipython=True, auto_load_commands=False, command_sets=basic_commands) + use_ipython=True, auto_load_commands=False, command_sets=basic_commands, startup_script=script) self.intro = style('Welcome to pySim-shell!', fg=fg.red) self.default_category = 'pySim-shell built-in commands' self.card = card @@ -212,6 +212,10 @@ def parse_options(): help="Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)", default=None, ) + parser.add_option("--script", dest="script", metavar="PATH", + help="script with shell commands to be executed automatically", + default=None, + ) parser.add_option("-a", "--pin-adm", dest="pin_adm", help="ADM PIN used for provisioning (overwrites default)", @@ -261,6 +265,6 @@ if __name__ == '__main__': rs.mf.add_file(DF_TELECOM()) rs.mf.add_file(DF_GSM()) - app = PysimApp(card, rs) + app = PysimApp(card, rs, opts.script) rs.select('MF', app) app.cmdloop() |