Пример #1
0
def make_creds_file(root):
    """
    Prompt the user for user name and password to create a read-only file
    containing login credentials. If the user cancels the operation anytime,
    raises an IOError and no file is created.

    root is the root directory of the interface program. It is needed so that
    the credentials file is saved in the correct location.

    The file contains two lines. The first is username. The second is password.

    Params:
        root string
    """
    path = defaults.creds(root)
    if utils.exists_file(path):
        while True:
            answer = raw_input('Credentials file found. Do you want to overwrite (Y/N)? ')
            if answer.lower() == 'y':
                os.remove(path)
                break
            elif answer.lower() == 'n':
                return
            else:
                print('Unknown input. Please try again.')

    try:
        user = get_username()
        pwd = get_password()
    except KeyboardInterrupt:
        raise IOError('User cancelled operation')

    with open(path, 'wb') as cf:
        cf.write('%s\n%s\n' % (user, pwd))
    os.chmod(path, 0400)
Пример #2
0
def run(root):
    creds_file = defaults.creds(root)
    cnxn_str = utils.get_cnxn_str(creds_file)
    meter_file = defaults.meter_file(root)

    earliest = {}
    latest = {}
    print("Running check.py...")
    with Cursor.Cursor(cnxn_str) as cursor:
        earliest_query = get_query_str(True)
        latest_query = get_query_str(False)
        meter_generator = utils.read_meter_file(meter_file)
        meters = [m for m in meter_generator]
        earliest = get_timestamps(cursor, meters, earliest_query)
        latest = get_timestamps(cursor, meters, latest_query)

        for i, m in enumerate(meters):
            ion_name = utils.get_ion_name(m)
            earliest_ts = earliest[ion_name]
            latest_ts = latest[ion_name]
            print(" %d)\t%s\tStart: %s\tEnd: %s" % (i, ion_name, earliest_ts, latest_ts))
Пример #3
0
def run(root):
    creds_file = defaults.creds(root)
    cnxn_str = utils.get_cnxn_str(creds_file)
    meter_file = defaults.meter_file(root)

    earliest = {}
    latest = {}
    print("Running check.py...")
    with Cursor.Cursor(cnxn_str) as cursor:
        earliest_query = get_query_str(True)
        latest_query = get_query_str(False)
        meter_generator = utils.read_meter_file(meter_file)
        meters = [m for m in meter_generator]
        earliest = get_timestamps(cursor, meters, earliest_query)
        latest = get_timestamps(cursor, meters, latest_query)

        for i, m in enumerate(meters):
            ion_name = utils.get_ion_name(m)
            earliest_ts = earliest[ion_name]
            latest_ts = latest[ion_name]
            print(" %d)\t%s\tStart: %s\tEnd: %s" %
                  (i, ion_name, earliest_ts, latest_ts))
Пример #4
0
def make_creds_file(root):
    """
    Prompt the user for user name and password to create a read-only file
    containing login credentials. If the user cancels the operation anytime,
    raises an IOError and no file is created.

    root is the root directory of the interface program. It is needed so that
    the credentials file is saved in the correct location.

    The file contains two lines. The first is username. The second is password.

    Params:
        root string
    """
    path = defaults.creds(root)
    if utils.exists_file(path):
        while True:
            answer = raw_input(
                'Credentials file found. Do you want to overwrite (Y/N)? ')
            if answer.lower() == 'y':
                os.remove(path)
                break
            elif answer.lower() == 'n':
                return
            else:
                print('Unknown input. Please try again.')

    try:
        user = get_username()
        pwd = get_password()
    except KeyboardInterrupt:
        raise IOError('User cancelled operation')

    with open(path, 'wb') as cf:
        cf.write('%s\n%s\n' % (user, pwd))
    os.chmod(path, 0400)