예제 #1
0
void MacSoftware::read()
{
    Util::exec("pkgutil --package > /tmp/pkgutil.txt");
    CommandParser *c = CommandParser::Instance();
    c->parse("cat", "/tmp/pkgutil.txt");
    vector<string> lines = c->lines();
    for (int i = 0; i < (int)lines.size(); i++) {
        mSoftwareList.push_back(SoftwarePackage());
        mSoftwareList[i].name = lines[i];
        c->parse("pkgutil", "--pkg-info " + lines[i]);
        vector<string> lines2 = c->lines();
        c->split(":");
        vector<vector<string> > fields = c->fields();
        for (int j = 0; j < (int)lines2.size(); j++) {
            if (fields[j][0] == "version") {
                mSoftwareList[i].version = fields[j][1];
            }
            if (fields[j][0] == "install-time") {
                //TODO: Format the time which is a time_t to a string
                // and poplulate mSoftwareList[i].install_time
                //mSoftwareList[i].install_time = fields[j][1];
            }

        }
    }
}
예제 #2
0
void LinuxOS::read()
{

    mName = Util::exec("uname -s");
    boost::trim(mName);
    std::string kernel = Util::exec("uname -r");
    boost::trim(kernel);
    std::vector<std::string> tokens;
    boost::split(tokens, kernel, boost::is_any_of("."));
    mMajorVersion = tokens[0];
    mMinorVersion = tokens[1];
    mBuild = tokens[2];


    CommandParser *c = CommandParser::Instance();
    c->parse("lsb_release", " -a");
    c->split(":");
    std::vector<std::vector<std::string> > fields2 = c->fields();
    for (unsigned int i = 0; i < fields2.size() ; ++i) {
        if (fields2[i].size() <= 0)
            continue;
        if (fields2[i][0] == "Description") {
            mName = fields2[i][1];
        }
        if (fields2[i][0] == "Release") {
            mMajorVersion = fields2[i][1];
            mMinorVersion = "";
            mBuild = kernel;
        }
    }

    c->parse("cat", "/etc/*-release");
    c->split("=");
    std::vector<std::vector<std::string> > fields = c->fields();
    for (unsigned int i = 0; i < fields.size() ; ++i) {
        if (fields[i].size() <= 0)
            continue;
        if (fields[i][0] == "PATCHLEVEL") {
            mMinorVersion = fields[i][1];
        }
    }
    
    /*
     * Slackware: /etc/slackware-version
Mandrake: /etc/mandrake-release
Red Hat: /etc/redhat-release
Fedora: /etc/fedora-release
Suse :  /etc/SuSE-release
United : /etc/UnitedLinux-release
Debian : /etc/debian_version
*/
}
예제 #3
0
void DMIParser::exec()
{
    bool readDescription = false;
    bool readFeatureList = true;
    std::string currentFeature = "";
    int currentIndex = -1;
    CommandParser *parser = CommandParser::Instance();
    std::stringstream o;
    o << "--type " << mType;
    parser->parse( "dmidecode", o.str(), true);
    std::vector<std::string> lines = parser->lines();
    parser->split(":");
    std::vector<std::vector<std::string> > fields = parser->fields();
    // Process the lines one by one
    for (unsigned int i = 0; i < lines.size() ; ++i) {
        if (readDescription) {
            mFrames[currentIndex].Description = lines[i];
            readDescription = false;
            continue;
        }
        if (lines[i].substr(0,6) == "Handle") {
            // Start new Frame
            Frame f;
            f.Handle = lines[i];
            mFrames.push_back(f);
            currentIndex++;
            readDescription = true;
            readFeatureList = false;
            continue;
        }
        if (currentIndex < 0)
            continue;
        if (lines[i].find(":") != std::string::npos) {
            readFeatureList = false;
        } else if (readFeatureList) {
            mFrames[currentIndex].FeatureData[currentFeature].push_back(lines[i]);
        }
        if (fields[i].size() == 2) {
            // Simple field
            readFeatureList = false;
            mFrames[currentIndex].Data[fields[i][0]] = fields[i][1];
        } else if (fields[i].size() == 1) {
            // Possible Feature list type field
            boost::trim(fields[i][0]);
            currentFeature = fields[i][0];
            readFeatureList = true;
        }

    }
}
예제 #4
0
int main()
{
    CommandParser commandParser;
    string input;

    while ( !cin.eof() )
    {
        getline( cin, input );
        if(!commandParser.parse( input ))
        {
            LOGME( "Error executing: "<< input << endl );
        }
    }
    return 0;
}
예제 #5
0
  void
  execute(const std::string& cmd)
  {
    std::vector<std::string> args;
    boost::split(args, cmd, boost::is_any_of(" "));

    CommandParser parser;
    registerCommands(parser);

    std::string noun, verb;
    CommandArguments ca;
    ExecuteCommand execute;
    std::tie(noun, verb, ca, execute) = parser.parse(args, ParseMode::ONE_SHOT);

    Controller controller(face, m_keyChain);
    ExecuteContext ctx{noun, verb, ca, 0, out, err, face, m_keyChain, controller};
    execute(ctx);
    exitCode = ctx.exitCode;
  }
