<commit_before>#!/usr/bin/python
# written in Python 2.7.5 by <NAME> (@pparadigm on GitHub)
# developed on a Win7 system
# last updated: August 6, 2013 @ 4:34PM

# This program is meant to handle the door management process with the RFID
# keys, and allow management of the system. Might track who is in the building.

# FEATURES TO IMPLEMENT
#
# 1. How to run a CLI and the door system at the same time
#    a. In the meantime, I will have two ways of running the program, which
#       require a restart in between. I would like to improve this, because
#       the doors would not be operable while the program database information
#       was modified.
# 2. No duplicate IDs in key database
#    a. What happens if one is manually added to the database? (json might
#       handle this already)
# 3. Back up whenever a card is added or removed, in case of power failure
# 4. Way to change settings without deleting whosin.conf file (will be done
#    with CLI)
# 5. Create list and process for determining who is in the building ("in" and
#    "out" scanner tags)
# 6. Add LCD screen outputs.
# 7. Add door control (servos).
# 8. Make databases pretty.
#
# ---------

import json
import logging

import RFID

listening = True


def keyRetrieval(ID):
    logging.info("Retrieving key info from database...")
    for index in range(len(keyDB)):
        if ID in keyDB[index]:
            for person in keyDB[index][ID]:
                level = int(keyDB[index][ID][person])
                logging.info("Information found.")
                logging.debug("Key returned name of %s and access level \
%i."%(person, level))
                return level, person
    logging.info("No information found.")
    return None, None


def doorRetrieval():
    # For now, door is hardcoded.
    door = "Front Door IN"
    logging.info("Tag scanned at %s."%(door))
    # The following is a lie, for now.
    logging.info("Retrieving door info from database...")
    level = int(-1)
    logging.info("Information found.")
    logging.debug("Door lookup returned required access level of %i."%(level))
    return level


# Print statements in this function should eventually print to the LCD screen.
def access(scan):
    # capitalized as a stylistic choice
    scan.ID = scan.ID.upper()
    if scan.isValid:
        search = keyRetrieval(scan.ID)
        accessLevel, name = search[0], search[1]
        if accessLevel is None:
            print "Key does not exist. No access."
        else:
            roomLevel = doorRetrieval()
            if accessLevel <= roomLevel:
                print "Welcome, %s."%(name)
            else:
                print "%s does not have access to this room."%(name)
    else:
        print "Bad scan. Try rescanning."
        return


def portConfig():
    try:
        setDoc = open("whosin.conf", "r")
        name, rate = setDoc.readline().split(" : ")
        setDoc.close()
    except (ValueError, IOError):
        logging.warning("No configuration found, attempting to create one...")
        name = str(raw_input("System port descripter (case-sensitive): "))
        rate = int(raw_input("Transmission rate: "))
        save = raw_input("Save these settings? [y/N]: ").lower().strip()
        # Honestly, I don't really care how the user says "no".
        if save == ("y" or "yes"):
            settings = "%s : %s"%(name, rate)
            setDoc = open("whosin.conf", "w")
            setDoc.write(settings)
            setDoc.close()
        else:
            print "Settings not saved."
    return name, rate


def startup():<commit_msg>implemented door database check for permission<commit_after>#!/usr/bin/python
# written in Python 2.7.5 by Prime Paradigm (@pparadigm on GitHub)
# developed on a Win7 system
# last updated: August 7, 2013 @ 1:28PM

# This program is meant to handle the door management process with the RFID
# keys, and allow management of the system. Might track who is in the building.

# FEATURES TO IMPLEMENT
#
# 1. How to run a CLI and the door system at the same time
#    a. In the meantime, I will have two ways of running the program, which
#       require a restart in between. I would like to improve this, because
#       the doors would not be operable while the program database information
#       was modified.
# 2. No duplicate IDs in key database
#    a. What happens if one is manually added to the database? (json might
#       handle this already)
# 3. Back up whenever a card is added or removed, in case of power failure
# 4. Way to change settings without deleting whosin.conf file (will be done
#    with CLI)
# 5. Create list and process for determining who is in the building ("in" and
#    "out" scanner tags)
# 6. Add LCD screen outputs.
# 7. Add door control (servos).
# 8. Make databases pretty.
#
# ---------

import json
import logging

import RFID

listening = True


def keyRetrieval(ID):
    logging.info("Retrieving key info from database...")
    for index in range(len(keyDB)):
        if ID in keyDB[index]:
            for person in keyDB[index][ID]:
                level = int(keyDB[index][ID][person])
                logging.info("Information found.")
                logging.debug("Key returned name of %s and access level \
%i."%(person, level))
                return level, person
    logging.info("No information found.")
    return None, None


def doorRetrieval():
    # For now, door is hardcoded.
    door = "Front Door IN"
    logging.info("Tag scanned at %s."%(door))
    # door will never not be in the database, as it is equivalent to the
    # scanner that the key ID is sent from.
    logging.info("Retrieving door info from database...")
    for index in range(len(doorDB)):
        if door in doorDB[index]:
            level = doorDB[index][door]
    logging.debug("Door lookup returned required access level of %i."%(level))
    return level


# Print statements in this function should eventually print to the LCD screen.
def access(scan):
    # capitalized as a stylistic choice
    scan.ID = scan.ID.upper()
    if scan.isValid:
        roomLevel = doorRetrieval()
        search = keyRetrieval(scan.ID)
        accessLevel, name = search[0], search[1]
        if accessLevel is None:
            print "Key does not exist. No access."
        else:
            if accessLevel <= roomLevel:
                print "Welcome, %s."%(name)
            else:
                print "%s does not have access to this room."%(name)
    else:
        print "Bad scan. Try rescanning."
        return


def portConfig():
    try:
        setDoc = open("whosin.conf", "r")
        name, rate = setDoc.readline().split(" : ")
        setDoc.close()
    except (ValueError, IOError):
        logging.warning("No configuration found, attempting to create one...")
        name = str(raw_input("System port descripter (case-sensitive): "))
        rate = int(raw_input("Transmission rate: "))
        save = raw_input("Save these settings? [y/N]: ").lower().strip()
        # Honestly, I don't really care how the user says "no".
        if save == ("y" or "yes"):
            settings = "%s : %s"%(name, rate)
            setDoc = open("whosin.conf", "w")
            setDoc.write(settings)
            setDoc.close()
        else:
            print "Settings not saved."
    return name, rate


def startup():
{'fraction_non_alphanumeric': 0.10435732823384783, 'fraction_numerical': 0.006146701270318263, 'mean_word_length': 2.4701421800947867, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '172635', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2022, 'n_words': 850}