def main():
    """Do some stuff"""
    # Parse all command line argument
    args = parse_arguments().parse_args()

    # Setup logging
    configure_logging(args)
    logging.debug(args)

    # Prompt for a password if necessary
    if not args.password:
        password = getpass.getpass(prompt='Password ({0}): '.format(args.user))
    else:
        password = args.password

    # Create an instance of ADQuery which sets up a single
    # connection used for querying, for all AD object types
    ldap_url = 'ldap://{0}:{1}'.format(args.host, args.port)
    adq = ADQuery(user=args.user, password=password, page_size=args.page_size,
                  ldap_url=ldap_url, tls_no_verify=args.tls_no_verify)
    if args.subcommand == 'user':
        adu = ADUser(adq)
        users = adu.users(base_dn=args.base_dn, attributes=args.attributes,
                          samaccountnames=args.samaccountnames,
                          explicit_membership_only=args.explicit_membership_only)
        users = object_filter(users, args.grep)
        print(serialize([u.to_dict() for u in users],
                        output_format=args.output_format, attributes_only=args.attributes_only))
    elif args.subcommand == 'group':
        adg = ADGroup(adq)
        groups = adg.groups(base_dn=args.base_dn, attributes=args.attributes,
                            samaccountnames=args.samaccountnames,
                            explicit_membership_only=args.explicit_membership_only)
        groups = object_filter(groups, args.grep)
        print(serialize([g.to_dict() for g in groups],
                        output_format=args.output_format, attributes_only=args.attributes_only))
    elif args.subcommand == 'computer':
        adg = ADComputer(adq)
        computers = adg.computers(base_dn=args.base_dn, attributes=args.attributes,
                                  samaccountnames=args.samaccountnames)
        computers = object_filter(computers, args.grep)
        print(serialize([c.to_dict() for c in computers],
                        output_format=args.output_format, attributes_only=args.attributes_only))
def main ( ) : args = parse_arguments ( ) . parse_args ( ) configure_logging ( args ) logging . debug ( args ) if not args . password : password = getpass . getpass ( prompt = 'Password ({0}): ' . format ( args . user ) ) else : password = args . password ldap_url = 'ldap://{0}:{1}' . format ( args . host , args . port ) adq = ADQuery ( user = args . user , password = password , page_size = args . page_size , ldap_url = ldap_url , tls_no_verify = args . tls_no_verify ) if args . subcommand == 'user' : adu = ADUser ( adq ) users = adu . users ( base_dn = args . base_dn , attributes = args . attributes , samaccountnames = args . samaccountnames , explicit_membership_only = args . explicit_membership_only ) users = object_filter ( users , args . grep ) print ( serialize ( [ u . to_dict ( ) for u in users ] , output_format = args . output_format , attributes_only = args . attributes_only ) ) elif args . subcommand == 'group' : adg = ADGroup ( adq ) groups = adg . groups ( base_dn = args . base_dn , attributes = args . attributes , samaccountnames = args . samaccountnames , explicit_membership_only = args . explicit_membership_only ) groups = object_filter ( groups , args . grep ) print ( serialize ( [ g . to_dict ( ) for g in groups ] , output_format = args . output_format , attributes_only = args . attributes_only ) ) elif args . subcommand == 'computer' : adg = ADComputer ( adq ) computers = adg . computers ( base_dn = args . base_dn , attributes = args . attributes , samaccountnames = args . samaccountnames ) computers = object_filter ( computers , args . grep ) print ( serialize ( [ c . to_dict ( ) for c in computers ] , output_format = args . output_format , attributes_only = args . attributes_only ) )
Do some stuff