Esempio n. 1
0
void ProcessManager::ExecuteTankCommandAsync(
        const FB::BrowserHostPtr& host,
        const std::string &pipelineConfigPath,
        const std::string &command,
        const std::vector<std::string> &args,
        const ExecuteTankCallback &cb)
{
    VerifyArguments(pipelineConfigPath, command);
    boost::thread cmdThread(&ProcessManager::_ExecuteTankCommandAsync, this, host, pipelineConfigPath, command, args, cb);
}
Esempio n. 2
0
/*
 * Execute the toolkit command asynchronously
 */
void ProcessManager::ExecuteToolkitCommandAsync(
        const FB::BrowserHostPtr& host,
        const std::string &pipelineConfigPath,
        const std::string &command,
        const std::vector<std::string> &args,
        const ExecuteToolkitCallback &cb)
{
    host->htmlLog("[ShotgunIntegration] ExecuteToolkitCommandAsync");
    VerifyArguments(pipelineConfigPath, command);
    boost::thread cmdThread(&ProcessManager::_ExecuteToolkitCommandAsync, this, pipelineConfigPath, command, args, cb);
}
Esempio n. 3
0
FB::VariantMap ProcessManager::ExecuteTankCommand(
    const FB::BrowserHostPtr& host,
    const std::string &pipelineConfigPath,
    const std::string &command,
    const std::vector<std::string> &args)
{
    host->htmlLog("[ShotgunIntegration] ExecuteTankCommand");
    
    try {
        VerifyArguments(pipelineConfigPath, command);
    
        fs::path exec = pipelineConfigPath;
        exec /= TANK_SCRIPT_NAME;

        std::vector<std::string> arguments = boost::assign::list_of(exec.string())(command);
        arguments.insert(arguments.end(), args.begin(), args.end());

        bp::child child = Launch(exec.string(), arguments);
        bp::status status = child.wait();

        int retcode;
        if (status.exited())
            retcode = status.exit_status();
        else
            retcode = -1;

        std::string line;
        std::ostringstream ossStdout;
        bp::pistream &isStdout = child.get_stdout();
        while (std::getline(isStdout, line)) {
            ossStdout << line << std::endl;
        }
        
        std::ostringstream ossStderr;
        bp::pistream &isStderr = child.get_stderr();
        while (std::getline(isStderr, line)) {
            ossStderr << line << std::endl;
        }
        
        return FB::variant_map_of<std::string>
            ("retcode", retcode)
            ("out", ossStdout.str())
            ("err", ossStderr.str());
    } catch (std::exception &e) {
        // May be running in a non-main thread.  Avoid propagating exception
        return FB::variant_map_of<std::string>
            ("retcode", -1)
            ("out", std::string(""))
            ("err", std::string(e.what()));
    }
}
Esempio n. 4
0
/*
 * Actually execute the command
 */
FB::VariantMap ProcessManager::_ExecuteToolkitCommand(
    const std::string &pipelineConfigPath,
    const std::string &command,
    const std::vector<std::string> &args)
{    
    try {
        VerifyArguments(pipelineConfigPath, command);
    
        fs::path pcPath = pipelineConfigPath;
        fs::path exec = pcPath / GetToolkitScriptName();

        if (!fs::is_regular_file(exec))
            exec = pcPath / GetToolkitFallbackScriptName();

        std::vector<std::string> arguments = boost::assign::list_of(exec.string())(command);
        arguments.insert(arguments.end(), args.begin(), args.end());

		bp::context ctx;
		ctx.environment = bp::self::get_environment();
		ctx.stdout_behavior = bp::capture_stream();
		ctx.stderr_behavior = bp::capture_stream();

		bp::child child = Launch(exec.string(), arguments);
        
        // Keep trying through interrupts
        int retcode;
        while (true) {
            try {
                bp::status status = child.wait();
                if (status.exited())
                    retcode = status.exit_status();
                else
                    retcode = -1;
                break;
            } catch (boost::system::system_error &e) {
                if (e.code().value() != EINTR)
                    throw;
            }
        }

        std::string line;
        std::ostringstream ossStdout;
        bp::pistream &isStdout = child.get_stdout();
        while (std::getline(isStdout, line)) {
            ossStdout << line << std::endl;
        }
        
        std::ostringstream ossStderr;
        bp::pistream &isStderr = child.get_stderr();
        while (std::getline(isStderr, line)) {
            ossStderr << line << std::endl;
        }
        
        return FB::variant_map_of<std::string>
            ("retcode", retcode)
            ("out", ossStdout.str())
            ("err", ossStderr.str());
    } catch (std::exception &e) {
        // May be running in a non-main thread.  Avoid propagating exception
        return FB::variant_map_of<std::string>
            ("retcode", -1)
            ("out", std::string(""))
            ("err", std::string(e.what()));
    } catch (...) {
        return FB::variant_map_of<std::string>
            ("retcode", -1)
            ("out", std::string(""))
            ("err", std::string("unknown error executing toolkit command"));
    }
}
Esempio n. 5
0
int main(int argc, char **argv)
{
    int arg, len;
    char *output_filename;
    int output_file_found = 0;
    Options options;

    options.shrink = 1;
    options.rotate = False;
    options.compress = True;
    memset(&b.name, 0, MAX_BITMAPNAME);

    /* Parse options */
    for (arg = 1; arg < argc; arg++)
    {
        len = strlen(argv[arg]);
        if (len == 0)
            break;

        // Look for command file
        if (argv[arg][0] == '@')
        {
            CommandFileLoad(argv[arg] + 1, &argc, &argv, arg);
            arg--;    // Need to reparse this argument next time through; it's been changed
            continue;
        }

        if (argv[arg][0] != '-')
            break;

        if (len < 2)
        {
            printf("Ignoring unknown option -\n");
            continue;
        }

        switch(argv[arg][1])
        {
        case 'o':
            arg++;
            if (arg >= argc)
            {
                printf("Missing output filename\n");
                break;
            }
            output_filename = argv[arg];
            output_file_found = 1;
            break;

        case 'n':
            arg++;
            if (arg >= argc)
            {
                printf("Missing bitmap name\n");
                break;
            }
            strncpy(b.name, argv[arg], MAX_BITMAPNAME);
            b.name[MAX_BITMAPNAME - 1] = 0;
            break;

        case 's':
            arg++;
            if (arg >= argc)
            {
                printf("Missing shrink factor; assuming 1\n");
                break;
            }
            options.shrink = atoi(argv[arg]);
            if (options.shrink == 0)
            {
                printf("Illegal shrink factor value %d; assuming 1\n", options.shrink);
                options.shrink = 1;
            }
            break;

        case 'r':
            options.rotate = True;
            break;

        case 'x':
            options.compress = False;
            break;

        case '?':
            Usage();
            exit(0);

        default:
            printf("Ignoring unknown option %c\n", argv[arg][1]);
        }

    }

    if (!output_file_found)
        Error("No output file specified");

    if (arg >= argc)
        Error("Missing bitmap description list");

    ReadCommandLine(argc - arg, argv + arg, &options);

    if (!VerifyArguments(&b, &options))
        exit(1);

    WrapInit();

    if (!WriteBGFFile(&b, &options, output_filename))
        Error("Error writing output file");

    WrapShutdown();

    return 0;
}