#!/usr/bin/python3 # -*- coding: utf-8 -*- app_svnid = '$HeadURL$ $LastChangedRevision$' import sys import subprocess # python3's subprocess.Popen() returns a byte sequence, so to append the string '/include' we need to convert # one to the other. sys.path.append() expects a list of strings, not byte sequences. Therefore it makes most # sense to convert subprocess.Popen()'s output to a string or to get it to return a string directly. The latter # can be done by use of 'universal_newlines=True' sys.path.append(subprocess.Popen(["ade-config", "ade_share_prefix"], stdout=subprocess.PIPE, universal_newlines=True).communicate()[0][:-1] + '/include') import ade import os import time # to allow me to test interrupt routines adepyf_defined_errors = { "adepyf_err_misc":{"fmt":"%s"}, } def adepyf(errstack): ########################################################################### # # Set ADE options # ########################################################################### # Register application-specific errors ade.register_error_types(adepyf_defined_errors) ########################################################################## # # Process options # ########################################################################## # Defaults for options # Register options ade.debug(errstack, 10, "adepyf: registering options ...") rc = ade.register_options(errstack, None, None, globals(), "handle_option_%s") if rc != ade.ok: return rc # Register handler functions ade.debug(errstack, 10, "adepyf: registering message handlers ...") rc = ade.set_callbacks(errstack, adepyf_usage_help, adepyf_version, adepyf_paths) if rc != ade.ok: return rc # Process options ade.debug(errstack, 10, "adepyf: processing options ...") rc = ade.process_options(errstack) if rc != ade.ok: return rc ########################################################################## # # Process arguments # ########################################################################## if len(sys.argv) != 1: ade.show_bad_usage(errstack) namespace = { 'errstack':errstack } pythoncode = 'def adepyf_code_wrapper():\n %s\nrc=adepyf_code_wrapper()' % (sys.argv[0]) try: exec(pythoncode, namespace) except: e = sys.exc_info()[1] ade.error(errstack, "adepyf_err_misc", "code failed to run; the error was: " + str(e)) return ade.fail rc = namespace['rc'] if rc == ade.ok: return rc elif rc == ade.fail: ade.error(errstack, "adepyf_err_misc", "code ran but returned failure") return rc else: ade.error(errstack, "adepyf_err_misc", "code ran but returned a non-compliant return code; the return code was: %s" % (rc)) return ade.fail def adepyf_version(errstack): return ade.extract_version(errstack, app_svnid) def adepyf_paths(errstack): return ade.ok, None def adepyf_usage_help(errstack): return ade.ok, "", None ade.main(adepyf)