Commit 35f40da6d704704dc0cf7dea3ad11f869c4a09ce

Authored by Thiago Rocha
1 parent a65e13cf
Exists in master

Métodos de coleta de software para Linux criados.

gercols/gercols.cpp
@@ -32,7 +32,7 @@ qDebug() << "TESTE"; @@ -32,7 +32,7 @@ qDebug() << "TESTE";
32 32
33 void Gercols::run() 33 void Gercols::run()
34 { 34 {
35 - QJsonObject coleta; 35 +
36 /* Pega configurações do Json de configurações localizado 36 /* Pega configurações do Json de configurações localizado
37 * na pasta principal do cacic (deverá ser pega do registro, 37 * na pasta principal do cacic (deverá ser pega do registro,
38 * estou tentando implementar isso no installcacic). 38 * estou tentando implementar isso no installcacic).
src/cacic_software.cpp
@@ -8,8 +8,9 @@ void cacic_software::iniciaColeta() @@ -8,8 +8,9 @@ void cacic_software::iniciaColeta()
8 { 8 {
9 #ifdef Q_OS_WIN 9 #ifdef Q_OS_WIN
10 this->coletaSoftware = coletaWin(); 10 this->coletaSoftware = coletaWin();
11 -#else 11 +#elif defined(Q_OS_LINUX)
12 this->coletaSoftware = coletaLinux(); 12 this->coletaSoftware = coletaLinux();
  13 +
13 #endif 14 #endif
14 } 15 }
15 16
@@ -33,10 +34,84 @@ QJsonObject cacic_software::coletaWin() @@ -33,10 +34,84 @@ QJsonObject cacic_software::coletaWin()
33 return softwaresJson; 34 return softwaresJson;
34 } 35 }
35 36
36 -void cacic_software::coletaLinux() 37 +QJsonObject cacic_software::coletaLinux()
  38 +{
  39 +
  40 + OperatingSystem operatingSystem;
  41 +
  42 + if( operatingSystem.getIdOs() == OperatingSystem::LINUX_ARCH ) {
  43 + return coletaArch();
  44 + } else if ( operatingSystem.getIdOs() == OperatingSystem::LINUX_DEBIAN ||
  45 + operatingSystem.getIdOs() == OperatingSystem::LINUX_UBUNTU ) {
  46 + return coletaDebian();
  47 + }
  48 +
  49 + return QJsonObject();
  50 +}
  51 +
  52 +QJsonObject cacic_software::coletaArch()
  53 +{
  54 + ConsoleObject console;
  55 + QJsonObject softwaresJson;
  56 +
  57 + QStringList packages = console("pacman -Qe").split("\n");
  58 +
  59 + foreach(QString package, packages) {
  60 + QString packageName = package.split(" ")[0];
  61 + QJsonObject packageJson;
  62 +
  63 + QStringList packageInfo = console(QString("pacman -Qi ").append(packageName)).split("\n");
  64 +// qDebug() << packageInfo;
  65 +
  66 + packageJson["name"] = QJsonValue::fromVariant(QString(packageName));
  67 + foreach(QString line, packageInfo) {
  68 + if(line.contains("Version"))
  69 + packageJson["version"] = line.split(":")[1].mid(1);
  70 + if(line.contains("Description"))
  71 + packageJson["description"] = line.split(":")[1].mid(1);
  72 + if(line.contains("URL"))
  73 + packageJson["url"] = line.split(":")[1].mid(1);
  74 + if(line.contains("Installed size"))
  75 + packageJson["installed_size"] = line.split(":")[1].mid(1);
  76 + if(line.contains("Install Date"))
  77 + packageJson["install_date"] = line.split(":")[1].mid(1);
  78 + }
  79 + softwaresJson[packageName] = packageJson;
  80 + }
  81 + return softwaresJson;
  82 +}
  83 +
  84 +QJsonObject cacic_software::coletaDebian()
37 { 85 {
  86 + ConsoleObject console;
  87 + QJsonObject softwaresJson;
  88 +
  89 + QStringList packages = console("dpkg --get-selections").split("\n");
38 90
  91 + foreach(QString package, packages) {
  92 + QString packageName = package.split(" ")[0];
  93 + QJsonObject packageJson;
  94 +
  95 + QStringList packageInfo = console(QString("apt-cache show ").append(packageName)).split("\n");
  96 +// qDebug() << packageInfo;
  97 +
  98 + packageJson["name"] = QJsonValue::fromVariant(QString(packageName));
  99 + foreach(QString line, packageInfo) {
  100 + if(line.contains("Version"))
  101 + packageJson["version"] = line.split(":")[1].mid(1);
  102 + if(line.contains("Description"))
  103 + packageJson["description"] = line.split(":")[1].mid(1);
  104 + if(line.contains("Homepage"))
  105 + packageJson["url"] = line.split(":")[1].mid(1);
  106 + if(line.contains("Installed-Size"))
  107 + packageJson["installed_size"] = line.split(":")[1].mid(1);
  108 + }
  109 + softwaresJson[packageName] = packageJson;
  110 + }
  111 +
  112 + return softwaresJson;
39 } 113 }
  114 +
40 QJsonObject cacic_software::toJsonObject() 115 QJsonObject cacic_software::toJsonObject()
41 { 116 {
42 return coletaSoftware; 117 return coletaSoftware;
src/cacic_software.h
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 #define CACIC_SOFTWARE_H 2 #define CACIC_SOFTWARE_H
3 #include <QtCore> 3 #include <QtCore>
4 #include <ccacic.h> 4 #include <ccacic.h>
  5 +#include <console.h>
  6 +#include <operatingsystem.h>
5 class cacic_software 7 class cacic_software
6 { 8 {
7 public: 9 public:
@@ -11,7 +13,9 @@ public: @@ -11,7 +13,9 @@ public:
11 13
12 private: 14 private:
13 QJsonObject coletaWin(); 15 QJsonObject coletaWin();
14 - void coletaLinux(); 16 + QJsonObject coletaLinux();
  17 + QJsonObject coletaArch();
  18 + QJsonObject coletaDebian();
15 19
16 CCacic oCacic; 20 CCacic oCacic;
17 QJsonObject coletaSoftware; 21 QJsonObject coletaSoftware;
src/ccoleta.cpp
@@ -16,6 +16,7 @@ void CColeta::coletaSoftware() @@ -16,6 +16,7 @@ void CColeta::coletaSoftware()
16 { 16 {
17 qDebug() << "coletaSoftware() executado"; 17 qDebug() << "coletaSoftware() executado";
18 oSoftware.iniciaColeta(); 18 oSoftware.iniciaColeta();
  19 +
19 } 20 }
20 21
21 void CColeta::configuraColetas(){ 22 void CColeta::configuraColetas(){
@@ -35,10 +35,7 @@ public slots: @@ -35,10 +35,7 @@ public slots:
35 signals: 35 signals:
36 void beginComputer(); 36 void beginComputer();
37 void beginHardware(); 37 void beginHardware();
38 - void beginNetworkInterfaces();  
39 - void beginOperatingSystem();  
40 void beginSoftware(); 38 void beginSoftware();
41 - void beginUser();  
42 void finished(); 39 void finished();
43 }; 40 };
44 41