def main(argv): inputfile = "" outputfile = "" try: opts, args = getopt.getopt(argv, "hi:o:", ["inputfile=", "outputfile="]) except getopt.GetoptError: print sys.argv[0] + " -i <inputfile> -o <outputfile.csv>" sys.exit(2) for opt, arg in opts: if opt == "-h": print sys.argv[0] + " -i <inputfile> -o <outputfile.csv>" sys.exit() elif opt in ("-i", "--inputfile"): inputfile = arg elif opt in ("-o", "--outputfile"): outputfile = arg if outputfile == "": print "Gi en fil å skrive til, med opsjon -o" sys.exit() conn = bofh.connect("https://cerebrum-uio.uio.no:8000", "data/ca.pem") # kobler til cerebrum sid = conn._run_raw_command("login", getpass.getuser(), getpass.getpass()) # ber om passord conn._session = sid # session id brukerrapport = codecs.open(outputfile, encoding="utf-8", mode="w") for user in read_userlist(inputfile): brukerrapport.write(get_aff(conn, user) + "\n") brukerrapport.close()
def main(argv): inputfile = "" outputfile = "" disk = "" try: opts, args = getopt.getopt(argv, "hd:i:o:", ["disk=", "inputfile=", "outputfile="]) except getopt.GetoptError: print sys.argv[0] + " -d <disk> -i <inputfile> -o <outputfile.txt>" sys.exit(2) for opt, arg in opts: if opt == "-h": print sys.argv[0] + " -i <inputfile> -o <outputfile.txt>" sys.exit() elif opt in ("-d", "--disk"): disk = arg elif opt in ("-i", "--inputfile"): inputfile = arg elif opt in ("-o", "--outputfile"): outputfile = arg if outputfile == "": print "Gi en fil å skrive til, med opsjon -o" sys.exit() conn = bofh.connect("https://cerebrum-uio.uio.no:8000", "data/ca.pem") # kobler til cerebrum sid = conn._run_raw_command("login", getpass.getuser(), getpass.getpass()) # ber om passord conn._session = sid # session id instituttliste = set() brukerrapport = open(outputfile, "w") for stedkode in read_stedkodeliste(inputfile): for bruker in get_ids(conn, stedkode, "ANSATT"): instituttliste.add(bruker) for bruker in get_ids(conn, stedkode, "TILKNYTTET"): instituttliste.add(bruker) for bruker in get_ids(conn, stedkode, "MANUELL"): instituttliste.add(bruker) for bruker in read_disk(disk): instituttliste.add(bruker_til_id(conn, bruker)) for id in instituttliste: brukerrapport.write("id:" + id + "\n") brukerrapport.close()
def main(inargs=None): parser = argparse.ArgumentParser( description="The Cerebrum Bofh client") parser.add_argument( '--version', action='version', version=str(dist_info)) connect_args = parser.add_argument_group('connection settings') connect_args.add_argument( '--url', default=bofh.get_default_url(), help="connect to bofhd server at %(metavar)s" " (default: %(default)s)", metavar='URL', ) connect_args.add_argument( '-u', '--user', default=getpass.getuser(), help="authenticate as %(metavar)s (default: %(default)s)", metavar='USER', ) connect_args.add_argument( '-c', '--cert', default=bofh.get_default_cert(), help="use ca certificates from %(metavar)s (default: %(default)s)", metavar='PEM', ) connect_args.add_argument( '--insecure', default=False, action='store_true', help="skip certificate hostname validation", ) connect_args.add_argument( '--timeout', type=float, default=None, help="set connection timeout to %(metavar)s seconds" " (default: no timeout)", metavar="N", ) output_args = parser.add_argument_group('output settings') output_args.add_argument( '-p', '--prompt', default=bofh.readlineui.DEFAULT_PROMPT, help="use a custom prompt (default: %(default)r)", metavar='PROMPT', ) output_args.add_argument( '-v', '--verbosity', dest='verbosity', action='count', default=None, help="show debug messages on stderr") args = parser.parse_args(inargs) setup_logging(args.verbosity) logger.debug('args: %r', args) print("Connecting to {}\n".format(complete_url(args.url))) try: conn = bofh.connect(url=complete_url(args.url), cert=args.cert, insecure=args.insecure, timeout=args.timeout) if conn.motd: print(conn.motd) conn.login(args.user, prompt_password(args.user)) except (KeyboardInterrupt, EOFError): print("") raise SystemExit except bofh.proto.BofhError as e: raise SystemExit('{}'.format(e.args[0])) # Start the interactive REPL try: bofh.readlineui.repl(conn, prompt=args.prompt) except Exception as e: print('Error: {}'.format(e)) finally: conn.logout()
def main(inargs=None): parser = argparse.ArgumentParser(description="The Cerebrum Bofh client") parser.add_argument('--version', action='version', version=str(dist_info)) connect_args = parser.add_argument_group('connection settings') connect_args.add_argument( '--url', default=bofh.get_default_url(), help="connect to bofhd server at %(metavar)s" " (default: %(default)s)", metavar='URL', ) connect_args.add_argument( '-u', '--user', default=getpass.getuser(), help="authenticate as %(metavar)s (default: %(default)s)", metavar='USER', ) connect_args.add_argument( '-c', '--cert', default=bofh.get_default_cert(), help="use ca certificates from %(metavar)s (default: %(default)s)", metavar='PEM', ) connect_args.add_argument( '--insecure', default=False, action='store_true', help="skip certificate hostname validation", ) connect_args.add_argument( '--timeout', type=float, default=None, help="set connection timeout to %(metavar)s seconds" " (default: no timeout)", metavar="N", ) output_args = parser.add_argument_group('output settings') output_args.add_argument( '-p', '--prompt', default=bofh.readlineui.DEFAULT_PROMPT, help="use a custom prompt (default: %(default)r)", metavar='PROMPT', ) output_args.add_argument('-v', '--verbosity', dest='verbosity', action='count', default=None, help="show debug messages on stderr") args = parser.parse_args(inargs) setup_logging(args.verbosity) logger.debug('args: %r', args) print("Connecting to {}\n".format(complete_url(args.url))) try: conn = bofh.connect(url=complete_url(args.url), cert=args.cert, insecure=args.insecure, timeout=args.timeout) if conn.motd: print(conn.motd) conn.login(args.user, prompt_password(args.user)) except (KeyboardInterrupt, EOFError): print("") raise SystemExit except bofh.proto.BofhError as e: raise SystemExit('{}'.format(e.args[0])) # Start the interactive REPL try: bofh.readlineui.repl(conn, prompt=args.prompt) except Exception as e: print('Error: {}'.format(e)) finally: conn.logout()