mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 02:20:17 +00:00
prototype sourcetree management for sysadm
This commit is contained in:
@@ -58,6 +58,21 @@ bool General::RunQuickCommand(QString command, QStringList arguments,QString wor
|
||||
return success;
|
||||
}
|
||||
|
||||
QStringList General::gitCMD(QString dir, QString cmd, QStringList args){
|
||||
//Run a quick command in the proper dir and return the output
|
||||
QProcess proc;
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
if( !dir.isEmpty() && QFile::exists(dir) ){ proc.setWorkingDirectory(dir); }
|
||||
if(args.isEmpty()){ proc.start(cmd); }
|
||||
else{ proc.start(cmd, args); }
|
||||
while(!proc.waitForFinished(300)){ QCoreApplication::processEvents(); }
|
||||
QStringList out;
|
||||
while(proc.canReadLine()){
|
||||
out << QString( proc.readLine() );
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
//=================
|
||||
// TEXT FILE INTERACTION
|
||||
//=================
|
||||
@@ -311,3 +326,18 @@ QString General::bytesToHumanReadable(long long bytes)
|
||||
return QString().setNum(num,'f',2)+" "+unit;
|
||||
}
|
||||
|
||||
void General::emptyDir(QString dir){
|
||||
QDir d(dir);
|
||||
if(!d.exists()){ return; } //quick check to make sure directory exists first
|
||||
//Remove all the files in this directory
|
||||
QStringList tmp = d.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
for(int i=0; i<tmp.length(); i++){
|
||||
d.remove(tmp[i]);
|
||||
}
|
||||
//Now remove all the directories in this directory (recursive)
|
||||
tmp = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for(int i=0; i<tmp.length(); i++){
|
||||
General::emptyDir(d.absoluteFilePath(tmp[i])); //Empty this directory first
|
||||
d.rmdir(tmp[i]); //Now try to remove it
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ public:
|
||||
static QString RunCommand(QString command, QStringList arguments = QStringList(), QString workdir = "", QStringList env = QStringList() );
|
||||
// - success output only
|
||||
static bool RunQuickCommand(QString command, QStringList arguments = QStringList(), QString workdir = "", QStringList env = QStringList() );
|
||||
|
||||
static QStringList gitCMD(QString dir, QString cmd, QStringList args = QStringList());
|
||||
static void emptyDir(QString dir);
|
||||
//File Access Functions
|
||||
static QStringList readTextFile(QString filename);
|
||||
static bool writeTextFile(QString filename, QStringList contents, bool overwrite = true);
|
||||
|
||||
@@ -391,3 +391,60 @@ QJsonObject SysMgmt::systemReboot() {
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Source Management
|
||||
/*
|
||||
void SysMgmt::fetchPortsTree(QStringList &cmds, QStringList &dirs){
|
||||
//Clear the output variables
|
||||
cmds.clear(); dirs.clear();
|
||||
//Does Ports tree exist? If not create it.
|
||||
if(!QFile::exists("/usr/ports")){
|
||||
cmds << "mkdir /usr/ports"; dirs << "";
|
||||
}
|
||||
//Does a local git repo exist? If not create it.
|
||||
QString URL = "https://www.github.com/trueos/freebsd-ports.git";
|
||||
if(QFile::exists("/usr/ports/.git")){
|
||||
//Check if the remote URL is correct
|
||||
QString origin = General::gitCMD("/usr/ports", "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified();
|
||||
if(origin != URL){
|
||||
cmds << "git remote remove origin"; dirs <<"/usr/ports";
|
||||
cmds << "git remote add origin "+URL; dirs << "/usr/ports/.git";
|
||||
}
|
||||
}else{
|
||||
//new GIT setup
|
||||
General::emptyDir("/usr/ports");
|
||||
cmds << "git init"; dirs << "/usr/ports"; //setup git
|
||||
cmds << "git remote add origin "+URL; dirs << "/usr/ports/.git"; //setup TrueOS git repo
|
||||
}
|
||||
//Now update the tree with git
|
||||
cmds << "git fetch --depth=1"; dirs << "/usr/ports/.git";
|
||||
cmds << "git checkout master"; dirs << "/usr/ports";
|
||||
}
|
||||
|
||||
void SysMgmt::fetchSourceTree(QString branch, QStringList &cmds, QStringList &dirs, QStringList &info){
|
||||
//Clear the output variables
|
||||
cmds.clear(); dirs.clear();
|
||||
//Check if the source directory even exists
|
||||
if(!QFile::exists("/usr/src")){
|
||||
cmds << "mkdir /usr/src"; dirs << ""; //Create the ports tree
|
||||
}
|
||||
//Now check if the git directory exists
|
||||
QString URL = "https://www.github.com/pcbsd/freebsd.git";
|
||||
if(QFile::exists("/usr/src/.git")){
|
||||
//Check if the remote URL is correct
|
||||
QString origin = General::gitCMD("/usr/src", "git remote show -n origin").filter("Fetch URL:").join("").section("URL:",1,30).simplified();
|
||||
if(origin != URL){
|
||||
cmds << "git remote remove origin"; dirs <<"/usr/src";
|
||||
cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo
|
||||
}
|
||||
}else{
|
||||
//new GIT setup
|
||||
General::emptyDir("/usr/src");
|
||||
cmds << "git init"; dirs << "/usr/src"; //setup git
|
||||
cmds << "git remote add origin "+URL; dirs << "/usr/src/.git"; //setup PC-BSD git repo
|
||||
}
|
||||
//Now update the tree with git
|
||||
cmds << "git fetch --depth=1"; dirs << "/usr/src/.git";
|
||||
cmds << "git checkout "+branch; dirs << "/usr/src";
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
static QJsonObject systemInfo();
|
||||
static QJsonObject systemReboot();
|
||||
static QJsonObject systemHalt();
|
||||
// static void fetchPortsTree(QStringList &cmds, QStringList &dirs); // This is not ready yet
|
||||
// static void fetchSourceTree(QString branch, QStringList &cmds, QStringList &dirs); // This is not ready yet
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
Reference in New Issue
Block a user