Example #1
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
*/
}
Example #2
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];
            }

        }
    }
}
Example #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;
        }

    }
}