def profile_dump(connection, args): """Dumps ATC profiles.""" result = sap.adt.atc.dump_profiles(connection, args.profiles, args.checkman) printout(json.dumps(result, indent=2))
def begin(self, count): """Reports start of activation""" if count is None or count == 1: printout('Activating:') else: printout(f'Activating {count} objects:')
def start_object(self, name, index, count): """Reports start of object activation""" end = '\n' if count is not None and count != 1: end = f' ({index}/{count})\n' printout('*', name, end=end)
def activate_objects(self, connection, args): """Actives the given object.""" printout('Activating:') for name in args.name: printout('*', name) obj = self.instance(connection, name, args) sap.adt.wb.activate(obj)
def activate_object_list(activator, object_enumerable, count): """Starts object activation and handles results""" try: stats = activator.activate_sequentially(object_enumerable, count) except sap.cli.wb.StopObjectActivation as ex: printout('Activation has stopped') printout_activation_stats(ex.stats) if ex.stats.active_objects: printout('Active objects:') for obj in ex.stats.active_objects: printout_adt_object(' ', obj) return 1 else: printout('Activation has finished') printout_activation_stats(stats) if stats.inactive_objects: printout('Inactive objects:') for obj in stats.inactive_objects: printout_adt_object(' ', obj) return 1 return 1 if stats.errors > 0 else 0
def write_object_text(self, connection, args): """Changes source code of the given program include""" toactivate = collections.OrderedDict() printout('Writing:') for obj, text in write_args_to_objects(self, connection, args): printout('*', str(obj)) with obj.open_editor(corrnr=args.corrnr) as editor: editor.write(''.join(text)) toactivate[obj.name] = obj if not args.activate: return 0 activated_items = toactivate.items() return activate_object_list(self.build_activator(args), activated_items, count=len(activated_items))
def listcertificates(connection, args): """Lists X.509 Base64 certificates currently installed in SAP system Exceptions: - SAPCliError: - when the given storage does not belong to the storage white list - when identity argument has invalid format """ ssl_storages = ssl_storages_from_arguments(connection, args) for ssl_storage in ssl_storages: if not ssl_storage.exists(): raise SAPCliError( f'Storage for identity {ssl_storage.identity} does not exist') for cert in ssl_storage.get_certificates(): cert = ssl_storage.parse_certificate(cert) printout('*', cert['EV_SUBJECT'])
def write_object_text(self, connection, args): """Changes source code of the given program include""" toactivate = collections.OrderedDict() printout('Writing:') for obj, text in write_args_to_objects(self, connection, args): printout('*', str(obj)) with obj.open_editor(corrnr=args.corrnr) as editor: editor.write(''.join(text)) toactivate[obj.name] = obj if args.activate: printout('Activating:') for name, obj in toactivate.items(): printout('*', name) sap.adt.wb.activate(obj)
def osql(connection, args): """Executes OpenSQL query""" sqlconsole = sap.adt.DataPreview(connection) table = sqlconsole.execute(args.statement, rows=args.rows, aging=args.noaging) if args.output == 'json': printout(json.dumps(table, indent=2)) else: header = args.noheadings for row in table: if not header: printout(' | '.join(row.keys())) header = True printout(' | '.join(row.values()))
def dumpcertificates(connection, args): """Dumps X.509 Base64 certificates currently installed in SAP system Exceptions: - SAPCliError: - when the given storage does not belong to the storage white list - when identity argument has invalid format """ ssl_storages = ssl_storages_from_arguments(connection, args) for ssl_storage in ssl_storages: if not ssl_storage.exists(): raise SAPCliError( f'Storage for identity {ssl_storage.identity} does not exist') for cert in ssl_storage.get_certificates(): c_b64 = base64.b64encode(cert) printout('-----BEGIN CERTIFICATE-----') printout(c_b64.decode('ascii')) printout('-----END CERTIFICATE-----')
def customizing(connection, _): """Retrieves ATC customizing""" settings = sap.adt.atc.fetch_customizing(connection) printout('System Check Variant:', settings.system_check_variant)
def print_entry(entry, prefix=''): printout(f'{prefix}{entry.object.name} ({entry.object.typ})')
def profile_list(connection, args): """Retrieves ATC profiles.""" result = sap.adt.atc.fetch_profiles(connection) if args.output == 'json': printout(json.dumps(result, indent=2)) else: header_printed = args.noheadings for (profile_id, profile) in result.items(): # print header as the first line of the output if not header_printed: printout('profile_id', end='') if args.long: printout(' | ' + ' | '.join(profile.keys())) else: printout('') header_printed = True # print individual profiles printout(profile_id, end='') if args.long: printout(' | ' + ' | '.join(profile.values())) else: printout('')
def handle_message(self, msg): """Reports an activation message""" printout(f'-- {msg.obj_descr}') printout(f' {msg.typ}: {msg.short_text}')
def printout_adt_object(prefix, obj): """Prints out ADT object in identifiable way""" printout(f'{prefix}{obj.objtype.code} {obj.name}')
def printout_activation_stats(stats): """Prints out activation statistics""" printout('Warnings:', stats.warnings) printout('Errors:', stats.errors)