Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./.././../../../../../bin/ai-wizard
Real path: /usr/bin/ai-wizard
Zurück
#!/usr/bin/python3.7 -Es import solaris.no_site_packages # # Copyright (c) 2013, 2023, Oracle and/or its affiliates. # """ ai-wizard A utility for launching a web browser and starting the AI Manifest Wizard in it. Uses xdg-open or calls firefox directly. """ import gettext from optparse import OptionParser import os import sys import traceback from solaris_install import Popen, run from solaris_install.ai_wizard import _ from solaris_install.ai.server import Server # Executables accessed by ai-wizard XDG_OPEN = '/usr/bin/xdg-open' FIREFOX = '/usr/bin/firefox' UNAME = '/usr/bin/uname' SVCPROP = '/usr/bin/svcprop' # messages to STDERR WIZARD_ERR_OPT_ARGS = _("Error: Invalid options and arguments") WIZARD_ERR_RUN_CMD = _("Error while running a command:\n%s") WIZARD_ERR_UNAVAIL_CMD = _("Error: %s command not available") WIZARD_ERR_NO_HOSTNAME = _("Error: Cannot determine system's host name") WIZARD_ERR_NO_PORT = _("Error: Cannot determine wizard's port number") WIZARD_WARN_NO_DOMAIN = _("Warning: Cannot determine system's domain name") WIZARD_ERR_POINT = _("Error: Unable to automatically launch a browser, " "please point your desktop browser at the URL:\n\n" "\t%s\n\nto access the AI Wizard.") WIZARD_ERR_INSTALLADM_MISSING = _("Error: Required installadm package not " "installed") # messages to STDOUT WIZARD_MSG_CMD = _("Running command '%s'") # Only one server needed for invocation AISERVER = Server() def print_err(string): '''Print message to stderr.''' print(string, file=sys.stderr) def print_out(string): '''Print message to stdeout.''' print(string, file=sys.stdout) def usage(): '''Defines parameters and options of the command ai-wizard.''' print(_("Usage:"), file=sys.stderr) print(_("\tai-wizard [-p port]"), file=sys.stderr) sys.exit(1) def main(): '''main function.''' gettext.install('solaris_cmd_ai-wizard', '/usr/lib/locale') return run_wizard(sys.argv[1:]) def get_options(cmd_options=None): '''parse the command line options''' description = _("Start the Oracle Automated Install Manifest Wizard") parser_usage = _("%prog [-p port]") parser = OptionParser(usage=parser_usage, description=description) parser.add_option("-p", "--port", dest="port", default=AISERVER.http_port, type='int', help=_("port number for the AI Webserver")) options, args = parser.parse_args(cmd_options) if args: parser.error(_("Unexpected arguments(s): %s") % args) return options def run_wizard(opts): '''Start the wizard''' try: options = get_options(opts) except ValueError: print_err(WIZARD_ERR_INSTALLADM_MISSING) return 1 # Build up the command to execute and run it url = get_url(options.port) if url is None: return 1 cmd = get_command(url) if cmd is None: print_err(WIZARD_ERR_POINT % url) return 1 print_out(WIZARD_MSG_CMD % (" ".join(cmd))) proc = run(cmd, check_result=Popen.ANY) if proc.returncode != 0: print_err(WIZARD_ERR_RUN_CMD % (cmd)) print_err(proc.stderr) print_err(WIZARD_ERR_POINT % url) return 1 return 0 def get_url(port): '''Build the URL for the AI webserver runing on this system.''' schema = 'http' server_ip = get_ip() if server_ip is None: return None return "%s://%s:%d" % (schema, server_ip, port) def get_ip(): '''Get the first valid IP that AI Webserver is listening on.''' networks = AISERVER.active_networks if networks: return next(iter(networks)) else: return None def get_command(url): """Get the command to start the Wizard. One of: - 'xdg-open <url>' if 'xdg-open' command available this command works best as it takes into account local vs remote connection, etc - or 'firefox <url>' if 'firefox' command available (this automatically adds the "-remote OpenURL()" params as requried) - or None Returns: - a list containing command and params, suitable for passing to run() - None """ if check_executable(XDG_OPEN): return [XDG_OPEN, url] # Not fatal - print a warning and try using firefox direcly instead print_err(WIZARD_ERR_UNAVAIL_CMD % (XDG_OPEN)) if check_executable(FIREFOX): return [FIREFOX, url] print_err(WIZARD_ERR_UNAVAIL_CMD % (FIREFOX)) return None def check_executable(executable): '''Check if given path exists and is executable.''' return os.path.isfile(executable) and os.access(executable, os.X_OK) if __name__ == "__main__": try: RC = main() except SystemExit as err: raise err except Exception: traceback.print_exc() sys.exit(99) sys.exit(RC)