def read(args): """read config file""" from configparser import NoSectionError, MissingSectionHeaderError config_file = args.config if not config_file: config_file = constants.path_config try: conf_parser = config_parser() conf_parser.read(config_file) defaults = constants.OrderedDict( conf_parser.items(constants.dflt_section)) except (NoSectionError, MissingSectionHeaderError): if args.config: print('Cannot read config file! Run install script.') defaults = constants.OrderedDict() for opt, val in constants.default_config.items(): if opt not in defaults: defaults[opt] = val if not str(defaults['width_tot']).isdigit(): defaults['width_tot'] = constants.default_config['width_tot'] return defaults
def main(): config = config_parser() config.read("sapnwrfc.cfg") params_connection = config._sections["connection"] idoc_id = 1 try: connection = pyrfc.Connection(**params_connection) while True: choice = initial_screen() if 1 <= choice <= 4: # Create and send a new iDoc idoc = get_idoc_desc(idoc_id) print(" - Created iDoc with idoc_id = {}".format(idoc_id)) idoc_id += 1 if choice < 3: # bgRFC unit = connection.initialize_unit() print(" - (bgRFC) Using unit id = {}".format(unit["id"])) else: # t/qRFC unit = connection.initialize_unit(background=False) print(" - (t/qRFC) Using unit id = {}".format(unit["id"])) if choice == 2: # bgRFC, type 'Q' queue_input = input( "Enter queue names (comma separated): ") queue_names = [q.strip() for q in queue_input.split(",")] connection.fill_and_submit_unit( unit, [("IDOC_INBOUND_ASYNCHRONOUS", idoc)], queue_names=queue_names, ) elif choice == 4: # qRFC queue_input = input("Enter queue name: ") queue = queue_input.strip() connection.fill_and_submit_unit( unit, [("IDOC_INBOUND_ASYNCHRONOUS", idoc)], queue_names=[queue], ) else: connection.fill_and_submit_unit( unit, [("IDOC_INBOUND_ASYNCHRONOUS", idoc)]) print(" - Unit filled and submitted.") connection.confirm_unit(unit) print(" - Unit confirmed and destroyed.") else: print(" Bye...") break connection.close() except CommunicationError: print("Could not connect to server.") raise except LogonError: print("Could not log in. Wrong credentials?") raise except (ABAPApplicationError, ABAPRuntimeError): print("An error occurred.") raise
def get_options(): opts = parse_cl(argv) cparse = config_parser(os.environ['HOME'] + "/.timeball") copts = cparse.get_options(profile=opts['profile']) if (opts['operation'] == 'backup'): for var in ['target', 'dest']: if opts[var] == None: opts[var] = copts[var] for exc in copts['exclude']: opts['exclude'].append(exc) return opts
def write(args, out_stream): """write config file""" import sys config = config_parser() config.add_section(constants.dflt_section) for opt in constants.default_config: config.set(constants.dflt_section, opt, str(args[opt]).strip()) if out_stream is sys.stdout: config.write(out_stream) else: with open(out_stream, 'w') as out_file: config.write(out_file)
try: from configparser import ConfigParser COPA = ConfigParser() fc = open("tests/pyrfc.cfg", "r") COPA.read_file(fc) except ImportError as ex: from configparser import config_parser COPA = config_parser() COPA.read_file("tests/pyrfc.cfg") CONFIG_SECTIONS = COPA._sections PARAMS = CONFIG_SECTIONS["coevi51"] def get_error(ex): error = {} ex_type_full = str(type(ex)) error["type"] = ex_type_full[ex_type_full.rfind(".") + 1 : ex_type_full.rfind("'")] error["code"] = ex.code if hasattr(ex, "code") else "<None>" error["key"] = ex.key if hasattr(ex, "key") else "<None>" error["message"] = ex.message.split("\n") error["msg_class"] = ex.msg_class if hasattr(ex, "msg_class") else "<None>" error["msg_type"] = ex.msg_type if hasattr(ex, "msg_type") else "<None>" error["msg_number"] = ex.msg_number if hasattr(ex, "msg_number") else "<None>" error["msg_v1"] = ex.msg_v1 if hasattr(ex, "msg_v1") else "<None>" return error
return { 'BenchmarkResult': result, 'ElapsedTime': elapsed_time, 'UsedThreads': threads_used, 'BenchmarkVersion': benchmark_version, 'ExtraInfo': extra, 'UserNote': user_note, } if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: benchmark-conf-to-json.py benchmark.conf") sys.exit(1) cfg = config_parser(strict=False) cfg.optionxform = lambda opt: opt cfg.read(sys.argv[1]) out = defaultdict(lambda: []) for section in cfg.sections(): if section == 'param': continue for key in cfg[section]: values = cfg[section][key].split('|') if len(values) >= 10: bench = { 'MachineId': key,