mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
Fix ipa console filename
THe ipa console command takes an optional filename argument. The filename argument was broken, because the implementation passed a file object to exec() instead of a string or compiled object. ipa console now uses compile() to compile the code with print_function __future__ feature. Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
parent
5affc9b982
commit
87904b8f6b
@ -992,12 +992,18 @@ class console(frontend.Command):
|
||||
)
|
||||
if filename:
|
||||
try:
|
||||
script = open(filename)
|
||||
with open(filename) as f:
|
||||
source = f.read()
|
||||
except IOError as e:
|
||||
sys.exit("%s: %s" % (e.filename, e.strerror))
|
||||
try:
|
||||
with script:
|
||||
exec(script, globals(), local)
|
||||
compiled = compile(
|
||||
source,
|
||||
filename,
|
||||
'exec',
|
||||
flags=print_function.compiler_flag
|
||||
)
|
||||
exec(compiled, globals(), local)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
@ -164,3 +164,19 @@ class TestIPACommand(IntegrationTest):
|
||||
assert result.returncode == 0
|
||||
assert "SELinux user map order: {}".format(
|
||||
maporder) in result.stdout_text
|
||||
|
||||
def test_ipa_console(self):
|
||||
result = self.master.run_command(
|
||||
["ipa", "console"],
|
||||
stdin_text="api.env"
|
||||
)
|
||||
assert "ipalib.config.Env" in result.stdout_text
|
||||
|
||||
filename = tasks.upload_temp_contents(
|
||||
self.master,
|
||||
"print(api.env)\n"
|
||||
)
|
||||
result = self.master.run_command(
|
||||
["ipa", "console", filename],
|
||||
)
|
||||
assert "ipalib.config.Env" in result.stdout_text
|
||||
|
Loading…
Reference in New Issue
Block a user