Esempio n. 1
0
def main():
    logging.info("Started")
    global db
    while True:
        rfid_input = input("Scan a device...")
        db = MyDB()
        device_id = rfid_scan(rfid_input)
        if device_id is False:
            continue
        else:
            print("Valid Device")
        device_name = db.get_device_name_from_id(device_id)
        user_info = get_name()
        while user_info is False:
            user_info = get_name()
        print("Valid ID")
        if check_if_out(device_id):
            check_in(user_info, device_id)
            slack.check_in_notice(user_info, device_name)
            print("{} checked in by {} {}.".format(device_name,
                                                   user_info.get('FirstName'),
                                                   user_info.get('LastName')))
            create_space()
        else:
            check_out(user_info, device_id)
            slack.check_out_notice(user_info, device_name)
            print("{} checked out by {} {}.".format(device_name,
                                                    user_info.get('FirstName'),
                                                    user_info.get('LastName')))
            create_space()
Esempio n. 2
0
def main():
    logging.info("Started")
    global db
    while True:
        rfid_input = input("Scan a device...")
        db = MyDB()
        device_id = rfid_scan(rfid_input)
        if device_id is False:
            continue
        else:
            print("Valid Device")
        device_name = db.get_device_name_from_id(device_id)
        user_info = get_name()
        while user_info is False:
            user_info = get_name()
        print("Valid ID")
        if check_if_out(device_id):
            check_in(user_info, device_id)
            slack.check_in_notice(user_info, device_name)
            print("{} checked in by {} {}.".format(device_name, user_info.get(
                'FirstName'), user_info.get('LastName')))
            create_space()
        else:
            check_out(user_info, device_id)
            slack.check_out_notice(user_info, device_name)
            print("{} checked out by {} {}.".format(device_name, user_info.get(
                'FirstName'), user_info.get('LastName')))
            create_space()
Esempio n. 3
0
def main():
    """
    Assigns variables, checks if device is new or needs checked out/in.
    """
    global location
    location = config['DEFAULT']['Location']
    logging.info("LOCATION: {}".format(location))
    global db
    db = MyDB()
    global port
    port = find_port()
    serial = get_serial(port)
    global device_id
    device_id = db.get_device_id_from_serial(serial)
    global device_name
    device_name = get_device_name(device_id, location, port)
    global filename
    filename = create_tempfile(port)
    play_sound()
    if device_id is None and serial is not None:
        to_database(serial)
    else:
        checked_out = check_if_out(location, port)
        if checked_out:
            logging.info("[usb_checkout][main] CHECK IN")
            device_name = db.get_device_name_from_id(location, device_id)
            user_info = get_user_info_from_db(device_id)
            check_in(device_id, port)
            slack.check_in_notice(user_info, device_name)
        else:
            logging.info("[usb_checkout][main] CHECK OUT")
            device_id = db.get_device_id_from_port(location, port)
            device_name = db.get_device_name_from_id(location, device_id)
            timer.start()
            user_info = get_user_info()
            check_out(user_info, device_id)
            slack.check_out_notice(user_info, device_name)
            logging.info(
                "[usb_checkout][main] {} checked out by {} {}.".format(
                    device_name,
                    user_info.get('FirstName'), user_info.get('LastName')))
    delete_tempfile(filename)
Esempio n. 4
0
def main():
    """
    Assigns variables, checks if device is new or needs checked out/in.
    """
    global db
    db = MyDB()
    global port
    port = find_port()
    serial = get_serial(port)
    global device_id
    device_id = db.get_device_id_from_serial(serial)
    global device_name
    device_name = get_device_name(device_id, port)
    global filename
    filename = create_tempfile(port)
    play_sound()
    if device_id is None and serial is not None:
        to_database(serial)
    else:
        checked_out = check_if_out(port)
        if checked_out:
            logging.info("[usb_checkout][main]CHECK IN")
            device_name = db.get_device_name_from_id(device_id)
            user_info = get_user_info_from_db(device_id)
            check_in(device_id, port)
            slack.check_in_notice(user_info, device_name)
        else:
            logging.info("[usb_checkout][main] CHECK OUT")
            device_id = db.get_device_id_from_port(port)
            timer.start()
            user_info = get_user_info()
            check_out(user_info, device_id)
            slack.check_out_notice(user_info, device_name)
            logging.info(
                "[usb_checkout][main] {} checked out by {} {}.".format(
                    device_name, user_info.get('FirstName'),
                    user_info.get('LastName')))
    delete_tempfile(filename)
Esempio n. 5
0
    for f in os.listdir('/tmp'):
        if re.search('.nanny', f):
            os.remove(os.path.join('/tmp', f))


def main():
    """
    Keeps the database up-to-date by looking for devices that have been attached/removed
    from the Pi without checking them in/out, then sends a reminder to users who
    have expired checkouts.
    :return:
    """
    if not is_checkout_running():
        clean_tmp_file()
        check_usb_connections()
        verify_registered_connections()
        checkout_reminders()


if __name__ == "__main__":
    logging.config.fileConfig("config/nanny_logging.conf")
    config = configparser.ConfigParser()
    config.read('config/DeviceNanny.ini')
    global location
    location = config['DEFAULT']['Location']
    logging.info("[nanny] Started")
    global db
    db = MyDB()
    main()
    logging.info("[nanny] Finished")