Beispiel #1
0
def main():
    DEFAULTS = {
        "key": "./admin-adder/serviceAccountKey.json",
    }

    parser = argparse.ArgumentParser(
        description='Download and save teams answers to file',
        epilog="Made by László Baráth (Sasszem), 2018")
    parser.add_argument('output', help='Output CSV file')
    parser.add_argument('--key',
                        help='Account key JSON file. Defaults to "{}"'.format(
                            DEFAULTS["key"]),
                        default=DEFAULTS["key"])
    parser.add_argument('-v',
                        '--verbose',
                        help='Enable additional logging',
                        action="store_true",
                        dest="verbose")
    parser.add_argument(
        '--no-heading',
        help='Disable the generation of a first heading row in the report',
        dest="heading",
        action="store_false")
    args = parser.parse_args()

    db = utils.make_connection(args.key)
    ids = get_problem_ids(db)
    save_database(db.collection("teams"), args.output, args.heading, ids)
Beispiel #2
0
def main():
    DEFAULTS = {
        "key": "./serviceAccountKey.json",
        "collection": "problems",
    }

    # Only allow python 3
    if sys.version_info < (3, 0):
        print("Sry, only Python 3 is supported")
        exit(0)

    parser = argparse.ArgumentParser(
        description='Upload data to cloud firestore from a CSV file',
        epilog="Made by László Baráth (Sasszem), 2018")
    parser.add_argument('source', help='source CSV file')
    parser.add_argument('--key',
                        help='Account key JSON file. Defaults to "{}"'.format(
                            DEFAULTS["key"]),
                        default=DEFAULTS["key"])
    parser.add_argument(
        '--collection',
        help='Collection to upload to. Defaults to "{}"'.format(
            DEFAULTS["collection"]),
        default=DEFAULTS["collection"])
    parser.add_argument(
        '--nofresh',
        help='Do not remove old entries from target collection',
        action="store_false",
        dest="fresh")
    parser.add_argument('-v',
                        '--verbose',
                        help='Enable additional logging',
                        action="store_true",
                        dest="verbose")

    args = parser.parse_args()
    utils.verbose(args.verbose)

    db = utils.make_connection(args.key)

    collection = utils.get_collection(db, args.collection, args.fresh)

    read_to_db(args.source, collection)
INDEXES = {
    'rides': [
        'miles', 'seconds', 'start_timestamp', 'end_timestamp',
        ('miles', 'seconds')
    ],
    'payments': ['fare']
}

if __name__ == '__main__':
    drop_index = False
    if len(sys.argv) > 1:
        if sys.argv[1] == "drop":
            drop_index = True

    connection = make_connection()
    cursor = connection.cursor()

    for table in INDEXES:
        print(f"Working on table {table}")
        for column in INDEXES[table]:
            if drop_index:
                print(f"\tDropping index on column {column}")
                try:
                    if isinstance(column, str):
                        cursor.execute(f'DROP INDEX `{column}` ON `{table}`')
                    else:
                        cursor.execute(
                            f'DROP INDEX `{"_".join(column)}` ON `{table}`')
                except Exception as e:
                    print(e)
Beispiel #4
0
"""
Just a damn simple seeder for testing
"""

import utils
import random
import string


def randstring(N):
    return ''.join(random.choices(string.ascii_uppercase + string.digits, k=N))


db = utils.make_connection("../serviceAccountKey.json")


def generate_team(team_collection):
    doc = team_collection.document()
    doc.set({"name": randstring(8)})

    solutions = doc.collection("solutions")
    for id in range(30):
        solutions.document().set({"id": id, "solution": random.randrange(100)})


def generate(db):
    teams = db.collection("teams")
    for i in range(5):
        generate_team(teams)

Beispiel #5
0
def main():
    parser = argparse.ArgumentParser(description='DevNet Tool')
    parser.add_argument('--user', type=str, required=True, help='Username')
    parser.add_argument('--password', type=str, required=True, help='Password')
    parser.add_argument('--network',
                        type=str,
                        required=True,
                        help='Management Network')
    parser.add_argument('--ntp-server',
                        type=str,
                        required=True,
                        help='NTP server')

    args = parser.parse_args()

    validate_args(args)

    output_report = ''

    for address in get_ip_address_list(args.network):
        print(f'connection started to {address}')

        connection = make_connection(address=address,
                                     user=args.user,
                                     password=args.password)
        if not connection:
            continue
        print('connection success')

        connection.enable()

        device_info = parse_show_version(connection=connection)
        if bool(device_info) is False:
            print('show version parse failed, skip')
            continue

        config = make_backup(connection=connection,
                             hostname=device_info['Hostname'])
        if not config:
            print('failed to get config, skip')
            continue

        device_cdp_info = parse_cdp_neighbor_detail(
            connection=connection, hostname=device_info['Hostname'])

        config_timezone_ntp(connection=connection,
                            hostname=device_info['Hostname'],
                            ntp_server=args.ntp_server,
                            config=config)

        ntp_service_info = parse_ntp_status(connection=connection,
                                            hostname=device_info['Hostname'])

        close_connection(connection=connection)

        output_report += make_report(device_info=device_info,
                                     cdp_info=device_cdp_info,
                                     ntp_info=ntp_service_info)

    if output_report:
        print('----SUMMARY----\n')
        print(output_report)