Ejemplo n.º 1
0
int main(int argc, char ** argv)
{
    int config_status = loadConfig(argc, argv, USAGE_CLIENT); 
    if (config_status < 0) {
        if (config_status == CONFIG_VERSION) {
            reportVersion(argv[0]);
            return 0;
        } else if (config_status == CONFIG_HELP) {
            showUsage(argv[0], USAGE_CLIENT, "[ [package.]function]");
            return 0;
        } else if (config_status != CONFIG_ERROR) {
            log(ERROR, "Unknown error reading configuration.");
        }
        // Fatal error loading config file
        return 1;
    }

    int optind = config_status;

    assert(optind <= argc);

    if (optind == (argc - 1)) {
        std::string arg(argv[optind]);
        std::string::size_type pos = arg.rfind(".");
        if (pos == std::string::npos) {
            // std::cout << "function " << arg << std::endl << std::flush;
            function = arg;
        } else {
            package = arg.substr(0, pos);
            function = arg.substr(pos + 1);
            // std::cout << "module.function " << package << "." << function << std::endl << std::flush;
        }
    } else if (optind != argc) {
        usage(argv[0]);
        return 1;
    }

    bool interactive = global_conf->findItem("", "interactive");
    int status = 0;

    init_python_api(ruleset_name, false);
    extend_client_python_api();
    new ClientPropertyManager();

    if (interactive) {
        python_prompt();
    } else {
        std::map<std::string, std::string> keywords;
        keywords["account"] = account;
        keywords["password"] = password;
        keywords["host"] = server;
        python_client_script(package, function, keywords);
    }

    shutdown_python_api();

    return status;
}
Ejemplo n.º 2
0
int main(int argc, char ** argv)
{
    int config_status = loadConfig(argc, argv, USAGE_CLIENT); 
    if (config_status < 0) {
        if (config_status == CONFIG_VERSION) {
            reportVersion(argv[0]);
            return 0;
        } else if (config_status == CONFIG_HELP) {
            showUsage(argv[0], USAGE_CLIENT, "[ [package.]function]");
            return 0;
        } else if (config_status != CONFIG_ERROR) {
            log(ERROR, "Unknown error reading configuration.");
        }
        // Fatal error loading config file
        return 1;
    }

    int optind = config_status;

    assert(optind <= argc);

    if (optind == (argc - 1)) {
        std::string arg(argv[optind]);
        std::string::size_type pos = arg.rfind('.');
        if (pos == std::string::npos) {
            // std::cout << "function " << arg << std::endl << std::flush;
            function = arg;
        } else {
            package = arg.substr(0, pos);
            function = arg.substr(pos + 1);
            // std::cout << "module.function " << package << "." << function << std::endl << std::flush;
        }
    } else if (optind != argc) {
        usage(argv[0]);
        return 1;
    }

    bool interactive = global_conf->findItem("", "interactive");
    int status = 0;

    std::vector<std::string> python_directories;
    // Add the path to the non-ruleset specific code.
    python_directories.push_back(share_directory + "/cyphesis/scripts");
    python_directories.push_back(share_directory + "/cyphesis/rulesets/basic/scripts");
    // Add the path to the ruleset specific code.
    python_directories.push_back(share_directory + "/cyphesis/rulesets/" + ruleset_name + "/scripts");

    init_python_api({&CyPy_Physics::init,
                     &CyPy_Rules::init,
                     &CyPy_EntityFilter::init,
                     &CyPy_Atlas::init,
                     &CyPy_Common::init},
                    python_directories, false);

    extend_client_python_api();
    new ClientPropertyManager();

    if (interactive) {
        python_prompt();
    } else {
        std::map<std::string, std::string> keywords;
        keywords["account"] = account;
        keywords["password"] = password;
        keywords["host"] = server;
        python_client_script(package, function, keywords);
    }

    shutdown_python_api();

    return status;
}