예제 #6
0
TEST(parser, parseToCmd) {

  std::string storeConfig = "services/store/test/data_store.conf";
  ResultCode code = ::idgs::util::singleton<DataStore>::getInstance().initialize(storeConfig);

  //string insert_cmd = "store.service insert {\"store_name\":\"Customer\"} key={\"c_custkey\":\"234000\"} value={\"c_name\":\"Tom0\",\"c_nationkey\":\"10\",\"c_phone\":\"13500000000\"}";
  string insert_cmd = "store.service insert {\"store_name\":\"Orders\"} key={\"o_orderkey\":\"100000\"} value={\"o_custkey\":\"234000\",\"o_orderstatus\":\"2\",\"o_totalprice\":\"200.55\",\"o_orderdate\":\"2013-02-01\"}";

  CommandParser parser;
  Command command;
  code = parser.parse(insert_cmd, &command);
  ASSERT_EQ(RC_SUCCESS, code);
  ASSERT_EQ("store.service", command.actorId);
  ASSERT_EQ("insert", command.opName);
  ASSERT_EQ("{\"store_name\":\"Orders\"}", command.payload);
/*  for(auto it = command.attachments.begin(); it!=command.attachments.end(); ++it) {
    LOG(INFO) << "get Attachment " << it->first << " | " << it->second;
  }*/
}
예제 #7
0
int main(int ac, const char *av[]) {
    std::vector<std::string> argv(&av[1], &av[ac]);

    // stick to STL streams, no mix of C and C++ for IO operations
    std::ios_base::sync_with_stdio(false);

    bool interactiveMode = false;

    Irony irony;

    if (ac == 1) {
        printHelp();
        return 1;
    }

    std::ofstream logFile;

    // When logging to a specific file, std::clog.rdbuf() is replaced by the log
    // file's one. When we return from the main, this buffer is deleted (at the
    // same time as logFile) but std::clog is still active, and will try to
    // release the rdbuf() which has already been released in logFile's
    // destructor. To avoid this we restore std::clog()'s original rdbuf on exit.
    RestoreClogOnExit clogBufferRestorer;

    unsigned optCount = 0;
    while (optCount < argv.size()) {
        const std::string &opt = argv[optCount];

        if (opt.c_str()[0] != '-')
            break;

        if (opt == "--help" || opt == "-h") {
            printHelp();
            return 0;
        }

        if (opt == "--version" || opt == "-v") {
            printVersion();
            return 0;
        }

        if (opt == "--interactive" || opt == "-i") {
            interactiveMode = true;
        } else if (opt == "--debug" || opt == "-d") {
            irony.setDebug(true);
        } else if (opt == "--log-file" && (optCount + 1) < argv.size()) {
            ++optCount;
            logFile.open(argv[optCount]);
            std::clog.rdbuf(logFile.rdbuf());
        } else {
            std::cerr << "error: invalid option '" << opt << "'\n";
            return 1;
        }

        ++optCount;
    }

    argv.erase(argv.begin(), argv.begin() + optCount);

    CommandParser commandParser;
    std::unique_ptr<CommandProviderInterface> commandProvider;

    if (interactiveMode) {
        commandProvider.reset(new InteractiveCommandProvider());
    } else {
        commandProvider.reset(new CommandLineCommandProvider(argv));
    }

    while (Command *c = commandParser.parse(commandProvider->nextCommand())) {
        if (c->action != Command::Exit) {
            std::clog << "execute: " << *c << std::endl;

            if (irony.isDebugEnabled()) {
                dumpUnsavedFiles(*c);
            }
        }

        switch (c->action) {
        case Command::Help:
            printHelp();
            break;

        case Command::Diagnostics:
            irony.diagnostics();
            break;

        case Command::Complete:
            irony.complete(c->file, c->line, c->column, c->flags, c->cxUnsavedFiles);
            break;

        case Command::Exit:
            return 0;

        case Command::Parse:
            irony.parse(c->file, c->flags, c->cxUnsavedFiles);
            break;

        case Command::SetDebug:
            irony.setDebug(c->opt);
            break;

        case Command::GetCompileOptions:
            irony.getCompileOptions(c->dir, c->file);
            break;

        case Command::Unknown:
            assert(0 && "unreacheable code...reached!");
            break;
        }

        std::cout << "\n;;EOT\n" << std::flush;
    }

    return 1;
}