コード例 #1
0
void generic_options::parse(int argc, char* argv[])
{
    _progname = boost::filesystem::path(argv[0]).filename().string();

    boost::program_options::command_line_parser parser(argc, argv);
    boost::program_options::store(
            parser
                .options(all_options())
                .positional(positional_options())
                .run(),
            _vm);
    boost::program_options::notify(_vm);

    if(_vm.count("help"))
    {
        usage();
        std::exit(1);
    }
}
コード例 #2
0
int main(int argc, char* argv[])
{
    std::string server;
    std::string port;
    std::string user;
    std::string folder;
    std::string password;
    fs::path from;
    fs::path to;
    bool inbox;
    
    //[Gmail]/Sent Mail
    po::options_description general_options("General");
    general_options.add_options()
        ("help", "list options");
    po::options_description file_options("Load");
    file_options.add_options()
        ("save-raw", po::value<fs::path>(&to), "path to save the data (after download phase)");
    po::options_description source_options("Download");
    source_options.add_options()
        ("load", po::value<fs::path>(&from), "mail folder");
        
    po::options_description run_options("Run");
    
    po::options_description all_options("Email Topology Options");
    all_options
        .add(general_options)
        .add(file_options)
        .add(source_options);

    if(argc < 2) {
        std::cout << all_options << std::endl;
        return 1;
    }

    po::variables_map vm;
    try {
        int options_style = po::command_line_style::default_style;
        po::store(po::parse_command_line(argc, argv, all_options, options_style), vm);
        po::notify(vm);
    } catch(std::exception& e) {
        std::cout << all_options << std::endl;
        std::cout << "Command line parsing failed: " << e.what() << std::endl;
        return 1;
    }
    
    if(vm.count("help")) {
        std::cout << all_options << std::endl;
        return 1;
    }

    email_id_bimap email_id;
    connectedness_graph cg;
    entity_map em;
    initial_group_partition_map igpm;
    message_id_set message_id;

    if(!vm.count("save-raw")) {
        std::cout << "you must specify --save-raw with a file name" << std::endl;
        return 1;
    }
    if(!vm.count("load") || !fs::exists(from) || !fs::is_directory(from)) {
        std::cout << "missing source data folder (or not a folder)" << std::endl;
        return 1;
    }
    std::vector<char> buffer(128 * 1024);
    std::string headers;
    std::cout << "loading " << from;
    for(fs::recursive_directory_iterator fe, fi(from); fi != fe; ++fi) {
        if(fs::is_directory(*fi))
            continue;
        fs::ifstream in(*fi);    
        headers.clear();
        while(in.good()) {
            in.getline(&buffer[0], buffer.size());
            std::string line = &buffer[0];
            boost::algorithm::trim(line);
            if(line.empty()) 
                break;
            headers += "\n";
            headers += line;
        }
        members_t g;
        for(boost::sregex_iterator i(headers.begin(), headers.end(), re_terms), e; i != e; ++i) {
            const boost::smatch& what = *i;
            std::string field = what[1].str();
            if(boost::algorithm::iequals(field, "Message-ID")) {
                std::string id = what[2].str();
                boost::algorithm::trim(id);
                std::pair<message_id_set::iterator, bool> result = message_id.insert(id);
                //skip this duplicate message
                if(!result.second) {
                    g.clear();
                    break;
                }

            } else if(boost::algorithm::iequals(field, "From") || boost::algorithm::iequals(field, "To") || boost::algorithm::iequals(field, "Cc")) {
                std::string data = what[2].str();
                boost::replace_all(data, "\n", "");
                boost::replace_all(data, "\r", "");
                for(boost::sregex_iterator j(data.begin(), data.end(), re_email), e; j != e; ++j) {
                    std::string name = (*j)[1].str();
                    if(name.empty())
                        name = (*j)[2].str();
                    std::string email_address = (*j)[3].str();
                    boost::algorithm::to_lower(email_address);
                    boost::algorithm::trim(name);
                    std::pair<email_id_bimap::map_by<email>::iterator, bool> result = email_id.by<email>().insert(
                        email_id_bimap::map_by<email>::value_type(email_address, email_id.size()));
                    if(result.second)
                        std::cout << "@" << std::flush;
                    if(!name.empty() && boost::to_lower_copy(name) != email_address)
                        em[email_address].insert(name);
                    g.insert(result.first->second);
                }
            }
        }
        if(g.empty()) {
            continue;
        }

        initial_group_partition_map::iterator r = igpm.find(g);
        if(r == igpm.end()) {
            connectedness_graph::vertex_descriptor node = gr::add_vertex(cg);
            cg[node].members = g;
            cg[node].weight = 1;
            igpm.insert(r, std::make_pair(g, node));
        } else {
            connectedness_graph::vertex_descriptor node = r->second;
            cg[node].weight++;
        }
        std::cout << ". " <<  std::flush;
    }
    std::cout << std::endl;
    if(fs::exists(to))
        fs::remove(to);
    fs::ofstream out(to);
    std::cout << "saving data to " << to.file_string();        
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        out << (unsigned long long)cg[*i].weight;
        for(members_t::iterator j = cg[*i].members.begin(); j != cg[*i].members.end(); ++j) {
            out << "\t" << email_id.by<bit>().equal_range(*j).first->second;
        }
        out << std::endl;
    }
    out << "-" << std::endl;
    for(entity_map::iterator i = em.begin(); i != em.end(); ++i) {
        out << i->first;
        for(std::set<std::string>::iterator k = i->second.begin(); k != i->second.end(); ++k) {
            out << "\t" << *k; 
        }
        out << std::endl;
    }
    return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: fjflores/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    std::string source;
    std::string file_name;
    std::string save_path;
    po::options_description visible_options("OPTIONS");

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description config("CONFIGURATION");
        config.add_options()
                ("filename,n", po::value<std::string>(&file_name),
                "The base snapshot file name.\n"
                "The timestamp of the snapshot will be prepended to this name."
                "If not provided, the SOURCE name will be used.\n")
                ("folder,f", po::value<std::string>(&save_path),
                "The folder in which snapshots will be saved.")
                ;

        po::options_description hidden("HIDDEN OPTIONS");
        hidden.add_options()
                ("source", po::value<std::string>(&source),
                "The name of the frame SOURCE that supplies frames to view.\n")
                ;

        po::positional_options_description positional_options;
        positional_options.add("source", -1);

        po::options_description all_options("ALL OPTIONS");
        all_options.add(options).add(hidden);

        visible_options.add(options).add(config);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat Frame Viewer version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("source")) {
            printUsage(visible_options);
            std::cerr << oat::Error("A SOURCE must be specified. Exiting.\n");
            return -1;
        }

        if (!variable_map.count("folder")) {
            save_path = ".";
        }

        if (!variable_map.count("filename")) {
            file_name = "";
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return -1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.\n");
        return -1;
    }

    // Make the viewer
    Viewer viewer(source, save_path, file_name);

    // Tell user
    std::cout << oat::whoMessage(viewer.get_name(),
              "Listening to source " + oat::sourceText(source) + ".\n")
              << oat::whoMessage(viewer.get_name(),
              "Press 's' on the viewer window to take a snapshot.\n")
              << oat::whoMessage(viewer.get_name(),
              "Press CTRL+C to exit.\n");

    try {

        // Infinite loop until ctrl-c or end of stream signal
        run(&viewer);

        // Tell user
        std::cout << oat::whoMessage(viewer.get_name(), "Exiting.\n");

        // Exit
        return 0;

    } catch (const std::runtime_error& ex) {
        std::cerr << oat::whoError(viewer.get_name(), ex.what())
                  << "\n";
    } catch (const cv::Exception& ex) {
        std::cerr << oat::whoError(viewer.get_name(), ex.msg)
                  << "\n";
    } catch (...) {
        std::cerr << oat::whoError(viewer.get_name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #4
0
ファイル: tool.cpp プロジェクト: erickt/mongo
    int Tool::main( int argc , char ** argv ){
        static StaticObserver staticObserver;
        
        cmdLine.prealloc = false;

        boost::filesystem::path::default_name_check( boost::filesystem::no_check );

        _name = argv[0];

        /* using the same style as db.cpp */
        int command_line_style = (((po::command_line_style::unix_style ^
                                    po::command_line_style::allow_guessing) |
                                   po::command_line_style::allow_long_disguise) ^
                                  po::command_line_style::allow_sticky);
        try {
            po::options_description all_options("all options");
            all_options.add(*_options).add(*_hidden_options);

            po::store( po::command_line_parser( argc , argv ).
                       options(all_options).
                       positional( _positonalOptions ).
                       style(command_line_style).run() , _params );

            po::notify( _params );
        } catch (po::error &e) {
            cerr << "ERROR: " << e.what() << endl << endl;
            printHelp(cerr);
            return EXIT_BADOPTIONS;
        }

        // hide password from ps output
        for (int i=0; i < (argc-1); ++i){
            if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")){
                char* arg = argv[i+1];
                while (*arg){
                    *arg++ = 'x';
                }
            }
        }

        if ( _params.count( "help" ) ){
            printHelp(cout);
            return 0;
        }

        if ( _params.count( "verbose" ) ) {
            logLevel = 1;
        }

        for (string s = "vv"; s.length() <= 10; s.append("v")) {
            if (_params.count(s)) {
                logLevel = s.length();
            }
        }
        
        preSetup();

        bool useDirectClient = hasParam( "dbpath" );
        
        if ( ! useDirectClient ) {
            _host = "127.0.0.1";
            if ( _params.count( "host" ) )
                _host = _params["host"].as<string>();

            if ( _params.count( "port" ) )
                _host += ':' + _params["port"].as<string>();
            
            if ( _noconnection ){
                // do nothing
            }
            else if ( _host.find( "," ) == string::npos ){
                DBClientConnection * c = new DBClientConnection( _autoreconnect );
                _conn = c;

                string errmsg;
                if ( ! c->connect( _host , errmsg ) ){
                    cerr << "couldn't connect to [" << _host << "] " << errmsg << endl;
                    return -1;
                }
            }
            else {
                log(1) << "using pairing" << endl;
                DBClientPaired * c = new DBClientPaired();
                _paired = true;
                _conn = c;

                if ( ! c->connect( _host ) ){
                    cerr << "couldn't connect to paired server: " << _host << endl;
                    return -1;
                }
            }
            
            (_usesstdout ? cout : cerr ) << "connected to: " << _host << endl;
        }
        else {
            if ( _params.count( "directoryperdb" ) ) {
                directoryperdb = true;
            }
            assert( lastError.get( true ) );
            Client::initThread("tools");
            _conn = new DBDirectClient();
            _host = "DIRECT";
            static string myDbpath = getParam( "dbpath" );
            dbpath = myDbpath.c_str();
            try {
                acquirePathLock();
            }
            catch ( DBException& e ){
                cerr << endl << "If you are running a mongod on the same "
                    "path you should connect to that instead of direct data "
                    "file access" << endl << endl;
                dbexit( EXIT_CLEAN );
                return -1;
            }

            theFileAllocator().start();
        }

        if ( _params.count( "db" ) )
            _db = _params["db"].as<string>();

        if ( _params.count( "collection" ) )
            _coll = _params["collection"].as<string>();

        if ( _params.count( "username" ) )
            _username = _params["username"].as<string>();

        if ( _params.count( "password" )
             && ( _password.empty() ) ) {
            _password = askPassword();
        }

        if (_params.count("ipv6"))
            enableIPv6();

        int ret = -1;
        try {
            ret = run();
        }
        catch ( DBException& e ){
            cerr << "assertion: " << e.toString() << endl;
            ret = -1;
        }
    
        if ( currentClient.get() )
            currentClient->shutdown();

        if ( useDirectClient )
            dbexit( EXIT_CLEAN );
        return ret;
    }
コード例 #5
0
int main(int argc, char* argv[])
{
    std::string server;
    std::string port;
    std::string user;
    std::string folder;
    std::string password;
    std::vector<fs::path> from;
    std::vector<fs::path> entity;
    fs::path to;
    
    //[Gmail]/Sent Mail
    po::options_description general_options("General");
    general_options.add_options()
        ("help", "list options");
    po::options_description file_options("Load");
    file_options.add_options()
        ("save-raw", po::value<fs::path>(&to), "path to save the data (after download phase)");
    po::options_description download_options("Download");
    download_options.add_options()
        ("server", po::value<std::string>(&server), "imap server dns/ip")
        ("port", po::value<std::string>(&port)->default_value("993"), "imap port")
        ("folder", po::value<std::string>(&folder)->default_value("Sent"), "imap folder")
        ("user", po::value<std::string>(&user), "imap username")
        ("password", po::value<std::string>(&password), "imap password (will ask if not specified)");
    po::options_description run_options("Run");
    
    po::options_description all_options("Email Topology Options");
    all_options
        .add(general_options)
        .add(file_options)
        .add(download_options);

    if(argc < 2) {
        std::cout << all_options << std::endl;
        return 1;
    }

    po::variables_map vm;
    try {
        int options_style = po::command_line_style::default_style;
        po::store(po::parse_command_line(argc, argv, all_options, options_style), vm);
        po::notify(vm);
    } catch(std::exception& e) {
        std::cout << all_options << std::endl;
        std::cout << "Command line parsing failed: " << e.what() << std::endl;
        return 1;
    }
    
    if(vm.count("help")) {
        std::cout << all_options << std::endl;
        return 1;
    }

    email_id_bimap email_id;
    connectedness_graph cg;
    entity_map em;
    initial_group_partition_map igpm;

    if(!vm.count("save-raw")) {
        std::cout << "you must specify --save-raw with a file name" << std::endl;
        return 1;
    }
    if(!vm.count("password")) {
        password = getpass("Password: "******"missing server for download" << std::endl;
        return 1;
    }
    if(user.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    if(password.empty()) {
        std::cout << "missing user for download" << std::endl;
        return 1;
    }
    //this is our network block, downloads all messages headers
    try
    {
        std::cout << "downloading " << folder << " from " << server << std::endl;
        //use to dedupe if there are dupes
        message_id_set message_id;        

        typedef boost::function<void (const std::string&, const std::list<std::string>& args)> untagged_handler;
        std::string pending_tag = "* ";
        std::list<std::string> pending_command;
        pending_command.push_back("WAIT_FOR_ACK");
        untagged_handler pending_handler;
        unsigned int command_id = 0;

        //The sequence of imap commands we want to run
        std::list<std::list<std::string> > commands;
        std::list<untagged_handler> handlers;

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        std::ostringstream login_os;
        login_os << "LOGIN \"" << user << "\" {" << password.size() << "}";
        commands.back().push_back(login_os.str()); 
        commands.back().push_back(password); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("LIST \"\" *"); 

        handlers.push_back(log_handler());
        commands.push_back(std::list<std::string>());
        commands.back().push_back("SELECT \"" + folder + "\""); 

        handlers.push_back(header_handler(email_id, cg, em, message_id, igpm));
        commands.push_back(std::list<std::string>());
        commands.back().push_back("FETCH 1:* (BODY.PEEK[HEADER.FIELDS (MESSAGE-ID FROM TO CC)])");
        commands.push_back(std::list<std::string>());

        handlers.push_back(log_handler());
        commands.back().push_back("LOGOUT");
    
        //open ssl connection to the server, no cert checking
        asio::io_service io_service;
        asio::ip::tcp::resolver resolver(io_service);
        asio::ip::tcp::resolver::query query(server, port);
        asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
        asio::ssl::context context(io_service, asio::ssl::context::sslv23);
        context.set_verify_mode(asio::ssl::context::verify_none);
        asio::ssl::stream<asio::ip::tcp::socket> socket(io_service, context);
        socket.lowest_layer().connect(*iterator);
        socket.handshake(asio::ssl::stream_base::client);
        asio::streambuf buf;

        while(true) {
            //read the next line of data
            std::size_t line_length = asio::read_until(socket, buf, re_crlf);
            std::string line(
                asio::buffers_begin(buf.data()),
                asio::buffers_begin(buf.data()) + line_length);
            buf.consume(line_length);
            boost::match_results<std::string::iterator> what;
            std::size_t initial = 0;
            std::list<std::string> args;
            //the line may be split into segments with chunks of data embedded, this is the case
            //for bodies or message header blocks that are returned, we only handle this case if it
            //comes in untagged response (*) not a continuation (+), i think that is normal
            while(regex_search(line.begin() + initial, line.end(), what, re_byte_buffer, boost::match_default)) {
                unsigned int bytes = boost::lexical_cast<unsigned int>(what[1].str());
                if(buf.size() < bytes)
                    asio::read(socket, buf, asio::transfer_at_least(bytes - buf.size()));
                args.push_back(
                    std::string(
                        asio::buffers_begin(buf.data()),
                        asio::buffers_begin(buf.data()) + bytes));
                buf.consume(bytes);
                line.resize(what[1].second - line.begin());
                initial = line.size();
                //read the next line of data
                line_length = asio::read_until(socket, buf, re_crlf);
                line += std::string(
                    asio::buffers_begin(buf.data()),
                    asio::buffers_begin(buf.data()) + line_length);
                buf.consume(line_length);
            }
            if(boost::algorithm::starts_with(line, pending_tag)) {
                //if the command is being completed, then we will go here, bail out if the response wasn't ok
                if(!boost::algorithm::starts_with(line, pending_tag + "OK")) {
                    std::cout << line;
                    throw std::runtime_error("command failed");
                }
                //pull the next command off the list
                pending_tag = "A" + boost::lexical_cast<std::string>(command_id++) + " ";
                if(commands.size() == 0)
                    break;
                pending_handler = handlers.front();
                pending_command = commands.front();
                commands.pop_front();
                handlers.pop_front();

                //send the command along with any data arguments
                std::cout << pending_tag << pending_command.front() << std::endl;
                asio::write(socket, asio::buffer(pending_tag.data(), pending_tag.size()));
                for(std::list<std::string>::iterator i = pending_command.begin(); i != pending_command.end(); ++i) {
                    if(i != pending_command.begin()) {
                        //print the continuation response
                        std::size_t line_length = asio::read_until(socket, buf, re_crlf);
                        std::string line(
                            asio::buffers_begin(buf.data()),
                            asio::buffers_begin(buf.data()) + line_length);
                        buf.consume(line_length);
                        std::cout << line << std::flush;
                        if(!boost::algorithm::starts_with(line, "+ ")) {
                            throw std::runtime_error("bad response when writing extra data");
                        }
                    } else {
                        //print it out as well (but not the args)
                        std::cout << *i << std::endl;
                    }
                    asio::write(socket, asio::buffer(i->data(), i->size()));
                    asio::write(socket, asio::buffer("\r\n", 2));
                }
            } else if(boost::algorithm::starts_with(line, "* ")) {
                //if there is a registered handler, dispatch to it
                if(pending_handler)
                    pending_handler(line, args);
            } else {
                throw std::runtime_error("unrecognized response");
            }
        }
    }
    catch (std::exception& e) {
        std::cout << "Exception: " << e.what() << std::endl;
        return 1;
    }
    std::cout << std::endl;
    
    if(to.empty()) {
        std::cout << "Missing output file for save" << std::endl;
        return 1;
    }
    if(fs::exists(to))
        fs::remove(to);
    fs::ofstream out(to);
    std::cout << "saving data to " << to.file_string();        
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        out << (unsigned long long)cg[*i].weight;
        for(members_t::iterator j = cg[*i].members.begin(); j != cg[*i].members.end(); ++j) {
            out << "\t" << email_id.by<bit>().equal_range(*j).first->second;
        }
        out << std::endl;
    }
    out << "-" << std::endl;
    for(entity_map::iterator i = em.begin(); i != em.end(); ++i) {
        out << i->first;
        for(std::set<std::string>::iterator k = i->second.begin(); k != i->second.end(); ++k) {
            out << "\t" << *k; 
        }
        out << std::endl;
    }
    return 0;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: 410pfeliciano/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    std::vector<std::string> sources;
    std::string sink;
    std::string type;
    std::vector<std::string> config_fk;
    bool config_used = false;
    po::options_description visible_options("OPTIONS");


    std::unordered_map<std::string, char> type_hash;
    type_hash["mean"] = 'a';

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description config("CONFIGURATION");
        config.add_options()
                ("config,c", po::value<std::vector<std::string> >()->multitoken(),
                "Configuration file/key pair.")
                ;
        po::options_description hidden("HIDDEN OPTIONS");
        hidden.add_options()
                ("type", po::value<std::string>(&type),
                "Type of test position combiner to use.")
                ("sources", po::value< std::vector<std::string> >(),
                "The names the SOURCES supplying the Position2D objects to be combined.")
                ("sink", po::value<std::string>(&sink),
                "The name of the SINK to which combined position Position2D objects will be published.")
                ;

        po::positional_options_description positional_options;
        positional_options.add("type", 1);
        positional_options.add("sources", -1); // If not overridden by explicit --sink, last positional argument is sink.

        po::options_description all_options("OPTIONS");
        all_options.add(options).add(config).add(hidden);

        visible_options.add(options).add(config);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat Position Combiner version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("type")) {
            printUsage(visible_options);
            std::cerr << oat::Error("A TYPE must be specified.\n");
            return -1;
        }

        if (!variable_map.count("sources")) {
            printUsage(visible_options);
            std::cerr << oat::Error("At least two SOURCES and a SINK must be specified.\n");
            return -1;
        }

        sources = variable_map["sources"].as< std::vector<std::string> >();
        if (sources.size() < 3) {
            printUsage(visible_options);
            std::cerr << oat::Error("At least two SOURCES and a SINK must be specified.\n");
            return -1;
        }

        if (!variable_map.count("sink")) {

            // If not overridden by explicit --sink, last positional argument is the sink.
            sink = sources.back();
            sources.pop_back();
        }

        if (!variable_map["config"].empty()) {

            config_fk = variable_map["config"].as<std::vector<std::string> >();

            if (config_fk.size() == 2) {
                config_used = true;
            } else {
                printUsage(visible_options);
                std::cerr << oat::Error("Configuration must be supplied as file key pair.\n");
                return -1;
            }
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return -1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.\n");
        return -1;
    }

    // Create component
    std::shared_ptr<oat::PositionCombiner> combiner;

    // Refine component type
    switch (type_hash[type]) {
        case 'a':
        {
            combiner = std::make_shared<oat::MeanPosition>(sources, sink);
            break;
        }
        default:
        {
            printUsage(visible_options);
            std::cerr << oat::Error("Invalid TYPE specified.\n");
            return -1;
        }
    }

    // The business
    try {

        if (config_used)
            combiner->configure(config_fk[0], config_fk[1]);

        // Tell user
        std::cout << oat::whoMessage(combiner->name(), "Listening to sources ");
        for (auto s : sources)
            std::cout << oat::sourceText(s) << " ";
        std::cout << ".\n"
                << oat::whoMessage(combiner->name(),
                "Steaming to sink " + oat::sinkText(sink) + ".\n")
                << oat::whoMessage(combiner->name(),
                "Press CTRL+C to exit.\n");

        // Infinite loop until ctrl-c or server end-of-stream signal
        run(combiner);

        // Tell user
        std::cout << oat::whoMessage(combiner->name(), "Exiting.\n");

        // Exit
        return 0;

    } catch (const cpptoml::parse_exception &ex) {
        std::cerr << oat::whoError(combiner->name(),
                     "Failed to parse configuration file " + config_fk[0] + "\n")
                  << oat::whoError(combiner->name(), ex.what()) << "\n";
    } catch (const std::runtime_error &ex) {
        std::cerr << oat::whoError(combiner->name(), ex.what()) << "\n";
    } catch (const cv::Exception &ex) {
        std::cerr << oat::whoError(combiner->name(), ex.what()) << "\n";
    } catch (const boost::interprocess::interprocess_exception &ex) {
        std::cerr << oat::whoError(combiner->name(), ex.what()) << "\n";
    } catch (...) {
        std::cerr << oat::whoError(combiner->name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #7
0
ファイル: cmsRun.cpp プロジェクト: 12345ieee/cmg-cmssw
int main(int argc, char* argv[]) {

  int returnCode = 0;
  std::string context;
  bool alwaysAddContext = true;
  boost::shared_ptr<edm::Presence> theMessageServicePresence;
  std::auto_ptr<std::ofstream> jobReportStreamPtr;
  boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::JobReport> > jobRep;
  EventProcessorWithSentry proc;

  try {
    try {

      // NOTE: MacOs X has a lower rlimit for opened file descriptor than Linux (256
      // in Snow Leopard vs 512 in SLC5). This is a problem for some of the workflows
      // that open many small root datafiles.  Notice that this is safe to do also
      // for Linux, but we agreed not to change the behavior there for the moment.
      // Also the limits imposed by ulimit are not affected and still apply, if
      // there.
#ifdef __APPLE__
      context = "Setting file descriptor limit";
      struct rlimit limits;
      getrlimit(RLIMIT_NOFILE, &limits);
      limits.rlim_cur = (OPEN_MAX < limits.rlim_max) ? OPEN_MAX : limits.rlim_max;
      setrlimit(RLIMIT_NOFILE, &limits);
#endif

      context = "Initializing plug-in manager";
      edmplugin::PluginManager::configure(edmplugin::standard::config());

      // Decide whether to use the multi-thread or single-thread message logger
      //    (Just walk the command-line arguments, since the boost parser will
      //    be run below and can lead to error messages which should be sent via
      //    the message logger)
      context = "Initializing either multi-threaded or single-threaded message logger";
      bool multiThreadML = false;
      for(int i = 0; i < argc; ++i) {
        if((std::strncmp (argv[i], "-t", 20) == 0) ||
           (std::strncmp (argv[i], "--multithreadML", 20) == 0)) {
          multiThreadML = true;
          break;
        }
      }

      // Load the message service plug-in

      if(multiThreadML) {
        theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
          makePresence("MessageServicePresence").release());
      }
      else {
        theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
          makePresence("SingleThreadMSPresence").release());
      }

      context = "Processing command line arguments";
      std::string descString(argv[0]);
      descString += " [options] [--";
      descString += kParameterSetOpt;
      descString += "] config_file \nAllowed options";
      boost::program_options::options_description desc(descString);

      desc.add_options()
        (kHelpCommandOpt, "produce help message")
        (kParameterSetCommandOpt, boost::program_options::value<std::string>(), "configuration file")
        (kJobreportCommandOpt, boost::program_options::value<std::string>(),
                "file name to use for a job report file: default extension is .xml")
        (kEnableJobreportCommandOpt,
                "enable job report files (if any) specified in configuration file")
        (kJobModeCommandOpt, boost::program_options::value<std::string>(),
                "Job Mode for MessageLogger defaults - default mode is grid")
        (kMultiThreadMessageLoggerOpt,
                "MessageLogger handles multiple threads - default is single-thread")
        (kStrictOpt, "strict parsing");

      // anything at the end will be ignored, and sent to python
      boost::program_options::positional_options_description p;
      p.add(kParameterSetOpt, 1).add(kPythonOpt, -1);

      // This --fwk option is not used anymore, but I'm leaving it around as
      // it might be useful again in the future for code development
      // purposes.  We originally used it when implementing the boost
      // state machine code.
      boost::program_options::options_description hidden("hidden options");
      hidden.add_options()("fwk", "For use only by Framework Developers")
        (kPythonOpt, boost::program_options::value< std::vector<std::string> >(),
         "options at the end to be passed to python");

      boost::program_options::options_description all_options("All Options");
      all_options.add(desc).add(hidden);

      boost::program_options::variables_map vm;
      try {
        store(boost::program_options::command_line_parser(argc, argv).options(all_options).positional(p).run(), vm);
        notify(vm);
      }
      catch (boost::program_options::error const& iException) {
        edm::LogAbsolute("CommandLineProcessing") << "cmsRun: Error while trying to process command line arguments:\n"
          << iException.what()
	  << "\nFor usage and an options list, please do 'cmsRun --help'.";
        return edm::errors::CommandLineProcessing;
      }

      if (vm.count(kHelpOpt)) {
        std::cout << desc << std::endl;
        if (!vm.count(kParameterSetOpt)) edm::HaltMessageLogging();
        return 0;
      }

      if (!vm.count(kParameterSetOpt)) {
        edm::LogAbsolute("ConfigFileNotFound") << "cmsRun: No configuration file given.\n"
          << "For usage and an options list, please do 'cmsRun --help'.";
        edm::HaltMessageLogging();
        return edm::errors::ConfigFileNotFound;
      }
      std::string fileName(vm[kParameterSetOpt].as<std::string>());

      if (vm.count(kStrictOpt)) {
        //edm::setStrictParsing(true);
        edm::LogSystem("CommandLineProcessing") << "Strict configuration processing is now done from python";
      }

      context = "Creating the JobReport Service";
      // Decide whether to enable creation of job report xml file
      //  We do this first so any errors will be reported
      std::string jobReportFile;
      if (vm.count("jobreport")) {
        jobReportFile = vm["jobreport"].as<std::string>();
      } else if(vm.count("enablejobreport")) {
        jobReportFile = "FrameworkJobReport.xml";
      }
      jobReportStreamPtr = std::auto_ptr<std::ofstream>(jobReportFile.empty() ? 0 : new std::ofstream(jobReportFile.c_str()));

      //NOTE: JobReport must have a lifetime shorter than jobReportStreamPtr so that when the JobReport destructor
      // is called jobReportStreamPtr is still valid
      std::auto_ptr<edm::JobReport> jobRepPtr(new edm::JobReport(jobReportStreamPtr.get()));
      jobRep.reset(new edm::serviceregistry::ServiceWrapper<edm::JobReport>(jobRepPtr));
      edm::ServiceToken jobReportToken =
        edm::ServiceRegistry::createContaining(jobRep);

      context = "Processing the python configuration file named ";
      context += fileName;
      boost::shared_ptr<edm::ProcessDesc> processDesc;
      try {
        boost::shared_ptr<edm::ParameterSet> parameterSet = edm::readConfig(fileName, argc, argv);
        processDesc.reset(new edm::ProcessDesc(parameterSet));
      }
      catch(cms::Exception& iException) {
        edm::Exception e(edm::errors::ConfigFileReadError, "", iException);
        throw e;
      }

      context = "Initializing default service configurations";
      std::vector<std::string> defaultServices;
      defaultServices.reserve(6);
      defaultServices.push_back("MessageLogger");
      defaultServices.push_back("InitRootHandlers");
#ifdef linux
      defaultServices.push_back("EnableFloatingPointExceptions");
#endif
      defaultServices.push_back("UnixSignalService");
      defaultServices.push_back("AdaptorConfig");
      defaultServices.push_back("SiteLocalConfigService");

      // Default parameters will be used for the default services
      // if they are not overridden from the configuration files.
      processDesc->addServices(defaultServices);

      context = "Setting MessageLogger defaults";
      // Decide what mode of hardcoded MessageLogger defaults to use
      if (vm.count("mode")) {
        std::string jobMode = vm["mode"].as<std::string>();
        edm::MessageDrop::instance()->jobMode = jobMode;
      }

      context = "Constructing the EventProcessor";
      std::auto_ptr<edm::EventProcessor>
          procP(new
                edm::EventProcessor(processDesc, jobReportToken,
                                    edm::serviceregistry::kTokenOverrides));
      EventProcessorWithSentry procTmp(procP);
      proc = procTmp;

      alwaysAddContext = false;
      context = "Calling beginJob";
      proc->beginJob();

      alwaysAddContext = true;
      context = "Calling EventProcessor::forkProcess";
      if (!proc->forkProcess(jobReportFile)) {
        return 0;
      }

      alwaysAddContext = false;
      context = "Calling EventProcessor::runToCompletion (which does almost everything after beginJob and before endJob)";
      proc.on();
      bool onlineStateTransitions = false;
      edm::EventProcessor::StatusCode status = proc->runToCompletion(onlineStateTransitions);
      if (status == edm::EventProcessor::epSignal) {
        returnCode = edm::errors::CaughtSignal;
      }
      proc.off();

      context = "Calling endJob";
      proc->endJob();
    }
    catch (cms::Exception& e) {
      throw;
    }
    // The functions in the following catch blocks throw an edm::Exception
    catch(std::bad_alloc& bda) {
      edm::convertException::badAllocToEDM();
    }
    catch (std::exception& e) {
      edm::convertException::stdToEDM(e);
    }
    catch(std::string& s) {
      edm::convertException::stringToEDM(s);
    }
    catch(char const* c) {
      edm::convertException::charPtrToEDM(c);
    }
    catch (...) {
      edm::convertException::unknownToEDM();
    }
  }
  // All exceptions which are not handled before propagating
  // into main will get caught here.
  catch (cms::Exception& ex) {
    returnCode = ex.returnCode();
    if (!context.empty()) {
      if (alwaysAddContext) {
        ex.addContext(context);
      }
      else if (ex.context().empty()) {
        ex.addContext(context);
      }
    }
    if (!ex.alreadyPrinted()) {
      if (jobRep.get() != 0) {
        edm::printCmsException(ex, &(jobRep->get()), returnCode);
      }
      else {
        edm::printCmsException(ex);
      }
    }
  }
  // Disable Root Error Handler.
  SetErrorHandler(DefaultErrorHandler);
  return returnCode;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: ilodor/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    // Switches and options
    std::string type;
    std::string source;
    std::string save_path;
    std::string homography_method {"robust"};
    std::string camera_model {"pinhole"};
    int chessboard_width {6};
    int chessboard_height {9};
    double square_length {1.0};
    std::string config_file;
    std::string config_key;
    bool config_used {false};
    
    // Visible program options
    po::options_description visible_options("OPTIONS");

    // Component sub-type
    std::unordered_map<std::string, char> type_hash;
    type_hash["camera"] = 'a';
    type_hash["homography"] = 'b';
    
    // Homography estimation method
    std::unordered_map<std::string, HomographyGenerator::EstimationMethod> homo_meth_hash;
    homo_meth_hash["robust"] = HomographyGenerator::EstimationMethod::ROBUST;
    homo_meth_hash["regular"] = HomographyGenerator::EstimationMethod::REGULAR;
    homo_meth_hash["exact"] = HomographyGenerator::EstimationMethod::EXACT;
    
    // Camera calibration method
    std::unordered_map<std::string,CameraCalibrator::CameraModel> camera_model_hash;
    camera_model_hash["pinhole"] = CameraCalibrator::CameraModel::PINHOLE;
    camera_model_hash["fisheye"] = CameraCalibrator::CameraModel::FISHEYE;

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description config("CONFIGURATION");
        config.add_options()
                ("calibration-path,f", po::value<std::string>(&save_path),
                "The base configuration file location.\n"
                "The timestamp of the calibration will be prepended to th name."
                "If not provided, the calibration info will be printed to STDOUT.")
                ("homography-method", po::value<std::string>(&homography_method),
                "Homography estimation method.\n\n"
                "Values:\n"
                "  robust (default): RANSAC-based robust estimation method (automatic outlier rejection).\n"
                "  regular: Best-fit using all data points.\n"
                "  exact: Compute the homography that fits four points. Useful when frames contain know fiducial marks.\n")
                ("camera-model", po::value<std::string>(&camera_model),
                "Model used for camera calibration.\n\n"
                "Values:\n"
                "  pinhole (default): Pinhole camera model.\n"
                "  fisheye: Fisheye camera model (ultra wide-angle lens with pronounced radial distortion.\n")
                ("chessboard-height,h", po::value<int>(&chessboard_height),
                "The number of vertical black squares in the chessboard used for calibration.\n")
                ("chessboard-width,w", po::value<int>(&chessboard_width),
                "The number of horizontal black squares in the chessboard used for calibration.\n")
                ("square-width,W", po::value<double>(&square_length),
                "The length/width of a single chessboard square in meters.\n")
                ("config-file,c", po::value<std::string>(&config_file), "Configuration file.")
                ("config-key,k", po::value<std::string>(&config_key), "Configuration key.")
                ;

        po::options_description hidden("HIDDEN OPTIONS");
        hidden.add_options()
                ("type", po::value<std::string>(&type),
                "Type of frame calibrator to use.\n\n"
                "Values:\n"
                "  camera: Generate calibration parameters (camera matrix and distortion coefficients).\n"
                "  homography: Generate homography transform between pixels and world units.")
                
                ("source", po::value<std::string>(&source),
                "The name of the SOURCE that supplies images on which to perform background subtraction."
                "The server must be of type SMServer<SharedCVMatHeader>\n")
                ;

        po::positional_options_description positional_options;
        positional_options.add("type", 1);
        positional_options.add("source", 1);

        visible_options.add(options).add(config);

        po::options_description all_options("All options");
        all_options.add(options).add(config).add(hidden);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat calibrator version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("type")) {
            printUsage(visible_options);
            std::cerr << oat::Error("A TYPE must be specified.\n");
            return -1;
        }

        if (!variable_map.count("source")) {
            printUsage(visible_options);
            std::cerr << oat::Error("A SOURCE must be specified.\n");
            return -1;
        }

        if (!variable_map.count("calibration-path")) {
            save_path = bfs::current_path().string();
        }
        
        // Check to see that homography-method is valid
        if (homo_meth_hash.find(homography_method) == homo_meth_hash.end()) {
            printUsage(visible_options);
            std::cerr << oat::Error("Unrecognized homography-method.\n");
            return -1;
        }
        
        // Check that chessboard height and width are valid
        if (type_hash[type] == 'a' && (chessboard_height < 2 || chessboard_width < 2)) {
            printUsage(visible_options);
            std::cerr << oat::Error("Camera calibration requires chessboard to be at least 2x2.\n");
            return -1;
        }

        if ((variable_map.count("config-file") && !variable_map.count("config-key")) ||
                (!variable_map.count("config-file") && variable_map.count("config-key"))) {
            printUsage(visible_options);
            std::cerr << oat::Error("A configuration file must be supplied with a corresponding config-key.\n");
            return -1;
        } else if (variable_map.count("config-file")) {
            config_used = true;
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return -1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.\n");
        return -1;
    }

    // Create component
    std::shared_ptr<Calibrator> calibrator;

    // Refine component type
    switch (type_hash[type]) {
        case 'a':
        {
            auto chessboard_size = cv::Size(chessboard_height, chessboard_width);
            auto model =camera_model_hash.at(camera_model);
            calibrator = std::make_shared<CameraCalibrator>(source, model, chessboard_size, square_length);
            break;
        }
        case 'b':
        {
            auto meth = homo_meth_hash.at(homography_method);
            calibrator = std::make_shared<HomographyGenerator>(source, meth);
            break;
        }
        default:
        {
            printUsage(visible_options);
            std::cerr << oat::Error("Invalid TYPE specified.\n");
            return -1;
        }
    }

    try{

        if (config_used)
            calibrator->configure(config_file, config_key);

        // Generate the save path and check validity
        calibrator->generateSavePath(save_path);

        // Tell user
        std::cout << oat::whoMessage(calibrator->name(),
                "Listening to source " + oat::sourceText(source) + ".\n")
                << oat::whoMessage(calibrator->name(),
                "Press CTRL+C to exit.\n");

        // Infinite loop until ctrl-c or end of stream signal
        run(calibrator);

        // Tell user
        std::cout << oat::whoMessage(calibrator->name(), "Exiting.\n");

        // Exit success
        return 0;

    } catch (const cpptoml::parse_exception& ex) {
        std::cerr << oat::whoError(calibrator->name(),
                     "Failed to parse configuration file "
                     + config_file + "\n")
                  << oat::whoError(calibrator->name(), ex.what())
                  << "\n";
    } catch (const std::runtime_error& ex) {
        std::cerr << oat::whoError(calibrator->name(),ex.what())
                  << "\n";
    } catch (const cv::Exception& ex) {
        std::cerr << oat::whoError(calibrator->name(), ex.what())
                  << "\n";
    } catch (...) {
        std::cerr << oat::whoError(calibrator->name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: 410pfeliciano/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    // The image source to which the viewer will be attached
    std::vector<std::string> position_sources;
    std::string frame_source;
    std::string frame_sink;
    bool print_region = false;
    bool print_timestamp = false;
    bool print_sample_number = false;
    bool encode_sample_number = false;

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description configuration("CONFIGURATION");
        configuration.add_options()
                ("position-sources,p", po::value< std::vector<std::string> >()->multitoken(),
                "The name of position SOURCE(s) used to draw object position markers.\n")
                ("timestamp,t", "Write the current date and time on each frame.\n")
                ("sample,s", "Write the frame sample number on each frame.\n")
                ("sample-code,S", "Write the binary encoded sample on the corner of each frame.\n")
                ("region,R", "Write region information on each frame "
                "if there is a position stream that contains it.\n")
                ;

        po::options_description hidden("POSITIONAL OPTIONS");
        hidden.add_options() ("framesource", po::value<std::string>(&frame_source),
                "The name of the server that supplies images to decorate."
                "The server must be of type SMServer<SharedCVMatHeader>\n")
                ("framesink", po::value<std::string>(&frame_sink),
                "The name of the sink to which decorated images will be published."
                "The server must be of type SMServer<SharedCVMatHeader>\n")
                ;

        po::positional_options_description positional_options;

        // If not overridden by explicit --imagesource or --sink,
        // last positional arguments are imagesource and sink in that order
        positional_options.add("framesource", 1);
        positional_options.add("framesink", 1);

        po::options_description visible_options("OPTIONS");
        visible_options.add(options).add(configuration);

        po::options_description all_options("ALL OPTIONS");
        all_options.add(visible_options).add(hidden);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat Decorator, version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("framesource")) {
            printUsage(visible_options);
            std::cout <<  oat::Error("At least a single FRAME_SOURCE must be specified. \n");
            return -1;
        }

        if (!variable_map.count("framesink")) {
            printUsage(visible_options);
            std::cout <<  oat::Error("At least a single FRAME_SINK must be specified.\n");
            return -1;
        }

        if (variable_map.count("position-sources")) {
            position_sources = variable_map["position-sources"].as< std::vector<std::string> >();
        }

        if (variable_map.count("timestamp")) {
            print_timestamp = true;
        }

        if (variable_map.count("sample")) {
            print_sample_number = true;
        }

        if (variable_map.count("sample-code")) {
            encode_sample_number = true;
        }

        if (variable_map.count("region")) {
            print_region = true;
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return -1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.\n");
        return -1;
    }

    // Make the decorator
    auto decorator = std::make_shared<oat::Decorator>(position_sources, frame_source, frame_sink);
    decorator->set_print_timestamp(print_timestamp);
    decorator->set_print_sample_number(print_sample_number);
    decorator->set_encode_sample_number(encode_sample_number);
    decorator->set_print_region(print_region);

     // Tell user
    std::cout << oat::whoMessage(decorator->name(),
            "Listening to source " + oat::sourceText(frame_source) + ".\n")
            << oat::whoMessage(decorator->name(),
            "Steaming to sink " + oat::sinkText(frame_sink) + ".\n")
            << oat::whoMessage(decorator->name(),
            "Press CTRL+C to exit.\n");

    try {

        // Infinite loop until ctrl-c or end of stream signal
        run(decorator);

        // Tell user
        std::cout << oat::whoMessage(decorator->name(), "Exiting.\n");

        // Exit
        return 0;

    } catch (const std::runtime_error &ex) {
        std::cerr << oat::whoError(decorator->name(), ex.what()) << "\n";
    } catch (const cv::Exception &ex) {
        std::cerr << oat::whoError(decorator->name(), ex.what()) << "\n";
    } catch (const boost::interprocess::interprocess_exception &ex) {
        std::cerr << oat::whoError(decorator->name(), ex.what()) << "\n";
    } catch (...) {
        std::cerr << oat::whoError(decorator->name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #10
0
ファイル: tool.cpp プロジェクト: mindcrusher11/mongo
    int Tool::main( int argc , char ** argv ) {
        static StaticObserver staticObserver;

        cmdLine.prealloc = false;

        // The default value may vary depending on compile options, but for tools
        // we want durability to be disabled.
        cmdLine.dur = false;

#if( BOOST_VERSION >= 104500 )
    boost::filesystem::path::default_name_check( boost::filesystem2::no_check );
#else
    boost::filesystem::path::default_name_check( boost::filesystem::no_check );
#endif

        _name = argv[0];

        /* using the same style as db.cpp */
        int command_line_style = (((po::command_line_style::unix_style ^
                                    po::command_line_style::allow_guessing) |
                                   po::command_line_style::allow_long_disguise) ^
                                  po::command_line_style::allow_sticky);
        try {
            po::options_description all_options("all options");
            all_options.add(*_options).add(*_hidden_options);

            po::store( po::command_line_parser( argc , argv ).
                       options(all_options).
                       positional( _positonalOptions ).
                       style(command_line_style).run() , _params );

            po::notify( _params );
        }
        catch (po::error &e) {
            cerr << "ERROR: " << e.what() << endl << endl;
            printHelp(cerr);
            ::_exit(EXIT_BADOPTIONS);
        }

        // hide password from ps output
        for (int i=0; i < (argc-1); ++i) {
            if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")) {
                char* arg = argv[i+1];
                while (*arg) {
                    *arg++ = 'x';
                }
            }
        }

        if ( _params.count( "help" ) ) {
            printHelp(cout);
            ::_exit(0);
        }

        if ( _params.count( "version" ) ) {
            printVersion(cout);
            ::_exit(0);
        }

        if ( _params.count( "verbose" ) ) {
            logLevel = 1;
        }

        for (string s = "vv"; s.length() <= 10; s.append("v")) {
            if (_params.count(s)) {
                logLevel = s.length();
            }
        }


#ifdef MONGO_SSL
        if (_params.count("ssl")) {
            mongo::cmdLine.sslOnNormalPorts = true;
        }
#endif

        preSetup();

        bool useDirectClient = hasParam( "dbpath" );

        if ( ! useDirectClient ) {
            _host = "127.0.0.1";
            if ( _params.count( "host" ) )
                _host = _params["host"].as<string>();

            if ( _params.count( "port" ) )
                _host += ':' + _params["port"].as<string>();

            if ( _noconnection ) {
                // do nothing
            }
            else {
                string errmsg;

                ConnectionString cs = ConnectionString::parse( _host , errmsg );
                if ( ! cs.isValid() ) {
                    cerr << "invalid hostname [" << _host << "] " << errmsg << endl;
                    ::_exit(-1);
                }

                _conn = cs.connect( errmsg );
                if ( ! _conn ) {
                    cerr << "couldn't connect to [" << _host << "] " << errmsg << endl;
                    ::_exit(-1);
                }

                (_usesstdout ? cout : cerr ) << "connected to: " << _host << endl;
            }

        }
        else {
            if ( _params.count( "directoryperdb" ) ) {
                directoryperdb = true;
            }
            verify( lastError.get( true ) );

            if (_params.count("journal")){
                cmdLine.dur = true;
            }

            Client::initThread("tools");
            _conn = new DBDirectClient();
            _host = "DIRECT";
            static string myDbpath = getParam( "dbpath" );
            dbpath = myDbpath.c_str();
            try {
                acquirePathLock();
            }
            catch ( DBException& ) {
                cerr << endl << "If you are running a mongod on the same "
                     "path you should connect to that instead of direct data "
                     "file access" << endl << endl;
                dbexit( EXIT_CLEAN );
                ::_exit(-1);
            }

            FileAllocator::get()->start();

            dur::startup();
        }

        if ( _params.count( "db" ) )
            _db = _params["db"].as<string>();

        if ( _params.count( "collection" ) )
            _coll = _params["collection"].as<string>();

        if ( _params.count( "username" ) )
            _username = _params["username"].as<string>();

        if ( _params.count( "password" )
                && ( _password.empty() ) ) {
            _password = askPassword();
        }

        if (_params.count("ipv6"))
            enableIPv6();

        int ret = -1;
        try {
            ret = run();
        }
        catch ( DBException& e ) {
            cerr << "assertion: " << e.toString() << endl;
            ret = -1;
        }
	catch(const boost::filesystem::filesystem_error &fse) {
	    /*
	      https://jira.mongodb.org/browse/SERVER-2904

	      Simple tools that don't access the database, such as
	      bsondump, aren't throwing DBExceptions, but are throwing
	      boost exceptions.

	      The currently available set of error codes don't seem to match
	      boost documentation.  boost::filesystem::not_found_error
	      (from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm)
	      doesn't seem to exist in our headers.  Also, fse.code() isn't
	      boost::system::errc::no_such_file_or_directory when this
	      happens, as you would expect.  And, determined from
	      experimentation that the command-line argument gets turned into
	      "\\?" instead of "/?" !!!
	     */
#if defined(_WIN32)
	    if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/
		(fse.path1() == "\\?"))
		printHelp(cerr);
	    else
#endif // _WIN32
		cerr << "error: " << fse.what() << endl;

	    ret = -1;
	}

        if ( currentClient.get() )
            currentClient.get()->shutdown();

        if ( useDirectClient )
            dbexit( EXIT_CLEAN );
        ::_exit(ret);
    }
コード例 #11
0
int main( int argc, char * argv[] ) {
    char description[10000] = "";
    char color_str[10];
    strcat(description,
"usage:\n"
"   hi [options] REGEX FOREGROUND_COLOR BACKGROUND_COLOR\\\n"
"       [ REGEX FOREGROUND_COLOR BACKGROUND_COLOR ...]\n"
"\n"
"description:\n"
"   'hi' highlights text from standard in according to the supplied regular\n"
"   expressions and color arguments.  The regular expressions are Perl style.\n"
"\n"
"   e.g.\n"
"   % echo hello mother, hello father | hi 'hel*o' RED NONE\n"
"   ");
    set_colors_str(RED,NONE,color_str);
    strcat(description, color_str);
    strcat(description,"hello");
    set_colors_str(NONE,NONE,color_str);
    
    strcat(description, color_str);
    strcat(description," mother, ");
    
    set_colors_str(RED,NONE,color_str);
    strcat(description, color_str);
    strcat(description,"hello");
    set_colors_str(NONE,NONE,color_str);
    
    strcat(description, color_str);
    strcat(description," father \n");
    strcat(description,
"\n"
"   NOTE: To view these colors in 'less' add this line to your ~/.aliases file\n"
"       setenv LESS \"$LESS -R\"\n"
"\n"
"   The available foreground and background colors are:\n");
    strcat(description, color_swatch());
    strcat(description,
"\n"
"author:\n"
"   Ross Rogers, 2009.08.20\n"
"\n"
"options");
    
    namespace po = boost::program_options;
    po::options_description opts_desc( description );
    
    opts_desc.add_options()
        ("help", "show this help message and exit")
        ("dbg", "enable debug printouts")
    ;
    
    string hex_nums_desc = "Alternate colors on every group of 4 hex numbers like ";
    set_colors_str(CYAN,NONE,color_str);
    string cyan = color_str;
    set_colors_str(NONE,NONE,color_str);
    string none = color_str;
    hex_nums_desc += "0x"+cyan+"dead"+none+"beef"+cyan+"aced"+none+"face";
    opts_desc.add_options()
        ("hex_nums", hex_nums_desc.c_str())
    ;
    
    opts_desc.add_options()
        ("ignore-case,i", "Ignore case on all regular expressions.\n")
    ;
    
    po::options_description hidden_desc( "" );
    hidden_desc.add_options()
        ("h", "")
        ("input", po::value<vector<string> >()->composing(), "" )
    ;
    
    po::options_description all_options( description );
    all_options
        .add(opts_desc)
        .add(hidden_desc)
    ;
    
    po::positional_options_description positional_opts;
    positional_opts.add("input",-1);
    
    po::variables_map vm;
    po::parsed_options parsed = po::command_line_parser(argc, argv)
        .options(all_options)
        .positional(positional_opts)
        .allow_unregistered()
        .run();
    
    po::store(parsed, vm );
    po::notify(vm);
    
    if (argc == 1 || vm.count("help") || vm.count("h")) {
        cout << opts_desc << "\n";
        return 0;
    }
    
    bool dbg = false;
    if (vm.count("dbg")) {
        dbg = true;
    }
    
    vector<Filter*> build_filters;
    if (vm.count("input") || vm.count("hex_nums") ) {
        vector<string> v;
        if (vm.count("input") > 0) {
            v = vm["input"].as<vector<string> >();
        }
        if (vm.count("hex_nums")) {
            v.push_back("[a-fA-F0-9]{4}(?=(?:(?:_?[a-fA-F0-9]{4}){2}){0,18}(?:_?[a-fA-F0-9]{4})($|[^_a-fA-F0-9$]))");
            v.push_back("CYAN");
            v.push_back("NONE");
        }
        Filter *f;
        // add a default benign filter at the beginning
        f = new Filter;
        f->regex = NULL;
        f->foreground = NONE;
        f->background = NONE;
        build_filters.push_back(f);
        for(unsigned int i = 0; i < v.size(); i++) {
            switch ( i%3 ) {
              case 0:
                f = new Filter;
                if (dbg) {
                    cout << "hi dbg: Constructing filter with regex string'"
                        <<v[i]<<"'"<<endl;
                }
                f->regex = new boost::regex(v[i],(vm.count("ignore-case") >0 ? (boost::regex_constants::normal + boost::regex_constants::icase) : boost::regex_constants::normal));
                break;
              case 1:
                f->foreground = interpret_color(v[i].c_str());
                break;
              case 2:
                f->background = interpret_color(v[i].c_str());
                build_filters.push_back(f);
                break;
            }
        }
    }
    
    // Simplifying vector to c-style array for speed, since iterating through
    // vectors showed up near the top of a gprof profile.
    unsigned char filters_size = build_filters.size();
    Filter **filters = new Filter*[filters_size];
    copy( build_filters.begin(), build_filters.end(), filters);
    
    string input_line;
    unsigned int char_filter_indices_size = 0;
    int *char_filter_indices = NULL;
    while ( cin && !cin.eof()) {
        getline(cin,input_line,'\n');
        
        bool found_regex_match = false;
        
        if (char_filter_indices_size < input_line.size()) {
            char_filter_indices_size = input_line.size();
            delete [] char_filter_indices;
            char_filter_indices = new int[char_filter_indices_size];
        }
        for ( unsigned int c_i = 0; c_i < char_filter_indices_size; c_i++ ) {
            char_filter_indices[c_i] = 0;
        }
        
        for ( int f_i = 1; f_i < filters_size; f_i++ ) {
            boost::regex *re = filters[f_i]->regex;
            boost::cmatch matches;
            const char *current_str = input_line.c_str();
            const char *beg_line_adx = current_str;
            
            int watchdog = 0;
            
            while (boost::regex_search(current_str,matches,*re)) {
                if (!found_regex_match) found_regex_match = true;
                
                int begin_idx = (long)matches[0].first-(long)beg_line_adx;
                int end_idx = (long)matches[0].second-(long)beg_line_adx;
                for ( int c_i = begin_idx; c_i < end_idx ; c_i++ ) {
                    char_filter_indices[c_i] = f_i;
                }
                
                if (current_str == matches[0].second ) {
                    // found a zero width match, advancing 1 char.
                    current_str = matches[0].second +1;
                    if ( '\0' == *current_str) {
                        break;
                    }
                } else {
                    current_str = matches[0].second;
                }
                watchdog += 1;
                if (watchdog == 0x100) {
                    cerr << "hi ERROR: looped "<<watchdog<<" times on regex filter number "<< f_i-1<<endl;
                    return -1;
                }
            }
        }
        
        if (found_regex_match) {
            const char *c = input_line.c_str();
            int char_index = 0;
            Filter *cur_filter = NULL;
            int cur_filter_index = 0;
            while ( *c ) {
                if ( cur_filter_index != char_filter_indices[char_index] ) {
                    cur_filter_index = char_filter_indices[char_index];
                    cur_filter = filters[cur_filter_index];
                    set_console_colors(cur_filter->foreground,cur_filter->background);
                }
                putchar( *c);
                c += 1;
                char_index += 1;
            }
            reset_console_colors();
            puts("");
        } else {
            puts(input_line.c_str());
        }
        
    }
}
コード例 #12
0
boost::program_options::options_description generic_options::visible_options() const
{
    return all_options();
}
コード例 #13
0
ファイル: cmsRun.cpp プロジェクト: tuos/cmssw
int main(int argc, char* argv[])
{
// NOTE: MacOs X has a lower rlimit for opened file descriptor than Linux (256
// in Snow Leopard vs 512 in SLC5). This is a problem for some of the workflows
// that open many small root datafiles.  Notice that this is safe to do also
// for Linux, but we agreed not to change the behavior there for the moment.
// Also the limits imposed by ulimit are not affected and still apply, if
// there.
#ifdef __APPLE__
  struct rlimit limits;
  getrlimit(RLIMIT_NOFILE, &limits);
  limits.rlim_cur = (OPEN_MAX < limits.rlim_max) ? OPEN_MAX : limits.rlim_max;
  setrlimit(RLIMIT_NOFILE, &limits);
#endif

  // We must initialize the plug-in manager first
  try {
    edmplugin::PluginManager::configure(edmplugin::standard::config());
  } catch(const std::exception& e) {
    std::cerr << e.what() << std::endl;
    return 1;
  }
  
  // Decide whether to use the multi-thread or single-thread message logger
  //    (Just walk the command-line arguments, since the boost parser will
  //    be run below and can lead to error messages which should be sent via
  //    the message logger)
  bool multiThreadML = false;
  for (int i=0; i<argc; ++i) {
    if ( (std::strncmp (argv[i],"-t", 20) == 0) ||
         (std::strncmp (argv[i],"--multithreadML", 20) == 0) )
    { multiThreadML = true; 
      break; 
    }
  } 
 
  // TEMPORARY -- REMOVE AT ONCE!!!!!
  // if ( multiThreadML ) std::cerr << "\n\n multiThreadML \n\n";
  
  // Load the message service plug-in
  boost::shared_ptr<edm::Presence> theMessageServicePresence;

  if (multiThreadML)
  {
    try {
      theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
          makePresence("MessageServicePresence").release());
    } catch(cms::Exception& e) {
      std::cerr << e.what() << std::endl;
      return 1;
    }
  } else {
    try {
      theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
          makePresence("SingleThreadMSPresence").release());
    } catch(cms::Exception& e) {
      std::cerr << e.what() << std::endl;
      return 1;
    }
  }
  
  //
  // Specify default services to be enabled with their default parameters.
  // 
  // The parameters for these can be overridden from the configuration files.
  std::vector<std::string> defaultServices;
  defaultServices.reserve(6);
  defaultServices.push_back("MessageLogger");
  defaultServices.push_back("InitRootHandlers");
#ifdef linux
  defaultServices.push_back("EnableFloatingPointExceptions");
#endif
  defaultServices.push_back("UnixSignalService");
  defaultServices.push_back("AdaptorConfig");
  defaultServices.push_back("SiteLocalConfigService");

  // These cannot be overridden from the configuration files.
  // An exception will be thrown if any of these is specified there.
  std::vector<std::string> forcedServices;
  forcedServices.reserve(1);
  forcedServices.push_back("JobReportService");

  std::string descString(argv[0]);
  descString += " [options] [--";
  descString += kParameterSetOpt;
  descString += "] config_file \nAllowed options";
  boost::program_options::options_description desc(descString);
  
  desc.add_options()
    (kHelpCommandOpt, "produce help message")
    (kParameterSetCommandOpt, boost::program_options::value<std::string>(), "configuration file")
    (kJobreportCommandOpt, boost::program_options::value<std::string>(),
    	"file name to use for a job report file: default extension is .xml")
    (kEnableJobreportCommandOpt, 
    	"enable job report files (if any) specified in configuration file")
    (kJobModeCommandOpt, boost::program_options::value<std::string>(),
    	"Job Mode for MessageLogger defaults - default mode is grid")
    (kMultiThreadMessageLoggerOpt,
    	"MessageLogger handles multiple threads - default is single-thread")
    (kStrictOpt, "strict parsing");

  // anything at the end will be ignored, and sent to python
  boost::program_options::positional_options_description p;
  p.add(kParameterSetOpt, 1).add(kPythonOpt, -1);

  // This --fwk option is not used anymore, but I'm leaving it around as
  // it might be useful again in the future for code development
  // purposes.  We originally used it when implementing the boost
  // state machine code.
  boost::program_options::options_description hidden("hidden options");
  hidden.add_options()("fwk", "For use only by Framework Developers")
    (kPythonOpt, boost::program_options::value< std::vector<std::string> >(), 
     "options at the end to be passed to python");
  
  boost::program_options::options_description all_options("All Options");
  all_options.add(desc).add(hidden);

  boost::program_options::variables_map vm;
  try {
    store(boost::program_options::command_line_parser(argc,argv).options(all_options).positional(p).run(),vm);
    notify(vm);
  } catch(boost::program_options::error const& iException) {
    edm::LogError("FwkJob") << "Exception from command line processing: " << iException.what();
    edm::LogSystem("CommandLineProcessing") << "Exception from command line processing: " << iException.what() << "\n";
    return 7000;
  }
    
  if(vm.count(kHelpOpt)) {
    std::cout << desc <<std::endl;
    if(!vm.count(kParameterSetOpt)) edm::HaltMessageLogging();
    return 0;
  }
  
  if(!vm.count(kParameterSetOpt)) {
    std::string shortDesc("ConfigFileNotFound");
    std::ostringstream longDesc;
    longDesc << "cmsRun: No configuration file given.\n"
	     << "For usage and an options list, please do '"
	     << argv[0]
	     <<  " --"
	     << kHelpOpt
	     << "'.";
    int exitCode = 7001;
    edm::LogAbsolute(shortDesc) << longDesc.str() << "\n";
    edm::HaltMessageLogging();
    return exitCode;
  }

#ifdef CHANGED_FROM
  if(!vm.count(kParameterSetOpt)) {
    std::string shortDesc("ConfigFileNotFound");
    std::ostringstream longDesc;
    longDesc << "No configuration file given \n"
	     <<" please do '"
	     << argv[0]
	     <<  " --"
	     << kHelpOpt
	     << "'.";
    int exitCode = 7001;
    jobRep->reportError(shortDesc, longDesc.str(), exitCode);
    edm::LogSystem(shortDesc) << longDesc.str() << "\n";
    return exitCode;
  }
#endif

  //
  // Decide whether to enable creation of job report xml file 
  //  We do this first so any errors will be reported
  // 
  std::string jobReportFile;
  if (vm.count("jobreport")) {
    jobReportFile = vm["jobreport"].as<std::string>();
  } else if (vm.count("enablejobreport")) {
    jobReportFile = "FrameworkJobReport.xml";
  } 
  std::auto_ptr<std::ofstream> jobReportStreamPtr = std::auto_ptr<std::ofstream>(jobReportFile.empty() ? 0 : new std::ofstream(jobReportFile.c_str()));
  //
  // Make JobReport Service up front
  // 
  //NOTE: JobReport must have a lifetime shorter than jobReportStreamPtr so that when the JobReport destructor
  // is called jobReportStreamPtr is still valid
  std::auto_ptr<edm::JobReport> jobRepPtr(new edm::JobReport(jobReportStreamPtr.get()));  
  boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::JobReport> > jobRep( new edm::serviceregistry::ServiceWrapper<edm::JobReport>(jobRepPtr) );
  edm::ServiceToken jobReportToken = 
    edm::ServiceRegistry::createContaining(jobRep);
  
  std::string fileName(vm[kParameterSetOpt].as<std::string>());
  boost::shared_ptr<edm::ProcessDesc> processDesc;
  try {
    processDesc = edm::readConfig(fileName, argc, argv);
  }
  catch(cms::Exception& iException) {
    std::string shortDesc("ConfigFileReadError");
    std::ostringstream longDesc;
    longDesc << "Problem with configuration file " << fileName
             <<  "\n" << iException.what();
    int exitCode = 7002;
    jobRep->get().reportError(shortDesc, longDesc.str(), exitCode);
    edm::LogSystem(shortDesc) << longDesc.str() << "\n";
    return exitCode;
  }

  processDesc->addServices(defaultServices, forcedServices);
  //
  // Decide what mode of hardcoded MessageLogger defaults to use 
  // 
  if (vm.count("mode")) {
    std::string jobMode = vm["mode"].as<std::string>();
    edm::MessageDrop::instance()->jobMode = jobMode;
  }  

  if(vm.count(kStrictOpt))
  {
    //edm::setStrictParsing(true);
    edm::LogSystem("CommandLineProcessing") << "Strict configuration processing is now done from python";
  }
 
  // Now create and configure the services
  //
  EventProcessorWithSentry proc;
  int rc = -1; // we should never return this value!
  try {
    std::auto_ptr<edm::EventProcessor> 
	procP(new 
	      edm::EventProcessor(processDesc, jobReportToken, 
			     edm::serviceregistry::kTokenOverrides));
    EventProcessorWithSentry procTmp(procP);
    proc = procTmp;
    proc->beginJob();
    if(!proc->forkProcess(jobReportFile)) {
      return 0;
    }
    proc.on();
    bool onlineStateTransitions = false;
    proc->runToCompletion(onlineStateTransitions);
    proc.off();
    proc->endJob();
    rc = 0;
    // Disable Root Error Handler so we do not throw because of ROOT errors.
    edm::ServiceToken token = proc->getToken();
    edm::ServiceRegistry::Operate operate(token);
    edm::Service<edm::RootHandlers> rootHandler;
    rootHandler->disableErrorHandler();
  }
  catch (edm::Exception& e) {
    rc = e.returnCode();
    edm::printCmsException(e, kProgramName, &(jobRep->get()), rc);
  }
  catch (cms::Exception& e) {
    rc = 8001;
    edm::printCmsException(e, kProgramName, &(jobRep->get()), rc);
  }
  catch(std::bad_alloc& bda) {
    rc = 8004;
    edm::printBadAllocException(kProgramName, &(jobRep->get()), rc);
  }
  catch (std::exception& e) {
    rc = 8002;
    edm::printStdException(e, kProgramName, &(jobRep->get()), rc);
  }
  catch (...) {
    rc = 8003;
    edm::printUnknownException(kProgramName, &(jobRep->get()), rc);
  }
  // Disable Root Error Handler again, just in case an exception
  // caused the above disabling of the handler to be bypassed.
  SetErrorHandler(DefaultErrorHandler);
  return rc;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: ifzz/bitmonero
int main(int argc, char const * argv[])
{
  try {

    _note_c("dbg/main", "Begin of main()");
    // TODO parse the debug options like set log level right here at start

    tools::sanitize_locale();

    epee::string_tools::set_module_name_and_folder(argv[0]);

    // Build argument description
    po::options_description all_options("All");
    po::options_description hidden_options("Hidden");
    po::options_description visible_options("Options");
    po::options_description core_settings("Settings");
    po::positional_options_description positional_options;
    {
      bf::path default_data_dir = daemonizer::get_default_data_dir();
      bf::path default_testnet_data_dir = {default_data_dir / "testnet"};

      // Misc Options

      command_line::add_arg(visible_options, command_line::arg_help);
      command_line::add_arg(visible_options, command_line::arg_version);
      command_line::add_arg(visible_options, daemon_args::arg_os_version);
      bf::path default_conf = default_data_dir / std::string(CRYPTONOTE_NAME ".conf");
      command_line::add_arg(visible_options, daemon_args::arg_config_file, default_conf.string());
      command_line::add_arg(visible_options, command_line::arg_test_dbg_lock_sleep);
      cryptonote::core::init_options(core_settings);

      // Settings
      bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
      command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string());
      command_line::add_arg(core_settings, daemon_args::arg_log_level);

      daemonizer::init_options(hidden_options, visible_options);
      daemonize::t_executor::init_options(core_settings);

      // Hidden options
      command_line::add_arg(hidden_options, daemon_args::arg_command);

      visible_options.add(core_settings);
      all_options.add(visible_options);
      all_options.add(hidden_options);

      // Positional
      positional_options.add(daemon_args::arg_command.name, -1); // -1 for unlimited arguments
    }

    // Do command line parsing
    po::variables_map vm;
    bool ok = command_line::handle_error_helper(visible_options, [&]()
    {
      boost::program_options::store(
        boost::program_options::command_line_parser(argc, argv)
          .options(all_options).positional(positional_options).run()
      , vm
      );

      return true;
    });
    if (!ok) return 1;

    if (command_line::get_arg(vm, command_line::arg_help))
    {
      std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL << ENDL;
      std::cout << "Usage: " + std::string{argv[0]} + " [options|settings] [daemon_command...]" << std::endl << std::endl;
      std::cout << visible_options << std::endl;
      return 0;
    }

    // Monero Version
    if (command_line::get_arg(vm, command_line::arg_version))
    {
      std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
      return 0;
    }

    // OS
    if (command_line::get_arg(vm, daemon_args::arg_os_version))
    {
      std::cout << "OS: " << tools::get_os_version_string() << ENDL;
      return 0;
    }

    epee::g_test_dbg_lock_sleep = command_line::get_arg(vm, command_line::arg_test_dbg_lock_sleep);

    std::string db_type = command_line::get_arg(vm, command_line::arg_db_type);

    // verify that blockchaindb type is valid
    if(cryptonote::blockchain_db_types.count(db_type) == 0)
    {
      std::cout << "Invalid database type (" << db_type << "), available types are:" << std::endl;
      for (const auto& type : cryptonote::blockchain_db_types)
      {
        std::cout << "\t" << type << std::endl;
      }
      return 0;
    }

    bool testnet_mode = command_line::get_arg(vm, command_line::arg_testnet_on);

    auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;

    // data_dir
    //   default: e.g. ~/.bitmonero/ or ~/.bitmonero/testnet
    //   if data-dir argument given:
    //     absolute path
    //     relative path: relative to cwd

    // Create data dir if it doesn't exist
    boost::filesystem::path data_dir = boost::filesystem::absolute(
        command_line::get_arg(vm, data_dir_arg));
    tools::create_directories_if_necessary(data_dir.string());

    // FIXME: not sure on windows implementation default, needs further review
    //bf::path relative_path_base = daemonizer::get_relative_path_base(vm);
    bf::path relative_path_base = data_dir;

    std::string config = command_line::get_arg(vm, daemon_args::arg_config_file);

    boost::filesystem::path data_dir_path(data_dir);
    boost::filesystem::path config_path(config);
    if (!config_path.has_parent_path())
    {
      config_path = data_dir / config_path;
    }

    boost::system::error_code ec;
    if (bf::exists(config_path, ec))
    {
      po::store(po::parse_config_file<char>(config_path.string<std::string>().c_str(), core_settings), vm);
    }
    po::notify(vm);

    // If there are positional options, we're running a daemon command
    {
      auto command = command_line::get_arg(vm, daemon_args::arg_command);

      if (command.size())
      {
        auto rpc_ip_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_ip);
        auto rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
        if (testnet_mode)
        {
          rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_testnet_rpc_bind_port);
        }

        uint32_t rpc_ip;
        uint16_t rpc_port;
        if (!epee::string_tools::get_ip_int32_from_string(rpc_ip, rpc_ip_str))
        {
          std::cerr << "Invalid IP: " << rpc_ip_str << std::endl;
          return 1;
        }
        if (!epee::string_tools::get_xtype_from_string(rpc_port, rpc_port_str))
        {
          std::cerr << "Invalid port: " << rpc_port_str << std::endl;
          return 1;
        }

        daemonize::t_command_server rpc_commands{rpc_ip, rpc_port};
        if (rpc_commands.process_command_vec(command))
        {
          return 0;
        }
        else
        {
          std::cerr << "Unknown command" << std::endl;
          return 1;
        }
      }
    }

    // Start with log level 0
    epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);

    // Set log level
    {
      int new_log_level = command_line::get_arg(vm, daemon_args::arg_log_level);
      if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
      {
        LOG_PRINT_L0("Wrong log level value: " << new_log_level);
      }
      else if (epee::log_space::get_set_log_detalisation_level(false) != new_log_level)
      {
        epee::log_space::get_set_log_detalisation_level(true, new_log_level);
        int otshell_utils_log_level = 100 - (new_log_level * 20);
        gCurrentLogger.setDebugLevel(otshell_utils_log_level);
        LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
      }
    }

    // log_file_path
    //   default: <data_dir>/<CRYPTONOTE_NAME>.log
    //   if log-file argument given:
    //     absolute path
    //     relative path: relative to data_dir

    // Set log file
    {
      bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
      if (! vm["log-file"].defaulted())
        log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
      log_file_path = bf::absolute(log_file_path, relative_path_base);

      epee::log_space::log_singletone::add_logger(
          LOGGER_FILE
        , log_file_path.filename().string().c_str()
        , log_file_path.parent_path().string().c_str()
        );
    }

    _note_c("dbg/main", "Moving from main() into the daemonize now.");

    return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
  }
  catch (std::exception const & ex)
  {
    LOG_ERROR("Exception in main! " << ex.what());
  }
  catch (...)
  {
    LOG_ERROR("Exception in main!");
  }
  return 1;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: silky/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    std::string sink;
    std::string type;
    std::string file_path;
    double frames_per_second = 30;
    size_t index = 0;
    std::vector<std::string> config_fk;
    bool config_used = false;
    po::options_description visible_options("OPTIONAL ARGUMENTS");

    std::unordered_map<std::string, char> type_hash;
    type_hash["wcam"] = 'a';
    type_hash["gige"] = 'b';
    type_hash["file"] = 'c';
    type_hash["test"] = 'd';

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description config("CONFIGURATION");
        config.add_options()
                ("index,i", po::value<size_t>(&index),
                "Index of camera to capture images from.")
                ("file,f", po::value<std::string>(&file_path),
                "Path to video file if \'file\' is selected as the server TYPE.\n"
                "Path to image file if \'test\' is selected as the server TYPE.")
                ("fps,r", po::value<double>(&frames_per_second),
                "Frames per second. Overriden by information in configuration file if provided.")
                ("config,c", po::value<std::vector<std::string> >()->multitoken(),
                "Configuration file/key pair.")
                ;

        po::options_description hidden("HIDDEN OPTIONS");
        hidden.add_options()
                ("type", po::value<std::string>(&type), "Camera TYPE.")
                ("sink", po::value<std::string>(&sink),
                "The name of the sink through which images collected by the camera will be served.\n")
                ;

        po::positional_options_description positional_options;
        positional_options.add("type", 1);
        positional_options.add("sink", 1);

        visible_options.add(options).add(config);

        po::options_description all_options("ALL OPTIONS");
        all_options.add(options).add(config).add(hidden);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat Frame Server version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("type")) {
            printUsage(visible_options);
            std::cout << oat::Error("A TYPE must be specified. Exiting.\n");
            return -1;
        }

        if (!variable_map.count("sink")) {
            printUsage(visible_options);
            std::cout << oat::Error("A SINK must be specified. Exiting.\n");
            return -1;
        }

        if (!variable_map["config"].empty()) {

            config_fk = variable_map["config"].as<std::vector<std::string> >();

            if (config_fk.size() == 2) {
                config_used = true;
            } else {
                printUsage(visible_options);
                std::cerr << oat::Error("Configuration must be supplied as file key pair.\n");
                return -1;
            }
        }

        if ((type.compare("file") == 0 || type.compare("test") == 0 )
            && !variable_map.count("file")) {
            printUsage(visible_options);
            std::cout << oat::Error("When TYPE=file or test, a file path must be specified. Exiting.\n");
            return -1;
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return 1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.") << "\n";
    }

    // Create the specified TYPE of detector
    std::shared_ptr<oat::FrameServer> server;

    switch (type_hash[type]) {
        case 'a':
        {
            server = std::make_shared<oat::WebCam>(sink);
            break;
        }
        case 'b':
        {

#ifndef USE_FLYCAP
            std::cerr << oat::Error("Oat was not compiled with Point-Grey "
                    "flycapture support, so TYPE=gige is not available.\n");
            return -1;
#else
            server = 
                std::make_shared<oat::PGGigECam>(sink, index, frames_per_second);
#endif
            break;
        }
        case 'c':
        {
            server = 
                std::make_shared<oat::FileReader>(sink, file_path, frames_per_second);
            break;
        }
        case 'd':
        {
            server = std::make_shared<oat::TestFrame>(sink, file_path);
            break;
        }
        default:
        {
            printUsage(visible_options);
            std::cout << oat::Error("Invalid TYPE specified. Exiting.\n");
            return -1;
        }
    }

    // The business
    try {
        
        // TODO: For most of the server types, these methods don't do much or
        // nothing. Should they really be part of the FrameServer interface?
        if (config_used)
            server->configure(config_fk[0], config_fk[1]);
        else
            server->configure();


        // Tell user
        std::cout << oat::whoMessage(server->name(),
                  "Steaming to sink " + oat::sinkText(sink) + ".\n")
                  << oat::whoMessage(server->name(),
                  "Press CTRL+C to exit.\n");

        // Infinite loop until ctrl-c or end of stream signal
        run(server);

        // Tell user
        std::cout << oat::whoMessage(server->name(), "Exiting.\n");

        // Exit
        return 0;

    } catch (const cpptoml::parse_exception &ex) {
        std::cerr << oat::whoError(server->name(),
                     "Failed to parse configuration file " + config_fk[0] + "\n")
                  << oat::whoError(server->name(), ex.what()) << "\n";
    } catch (const std::runtime_error &ex) {
        std::cerr << oat::whoError(server->name(), ex.what()) << "\n";
    } catch (const cv::Exception &ex) {
        std::cerr << oat::whoError(server->name(), ex.what()) << "\n";
    } catch (const boost::interprocess::interprocess_exception &ex) {
        std::cerr << oat::whoError(server->name(), ex.what()) << "\n";
    } catch (...) {
        std::cerr << oat::whoError(server->name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #16
0
ファイル: main.cpp プロジェクト: newenclave/ferro-remote
int main( int argc, char **argv )
{
    po::options_description description("Allowed options");
    all_options( description );

    std::vector<std::string> fuse_opts_holder;
    std::vector<char *> fuse_opts;

    fuse_opts_holder.push_back( argv[0] );
//    fuse_opts_holder.push_back( "-s" );

    try {

        fr::fuse::g_opts = ( create_cmd_params( argc, argv, description ) );

    } catch( const std::exception &ex ) {
        std::cerr << "Command line error: " << ex.what( ) << "\n";
        usage( description );
        return 1;
    }

    if( fr::fuse::g_opts.count( "help" ) ) {
        usage( description );
        char help[] = "--help";

        char *p[] = { argv[0], help };


        fuse_main( 2, &p[0], (fuse_operations *)NULL );

        return 0;
    }

    if( !fr::fuse::g_opts.count( "server" ) ) {
        usage( description );
        return 2;
    }

    if( fr::fuse::g_opts.count( "foreground" ) ) {
        fuse_opts_holder.push_back( "-f" );
    }

    if( fr::fuse::g_opts.count( "debug" ) ) {
        fuse_opts_holder.push_back( "-d" );
    }

    if( fr::fuse::g_opts.count( "opt" ) ) {
        auto opts = fr::fuse::g_opts["opt"].as<std::vector<std::string > >( );
        for( auto &o: opts ) {
            fuse_opts_holder.push_back( "-o" );
            fuse_opts_holder.push_back( o );
        }
    }

    if( !fr::fuse::g_opts.count( "point" ) ) {
        usage( description );
        return 1;
    } else {
        auto p = fr::fuse::g_opts["point"].as<std::string>( );
        fuse_opts_holder.push_back( p );
    }

    for( auto &a: fuse_opts_holder ) {
        fuse_opts.push_back( &a[0] );
    }

    fuse_operations op = fr::fuse::application::set_operations( );
    fuse_main( fuse_opts.size( ), &fuse_opts[0], &op );

    return 0;
}
コード例 #17
0
ファイル: main.cpp プロジェクト: ilodor/Oat
int main(int argc, char *argv[]) {

    std::signal(SIGINT, sigHandler);

    std::string source;
    std::string file_name; //TODO: figure out if path is file or folder.
    std::string snapshot_path;
    po::options_description visible_options("OPTIONS");

    try {

        po::options_description options("INFO");
        options.add_options()
                ("help", "Produce help message.")
                ("version,v", "Print version information.")
                ;

        po::options_description config("CONFIGURATION");
        config.add_options()
                ("snapshot-path,f", po::value<std::string>(&snapshot_path),
                "The path to which in which snapshots will be saved."
                "If a folder is designated, the base file name will be SOURCE."
                "The timestamp of the snapshot will be prepended to the file name."
                "Defaults to the current directory.")
                ;

        po::options_description hidden("HIDDEN OPTIONS");
        hidden.add_options()
                ("source", po::value<std::string>(&source),
                "The name of the frame SOURCE that supplies frames to view.\n")
                ;

        po::positional_options_description positional_options;
        positional_options.add("source", -1);

        po::options_description all_options("ALL OPTIONS");
        all_options.add(options).add(config).add(hidden);

        visible_options.add(options).add(config);

        po::variables_map variable_map;
        po::store(po::command_line_parser(argc, argv)
                .options(all_options)
                .positional(positional_options)
                .run(),
                variable_map);
        po::notify(variable_map);

        // Use the parsed options
        if (variable_map.count("help")) {
            printUsage(visible_options);
            return 0;
        }

        if (variable_map.count("version")) {
            std::cout << "Oat Frame Viewer version "
                      << Oat_VERSION_MAJOR
                      << "."
                      << Oat_VERSION_MINOR
                      << "\n";
            std::cout << "Written by Jonathan P. Newman in the MWL@MIT.\n";
            std::cout << "Licensed under the GPL3.0.\n";
            return 0;
        }

        if (!variable_map.count("source")) {
            printUsage(visible_options);
            std::cerr << oat::Error("A SOURCE must be specified. Exiting.\n");
            return -1;
        }

        if (!variable_map.count("snapshot-path")) {
            snapshot_path = bfs::current_path().string();
        }

    } catch (std::exception& e) {
        std::cerr << oat::Error(e.what()) << "\n";
        return -1;
    } catch (...) {
        std::cerr << oat::Error("Exception of unknown type.\n");
        return -1;
    }

    // Create component
    std::shared_ptr<Viewer> viewer;
    
    // Make the viewer
    // TODO: use a method to create snapshot file name instead of the constructor
    //       This will allow you to get rid of these extra try-catch blocks
    try {
        viewer = std::make_shared<Viewer>(source, snapshot_path);
    } catch (const std::runtime_error& ex) {
        std::cerr << oat::Error(ex.what())
                  << "\n";
        
        // Exit failure
        return -1;
        
    } catch (...) {
        std::cerr << oat::Error("Unknown exception.\n");
        
        // Exit failure
        return -1;
    }

    try {

        // Tell user
        std::cout << oat::whoMessage(viewer->get_name(),
                  "Listening to source " + oat::sourceText(source) + ".\n")
                  << oat::whoMessage(viewer->get_name(),
                  "Press 's' on the viewer window to take a snapshot.\n")
                  << oat::whoMessage(viewer->get_name(),
                  "Press CTRL+C to exit.\n");
        
        // Infinite loop until ctrl-c or end of stream signal
        run(viewer);

        // Tell user
        std::cout << oat::whoMessage(viewer->get_name(), "Exiting.\n");

        // Exit
        return 0;

    } catch (const std::runtime_error& ex) {
        std::cerr << oat::whoError(viewer->get_name(), ex.what())
                  << "\n";
    } catch (const cv::Exception& ex) {
        std::cerr << oat::whoError(viewer->get_name(), ex.msg)
                  << "\n";
    } catch (...) {
        std::cerr << oat::whoError(viewer->get_name(), "Unknown exception.\n");
    }

    // Exit failure
    return -1;
}
コード例 #18
0
int main(int argc, char* argv[])
{
    std::vector<fs::path> from;
    std::vector<fs::path> entity;
    std::string ignore_string, save_base;
    unsigned int threshold;
    unsigned int person_threshold;
    bool no_individuals;
    bool remove_most_common;
    std::vector<unsigned int> save_at_v;
    std::set<unsigned int> save_at;
    
    //[Gmail]/Sent Mail
    po::options_description general_options("General");
    general_options.add_options()
        ("help", "list options");
    po::options_description file_options("Load");
    file_options.add_options()
        ("ignore", po::value<std::string>(&ignore_string)->default_value("@lists\\.|@googlegroups\\.|@yahoogroups\\.|@mailman\\.|@facebookmail\\.|noreply|do[-_]not[-_]reply|^buzz\\+"), "ignore messages with a recipient matching this expression")
        ("entity-raw", po::value<std::vector<fs::path> >(&entity), "paths to load data ONLY for entities")
        ("load-raw", po::value<std::vector<fs::path> >(&from), "paths to load data from");
    po::options_description run_options("Export Options");
    run_options.add_options()
        ("save", po::value<std::string>(&save_base), "base path to save the data at")
        ("remove-most-common", po::value<bool>(&remove_most_common)->default_value(1), "remove the most common individual (owner)")
        ("no-individuals", po::value<bool>(&no_individuals)->default_value(0), "ignore individuals")
        ("threshold", po::value<unsigned int>(&threshold)->default_value(1), "minimum mails for group")
        ("person-threshold", po::value<unsigned int>(&person_threshold)->default_value(2), "minimum mails for person");
    
    po::options_description all_options("Email Topology Options");
    all_options
        .add(general_options)
        .add(file_options)
        .add(run_options);

    if(argc < 2) {
        std::cout << all_options << std::endl;
        return 1;
    }

    po::variables_map vm;
    try {
        int options_style = po::command_line_style::default_style;
        po::store(po::parse_command_line(argc, argv, all_options, options_style), vm);
        po::notify(vm);
    } catch(std::exception& e) {
        std::cout << all_options << std::endl;
        std::cout << "Command line parsing failed: " << e.what() << std::endl;
        return 1;
    }
    
    if(vm.count("help")) {
        std::cout << all_options << std::endl;
        return 1;
    }
    std::copy(save_at_v.begin(), save_at_v.end(), std::inserter(save_at, save_at.end()));

    email_id_bimap email_id;
    connectedness_graph cg;
    initial_group_partition_map igpm;
    entity_map em;

    if(!vm.count("load-raw")) {
        std::cout << "must load something" << std::endl;
        return 1;
    }
    if(!vm.count("save")) {
        std::cout << "must save something" << std::endl;
        return 1;
    }

    std::size_t max_id = 0;
    std::vector<char> buffer(128 * 1024);
    try {
        boost::regex re_ignore(ignore_string);
        boost::regex re_loader("([^\t]+)");
        std::cout << "resolving entities" << std::endl;
        for(std::vector<fs::path>::iterator i = entity.begin(); i != entity.end(); ++i) {
            if(!fs::exists(*i))
                throw std::runtime_error(std::string("input file not found: ") + i->file_string());
            std::cout << "loading " << i->file_string();
            fs::ifstream in(*i);
            //we don't care about messages here
            while(in.good()) {
                in.getline(&buffer[0], buffer.size());
                std::string line = &buffer[0];
                boost::algorithm::trim(line);
                if(line == "-") {
                    break;
                }
                bool first = true;
                for(boost::sregex_iterator j(line.begin(), line.end(), re_loader), e; j != e; ++j) {
                    if(first) {
                        first = false;
                    } else {
                        std::string email_address = (*j)[0].str();
                        if(regex_search(email_address, re_ignore)) {
                            continue;
                        }
                        std::pair<email_id_bimap::map_by<email>::iterator, bool> result = email_id.by<email>().insert(
                            email_id_bimap::map_by<email>::value_type(email_address, email_id.size()));
                        if(result.second)
                            std::cout << "@" << std::flush;
                    }
                }
            }
            while(in.good()) {
                in.getline(&buffer[0], buffer.size());
                std::string line = &buffer[0];
                boost::algorithm::trim(line);
                
                std::string email_address;
                bool first = true;
                for(boost::sregex_iterator j(line.begin(), line.end(), re_loader), e; j != e; ++j) {
                    if(first) {
                        first = false;
                        email_address = (*j)[0].str();
                        if(regex_search(email_address, re_ignore)) {
                            break;
                        }
                    } else {
                        std::string name = (*j)[0].str();
                        try {
                            em[email_address].insert(name);
                        } catch(std::exception& e) {
                            std::cout <<  "err missing: " << email_address << std::endl;
                            throw;
                        }
                    }
                }
            }
            std::cout << std::endl;
        }
        resolve_entities(em, email_id);
        for(std::vector<fs::path>::iterator i = from.begin(); i != from.end(); ++i) {
            if(!fs::exists(*i))
                throw std::runtime_error(std::string("input file not found: ") + i->file_string());
            std::cout << "loading " << i->file_string();
            fs::ifstream in(*i);
            while(in.good()) {
                in.getline(&buffer[0], buffer.size());
                std::string line = &buffer[0];
                boost::algorithm::trim(line);
                if(line == "-") {
                    break;
                }
                members_t g;
                unsigned int count = 0;
                bool first = true;
                for(boost::sregex_iterator j(line.begin(), line.end(), re_loader), e; j != e; ++j) {
                    if(first) {
                        first = false;
                        std::string number = (*j)[0].str();
                        count = boost::lexical_cast<unsigned int>(number);
                    } else {
                        std::string email_address = (*j)[0].str();
                        if(regex_search(email_address, re_ignore)) {
                            g.clear();
                            continue;
                        }
                        std::pair<email_id_bimap::map_by<email>::iterator, bool> result = email_id.by<email>().insert(
                            email_id_bimap::map_by<email>::value_type(email_address, email_id.size()));
                        if(result.second)
                            std::cout << "@" << std::flush;
                        g.insert(result.first->second);
                    }
                }

                if(g.empty()) {
                    //no emails? wtfs
                    continue;
                }
                initial_group_partition_map::iterator r = igpm.find(g);
                if(r == igpm.end()) {
                    connectedness_graph::vertex_descriptor node = gr::add_vertex(cg);
                    cg[node].members = g;
                    cg[node].weight = count;
                    igpm.insert(r, std::make_pair(g, node));
                } else {
                    connectedness_graph::vertex_descriptor node = r->second;
                    cg[node].weight += count;
                }
                std::cout << "." << std::flush;
            }
            //no need to load em
            std::cout << std::endl;
        }
        max_id = email_id.size();
    } catch(std::exception& e) {
        std::cout << "failed to load data: " << e.what() << std::endl;
        return 1;
    }

    std::map<unsigned int, score_t> ppl;
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second;) {
        if(cg[*i].weight >= threshold) {
            for(members_t::iterator j = cg[*i].members.begin(); j != cg[*i].members.end(); ++j) {
                ppl[*j] += cg[*i].weight;
            }
            ++i;
        } else {
            connectedness_graph::vertex_iterator to_erase = i++;
            gr::clear_vertex(*to_erase, cg);
            gr::remove_vertex(*to_erase, cg);
        }
    }
    //remove the owner, todo, this is evil because now there are dupe groups if A was owner and A B C and B C existed
    if(!ppl.empty()) {
        if(remove_most_common) {
            unsigned int max_person = ppl.begin()->first;
            score_t max_val = ppl.begin()->second;
            for(std::map<unsigned int, score_t>::iterator j = ppl.begin(); j != ppl.end(); ++j) {
                if(j->second > max_val) {
                    max_val = j->second;
                    max_person = j->first;
                }
            }
            for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second;) {
                cg[*i].members.erase(max_person);
                if(cg[*i].members.empty()) {
                    connectedness_graph::vertex_iterator to_delete = i;
                    ++i;
                    gr::clear_vertex(*to_delete, cg);
                    gr::remove_vertex(*to_delete, cg);
                } else {
                    ++i;
                }
            }
        }
        for(std::map<unsigned int, score_t>::iterator j = ppl.begin(); j != ppl.end();) {
            if(j->second >= person_threshold) {
                std::map<unsigned int, score_t>::iterator to_delete = j++;
                ppl.erase(to_delete);
            } else {
                ++j;
            }
        }
        for(std::map<unsigned int, score_t>::iterator j = ppl.begin(); j != ppl.end(); ++j) {
            for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second;) {
                cg[*i].members.erase(j->first);
                if(cg[*i].members.empty()) {
                    connectedness_graph::vertex_iterator to_delete = i;
                    ++i;
                    gr::clear_vertex(*to_delete, cg);
                    gr::remove_vertex(*to_delete, cg);
                } else {
                    ++i;
                }
            }
        }
    }
    if(no_individuals) {
        for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second;) {
            if(cg[*i].members.size() > 1) {
                ++i;
            } else {
                connectedness_graph::vertex_iterator to_erase = i++;
                gr::clear_vertex(*to_erase, cg);
                gr::remove_vertex(*to_erase, cg);
            }
        }
    }
    //normalize group weights for large groups
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        if(cg[*i].members.size() < 20) 
            continue;
        cg[*i].weight *= score_t(20) / cg[*i].members.size();
    }
    unsigned int vertex_number = 0;
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        cg[*i].index = vertex_number++;
    }
    
    std::cout << "converting to person graph" << std::endl;
    people_graph pg;
    std::map<unsigned int, people_graph::vertex_descriptor> remaining_people;
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        group& g = cg[*i];
        for(members_t::const_iterator j = g.members.begin(); j != g.members.end(); ++j) {
            //if there is a new person represented add them to the map
            std::pair<std::map<unsigned int, people_graph::vertex_descriptor>::iterator, bool> res =
                remaining_people.insert(std::make_pair(*j, people_graph::vertex_descriptor()));
            if(res.second) {
                res.first->second = gr::add_vertex(pg);
                person& p = pg[res.first->second];
                p.id = res.first->first;
                p.name = email_id.by<bit>().equal_range(p.id).first->second;
            }
        }
    }
    for(connectedness_graph::vertex_iterator i = gr::vertices(cg).first; i != gr::vertices(cg).second; ++i) {
        group& g = cg[*i];
        for(members_t::const_iterator j = g.members.begin(); j != g.members.end(); ++j) {
            members_t::const_iterator k = j;
            for(++k; k != g.members.end(); ++k) {
                //duplicates eliminated by setS type container
                people_graph::edge_descriptor l = gr::add_edge(remaining_people[*j], remaining_people[*k], pg).first;
                edge& e = pg[l];
                e.weight += g.weight;
            }
        }
    }
    fs::path path(save_base);
    if(fs::exists(path))
        fs::remove(path);
    fs::ofstream out(path);

    gr::dynamic_properties dp;
    dp.property("label", get(&person::name, pg));
    dp.property("weight", gr::get(&edge::weight, pg));

    gr::write_graphml(out, pg, gr::get(&person::id, pg), dp, false);
    return 0;
}