mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipalib.cli: Add filename argument to ipa console
This allows writing simple IPA scripts using the shebang #! /usr/bin/ipa console https://fedorahosted.org/freeipa/ticket/4351 Reviewed-By: Nathaniel McCallum <npmccallum@redhat.com>
This commit is contained in:
parent
58f8ebf491
commit
4d7351ef07
@ -30,6 +30,7 @@ import fcntl
|
||||
import termios
|
||||
import struct
|
||||
import base64
|
||||
import traceback
|
||||
try:
|
||||
#pylint: disable=F0401
|
||||
import default_encoding_utf8
|
||||
@ -875,14 +876,32 @@ class show_mappings(frontend.Command):
|
||||
|
||||
|
||||
class console(frontend.Command):
|
||||
"""Start the IPA interactive Python console."""
|
||||
"""Start the IPA interactive Python console, or run a script.
|
||||
|
||||
An IPA API object is initialized and made available
|
||||
in the `api` global variable.
|
||||
"""
|
||||
|
||||
takes_args = ('filename?',)
|
||||
has_output = tuple()
|
||||
|
||||
def run(self, **options):
|
||||
def run(self, filename=None, **options):
|
||||
local = dict(api=self.api)
|
||||
if filename:
|
||||
try:
|
||||
script = open(filename)
|
||||
except IOError as e:
|
||||
exit("%s: %s" % (e.filename, e.strerror))
|
||||
try:
|
||||
with script:
|
||||
exec(script, globals(), local)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
else:
|
||||
code.interact(
|
||||
'(Custom IPA interactive Python console)',
|
||||
local=dict(api=self.api)
|
||||
local=local
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user