def main()

in src/neuron-gatherinfo/neuron-gatherinfo.py [0:0]


def main():
    """ main function
        creates command-line option parser, sanity checks, and then executes code
        based on command-line options
    """

    parser = add_cmdline_args()

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    options = parser.parse_args()
    # append the directory where we'll create files to what the user provides
    options.outdir = os.path.realpath(os.path.join(options.outdir, NEURONTMPDIR))

    if options.ccdir is not None:
        options.ccdir = os.path.realpath(options.ccdir)

    if options.addfldir is not None:
        options.addfldir = os.path.realpath(options.addfldir)

    if options.rtdir is not None:
        options.rtdir = os.path.realpath(options.rtdir)

    options.stdout = os.path.realpath(options.stdout)

    if sanity_check(options):
        parser.print_help()
        sys.exit(1)

    # create the base directory
    try:
        os.makedirs(options.outdir)
    except FileNotFoundError:
        print("Error in creating directory {}".format(options.outdir))
        sys.exit(1)

    # if options.allow:
    #     allow_capture_of_files()

    if options.filterfile is not None:
        add_additional_filters(os.path.realpath(options.filterfile))

    # record the command as executed by the user
    with open(os.path.join(options.outdir, USERCMDFILE), "w") as fdout:
        fdout.write("Command executed as: {}\n".format(" ".join(sys.argv)))

    dump_compiler_info(outdir=options.outdir, location=options.ccdir,
                       allowmodel=options.allowmodel,
                       addfldir=options.addfldir,
                       verbose=options.verbose)

    # Not being used now. neuron-dump.py would do this
    # dump_rt_info(location=options.rtdir, verbose=options.verbose)

    dump_miscinfo(outdir=options.outdir, verbose=options.verbose)
    dump_proc_info(outdir=options.outdir, verbose=options.verbose)

    copy_stdout(outdir=options.outdir, stdout=options.stdout, verbose=options.verbose)
    copy_syslog(outdir=options.outdir, include_flag=options.includemismatch,
                verbose=options.verbose)

    # run the existing tool neuron-dump.py as well
    run_neuron_dump(outdir=options.outdir, verbose=options.verbose)

    package_tarball(outdir=options.outdir, allowmodel=options.allowmodel,
                    ccdir=options.ccdir, verbose=options.verbose)

    # change permissions for the directory and output
    os.system("chown -R {} {}".format(os.getlogin(), os.path.split(options.outdir)[0]))