Skip to content
Snippets Groups Projects
Commit 6b5fa14c authored by Matus Balogh's avatar Matus Balogh
Browse files

v2

parent b37ab9fc
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <ctime>
#include <fstream>
#include <dirent.h>
#include <unistd.h>
#ifndef PROJECT_FOLDER
#define PROJECT_FOLDER "undefined"
#endif
//terminal colors
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
void processGit()
using namespace std;
bool DirectoryExists( const char* pzPath )
{
if ( pzPath == NULL) return false;
DIR *pDir;
bool bExists = false;
pDir = opendir (pzPath);
if (pDir != NULL)
{
bExists = true;
(void) closedir (pDir);
}
return bExists;
}
string GetMachineID()
{
system("git checkout");
system("git status");
std::cout << PROJECT_FOLDER << std::endl;
string id;
ifstream machineIdFile;
machineIdFile.open("/etc/machine-id");
if(machineIdFile.good())
{
getline(machineIdFile, id);
cout << BOLDGREEN << "This machine ID is: " << RESET << GREEN << id << RESET << endl;
}
else
{
id = "NULL";
cout << BOLDYELLOW << "Machine ID was not identified, " << RESET << YELLOW << "value \"NULL\" will be used instead" << RESET<< endl;
}
return id;
}
void ShowError(string cmd)
{
std::cout << BOLDRED << " --- ERROR: " << RESET << RED << "Command \"" << cmd << "\" returned bad value" << RESET << std::endl;
std::cout << BOLDRED << "Backing data to git failed" << RESET << endl;
std::cout << BOLDYELLOW << "Error details are in gitlog.txt:" << RESET << std::endl;
system("cat gitlog.txt");
}
void processGit(string filename)
{
//get time for backed-up file name
time_t curr_time;
tm * curr_tm;
time(&curr_time);
curr_tm = localtime(&curr_time);
char nf[100];
strftime(nf, 100, "caenSC_%e-%m-%Y_%Hh%Mm%Ss", curr_tm);
string newfile = nf;
newfile += "__" + GetMachineID() + ".json";
//we must pull the submodule first to ensure all is up to date
if (system("git -C ./caenslowcontrol_json pull > gitlog.txt") != 0)
{
ShowError(cmd);
return;
}
sleep(1);
//check if project folder exists
string path =PROJECT_FOLDER;
path = "./caenslowcontrol_json/" + path;
string cmd = "mkdir " + path;
if(!DirectoryExists(path.c_str())) system(cmd.c_str());
//copy to project folder
cmd = "cp " + filename + " " + path + "/" + newfile;
if (system(cmd.c_str()) != 0)
{
ShowError(cmd);
return;
}
//git add
path = PROJECT_FOLDER;
cmd = "git -C ./caenslowcontrol_json add " + path + "/" + newfile + " >> gitlog.txt";
if (system(cmd.c_str()) != 0)
{
ShowError(cmd);
return;
}
//git commit
string commit = "\"autopush of " + newfile + "\"";
cmd = "git -C ./caenslowcontrol_json commit -m " + commit + " >> gitlog.txt";
if (system(cmd.c_str()) != 0)
{
ShowError(cmd);
return;
}
//git push
cmd = "git -C ./caenslowcontrol_json push >> gitlog.txt";
if (system(cmd.c_str()) != 0)
{
ShowError(cmd);
return;
}
}
bla
bla
bla
bla
bla
bla
bla
bla
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment