Ejemplo n.º 1
0
    parser.add_argument("-v","--verbose", action='store_true', help="Be verbose")

    args = parser.parse_args()

    #signal.signal(signal.SIGINT, signal_handler)

    if path.isfile(args.file):
        pargs = subprocess_args(args.file)
        (module_name,dot,ext) = args.file.partition('.')
        action = imp.load_source(module_name, args.file)
    else:
        stderr.write("{}: could not find action file\n".format(args.file))
        exit(1)
    ec = EmacsClient(servername=action.session_name())

    for line in imap(lambda x: x.strip("\" \n"), stdin):
        if path.isfile(line) or path.isdir(line):
            stderr.write("{}\n".format(line))
            if args.verbose:
                stderr.write("Running action {} with input {}\n".format(pargs, line))
            aprocess = subprocess.Popen(pargs, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (pout,perr) = aprocess.communicate(line)
            actions = [action for action in (action.strip() for action in pout.split('\n')) if action]
            parse_actions(actions, verbose=args.verbose, ec=ec)
            stderr.write("paction error: {}\n".format(perr))
            ec.kill_all()
        else:
            stderr.write("{}: Invalid path\n".format(line))
    ec.kill_all()