<commit_before>#! /usr/bin/env python
import sys
from argparse import ArgumentParser
import json
from router import Router


def main():
    # Parse argment
    parser = ArgumentParser(
        description='Collect configuration files on mutiple routers')
    parser.add_argument('-i', '--inventory',
                        type=str,
                        default='/etc/configcollector/inventory.json',
                        help='router information file\n\
                        (default=etc/configcollector/inventory.json)')
    parser.add_argument('-o',  '--output',
                        type=str,
                        default='./output/',
                        help='output directory\n\
                        (default=CURRENT_DIRECTORY/output/)')
    args = parser.parse_args()

    # Read router infomation file
    try:
        with open(args.inventory, 'r') as file:
            router_info_json = file.read()
    except (IOError, IndexError):
        sys.stderr.write('Cannot open file : ' + args.inventory + '\n')
        sys.exit(1)

    # Convert json format to dictionary
    try:
        router_info = json.loads(router_info_json)
    except ValueError as error:
        sys.stderr.write('JSON format error : \n')
        sys.stderr.write(router_info_json)
        sys.stderr.write(str(error))
        sys.exit(1)

    # Login and get config for each routers
    for num in range(len(router_info)):
        router = Router(router_info[num])
        print 'Accessing router: ' + router_info[num]['hostname'] + '...'

        try:
            router.login()
            output = router.get_config()
        except:<commit_msg>change default output directory<commit_after>#! /usr/bin/env python
import sys
from argparse import ArgumentParser
import json
from router import Router


def main():
    # Parse argment
    parser = ArgumentParser(
        description='Collect configuration files on mutiple routers')
    parser.add_argument('-i', '--inventory',
                        type=str,
                        default='/etc/configcollector/inventory.json',
                        help='router information file\n\
                        (default=etc/configcollector/inventory.json)')
    parser.add_argument('-o',  '--output',
                        type=str,
                        default='./',
                        help='output directory\n\
                        (default=CURRENT_DIRECTORY)')
    args = parser.parse_args()

    # Read router infomation file
    try:
        with open(args.inventory, 'r') as file:
            router_info_json = file.read()
    except (IOError, IndexError):
        sys.stderr.write('Cannot open file : ' + args.inventory + '\n')
        sys.exit(1)

    # Convert json format to dictionary
    try:
        router_info = json.loads(router_info_json)
    except ValueError as error:
        sys.stderr.write('JSON format error : \n')
        sys.stderr.write(router_info_json)
        sys.stderr.write(str(error))
        sys.exit(1)

    # Login and get config for each routers
    for num in range(len(router_info)):
        router = Router(router_info[num])
        print 'Accessing router: ' + router_info[num]['hostname'] + '...'

        try:
            router.login()
            output = router.get_config()
        except:
{'fraction_non_alphanumeric': 0.10963455149501661, 'fraction_numerical': 0.0012080942313500453, 'mean_word_length': 1.9335695305580158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1864157', 'n_tokens_mistral': 908, 'n_tokens_neox': 887, 'n_words': 214}