예제 #1
0
        sys.stderr.write('Could not find plugin class, aborting...\n')
        sys.exit(1)

    # Load configuration
    if args.config:
        plugin.set_parameters(pickle.loads(args.config))

    # Load selection
    sels = []
    try:
        if args.selectionfile:
            f = open(args.Selection, 'r')
            sel_string = '\n'.join(f.readlines())
        else:
            sel_string = args.Selection

        sels = json.loads(sel_string)
    except Exception, e:
        sys.stderr.write('Could not load selection, aborting...\n')
        sys.exit(1)

    selections = []
    for s in sels:
        selections.append(DataProvider.from_data(s))

    if args.datadir and os.path.isdir(args.datadir):
        AnalysisPlugin.data_dir = args.datadir
    plugin.start(selections[0], selections[1:])

if __name__ == '__main__':
    main()
예제 #2
0
def main():
    parser = argparse.ArgumentParser(description="Start an analysis plugin")
    parser.add_argument("Name", type=str, help="Name of analysis class")
    parser.add_argument("Code", type=str, help="Code of the analysis")
    parser.add_argument("Selection", type=str, help="Serialized selection")
    parser.add_argument("-c", "--config", dest="config", type=str, help="Pickled configuration of analysis")
    parser.add_argument(
        "-cf",
        "--codefile",
        dest="codefile",
        action="store_const",
        const=True,
        default=False,
        help="Code represents a filename containing " "code (default: Code is a string containing code",
    )
    parser.add_argument(
        "-sf",
        "--selectionfile",
        dest="selectionfile",
        action="store_const",
        const=True,
        default=False,
        help="Selection represents a filename containing " "the serialized selection (default: Selection is a string",
    )
    parser.add_argument("-dd", "--datadir", type=str, help="The data directory")
    parser.add_argument("-io", type=str, default=[], nargs="+", help="IO plugin file paths")

    parsed = parser.parse_known_args()
    args = parsed[0]
    if parsed[1]:
        print >> sys.stderr, ("Warning: the following command options are " "invalid and were ignored:"), parsed[1]

    exc_globals = {}

    if args.codefile:
        execfile(args.Code, exc_globals)
    else:
        exec (args.Code, exc_globals)

    # Load plugin
    plugin = None
    for cl in exc_globals.values():
        if not inspect.isclass(cl):
            continue

        if not issubclass(cl, AnalysisPlugin):
            continue

        if not cl.__name__ == args.Name:
            continue

        plugin = cl()
        break

    # Load IO plugins
    for io in args.io:
        io_plugin.load_from_file(io)

    if not plugin:
        sys.stderr.write("Could not find plugin class, aborting...\n")
        sys.exit(1)

    # Load configuration
    if args.config:
        plugin.set_parameters(pickle.loads(args.config))

    # Load selection
    try:
        if args.selectionfile:
            f = open(args.Selection, "r")
            sel_string = "\n".join(f.readlines())
        else:
            sel_string = args.Selection

        sels = json.loads(sel_string)
    except Exception:
        sys.stderr.write("Could not load selection, aborting...\n")
        sys.exit(1)

    selections = []
    for s in sels:
        selection = DataProvider.from_data(s)
        selection.progress = progress
        selections.append(selection)

    if args.datadir and os.path.isdir(args.datadir):
        AnalysisPlugin.data_dir = args.datadir

    try:
        plugin.start(selections[0], selections[1:])
    except progress_indicator.CancelException:
        print "User canceled."
    finally:
        progress.done()

    if has_qt:  # Quit event loop if the plugin has not created a Qt Window
        if app.topLevelWidgets() == [progress]:
            app.exit(0)

    return 0