mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Decode script arguments using file system encoding
This mimics Python 3's behavior, where sys.argv is automatically decoded using file system encoding, as returned by sys.getfilesystemencoding(). This includes reimplementation of os.fsdecode() from Python 3. Reviewed-By: Petr Viktorin <pviktori@redhat.com>
This commit is contained in:
@@ -63,7 +63,7 @@ if len(args) != 1:
|
|||||||
# LSB status code 2: invalid or excess argument(s)
|
# LSB status code 2: invalid or excess argument(s)
|
||||||
raise ScriptError("You must specify trusted domain name", 2)
|
raise ScriptError("You must specify trusted domain name", 2)
|
||||||
|
|
||||||
trusted_domain = unicode(args[0].lower())
|
trusted_domain = ipautil.fsdecode(args[0]).lower()
|
||||||
|
|
||||||
env = Env()
|
env = Env()
|
||||||
env._bootstrap(context='server', debug=options.debug, log=None)
|
env._bootstrap(context='server', debug=options.debug, log=None)
|
||||||
|
|||||||
@@ -707,7 +707,7 @@ def del_master_managed(realm, hostname, options):
|
|||||||
Removing of master in managed_topology
|
Removing of master in managed_topology
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hostname_u = unicode(hostname)
|
hostname_u = ipautil.fsdecode(hostname)
|
||||||
if hostname == options.host:
|
if hostname == options.host:
|
||||||
print("Can't remove itself: %s" % (options.host))
|
print("Can't remove itself: %s" % (options.host))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ def main():
|
|||||||
# Use the RPC directly so older servers are supported
|
# Use the RPC directly so older servers are supported
|
||||||
result = api.Backend.rpcclient.forward(
|
result = api.Backend.rpcclient.forward(
|
||||||
'automountlocation_show',
|
'automountlocation_show',
|
||||||
unicode(options.location),
|
ipautil.fsdecode(options.location),
|
||||||
version=u'2.0',
|
version=u'2.0',
|
||||||
)
|
)
|
||||||
except errors.VersionError as e:
|
except errors.VersionError as e:
|
||||||
|
|||||||
@@ -1811,7 +1811,7 @@ def update_ssh_keys(server, hostname, ssh_dir, create_sshfp):
|
|||||||
# Use the RPC directly so older servers are supported
|
# Use the RPC directly so older servers are supported
|
||||||
api.Backend.rpcclient.forward(
|
api.Backend.rpcclient.forward(
|
||||||
'host_mod',
|
'host_mod',
|
||||||
unicode(hostname),
|
ipautil.fsdecode(hostname),
|
||||||
ipasshpubkey=[pk.openssh() for pk in pubkeys],
|
ipasshpubkey=[pk.openssh() for pk in pubkeys],
|
||||||
updatedns=False,
|
updatedns=False,
|
||||||
version=u'2.26', # this version adds support for SSH public keys
|
version=u'2.26', # this version adds support for SSH public keys
|
||||||
|
|||||||
@@ -1352,3 +1352,22 @@ def private_ccache(path=None):
|
|||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
|
|
||||||
|
if six.PY2:
|
||||||
|
def fsdecode(value):
|
||||||
|
"""
|
||||||
|
Decode argument using the file system encoding, as returned by
|
||||||
|
`sys.getfilesystemencoding()`.
|
||||||
|
"""
|
||||||
|
if isinstance(value, six.binary_type):
|
||||||
|
return value.decode(sys.getfilesystemencoding())
|
||||||
|
elif isinstance(value, six.text_type):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
raise TypeError("expect {0} or {1}, not {2}".format(
|
||||||
|
six.binary_type.__name__,
|
||||||
|
six.text_type.__name__,
|
||||||
|
type(value).__name__))
|
||||||
|
else:
|
||||||
|
fsdecode = os.fsdecode #pylint: disable=no-member
|
||||||
|
|||||||
Reference in New Issue
Block a user