2015-09-06 15:34:39 +02:00
|
|
|
#include "repoindex/alpm/manager.h"
|
|
|
|
#include "repoindex/alpm/utilities.h"
|
|
|
|
#include "repoindex/alpm/config.h"
|
|
|
|
#include "repoindex/alpm/resolvebuildorder.h"
|
|
|
|
#include "repoindex/alpm/mingwbundle.h"
|
2015-09-04 14:37:01 +02:00
|
|
|
|
2015-09-06 15:34:39 +02:00
|
|
|
#include "repoindex/network/server.h"
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
#include <c++utilities/application/argumentparser.h>
|
2015-09-05 17:25:05 +02:00
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
2015-08-10 22:46:01 +02:00
|
|
|
#include <c++utilities/application/failure.h>
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
#include <iostream>
|
2015-08-19 02:13:28 +02:00
|
|
|
#include <algorithm>
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ApplicationUtilities;
|
2015-09-05 17:25:05 +02:00
|
|
|
using namespace RepoIndex;
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-09-05 17:25:05 +02:00
|
|
|
// check whether shell syntax is enabled
|
|
|
|
for(char **arg = argv, **end = argv + argc; arg != end; ++arg) {
|
|
|
|
if(strcmp(*arg, "--sh-syntax") == 0) {
|
|
|
|
useShSyntax = true;
|
|
|
|
shchar = "# ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-10 22:46:01 +02:00
|
|
|
// setup the argument parser
|
|
|
|
ArgumentParser parser;
|
|
|
|
ConfigArgs configArgs(parser);
|
|
|
|
parser.setIgnoreUnknownArguments(false);
|
|
|
|
// parse command line arguments
|
|
|
|
try {
|
|
|
|
parser.parseArgs(argc, argv);
|
|
|
|
} catch (Failure &e) {
|
2015-09-05 17:25:05 +02:00
|
|
|
cerr << shchar << "Unable to parse arguments: " << e.what() << endl;
|
2015-08-10 22:46:01 +02:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// load configuration
|
|
|
|
Config config;
|
|
|
|
config.loadFromConfigFile(configArgs);
|
|
|
|
config.loadFromArgs(configArgs);
|
2015-08-19 02:13:28 +02:00
|
|
|
if(find_if(parser.mainArguments().cbegin(), parser.mainArguments().cend(), [&configArgs] (const Argument *arg) {
|
|
|
|
return arg != &configArgs.helpArg && arg->isPresent();
|
|
|
|
}) != parser.mainArguments().cend()) {
|
|
|
|
// create app
|
2015-08-10 22:46:01 +02:00
|
|
|
QCoreApplication application(argc, argv);
|
2015-08-19 02:13:28 +02:00
|
|
|
// setup ALPM
|
|
|
|
Manager manager(config);
|
|
|
|
manager.applyPacmanConfig();
|
|
|
|
manager.applyRepoIndexConfig();
|
2015-09-05 17:25:05 +02:00
|
|
|
cerr << shchar << "Loading databases ..." << endl;
|
|
|
|
manager.initAlpmDataBases();
|
2015-08-19 02:13:28 +02:00
|
|
|
if(configArgs.serverArg.isPresent()) {
|
|
|
|
// setup the server
|
|
|
|
Server server(manager, manager.config());
|
|
|
|
QObject::connect(&server, &Server::closed, &application, &QCoreApplication::quit);
|
|
|
|
// run Qt loop
|
|
|
|
return application.exec();
|
|
|
|
} else if(configArgs.buildOrderArg.isPresent()) {
|
|
|
|
BuildOrderResolver resolver(manager);
|
|
|
|
const QStringList results = resolver.resolve(configArgs.buildOrderArg.values());
|
|
|
|
// print results
|
2015-09-05 17:25:05 +02:00
|
|
|
if(useShSyntax) {
|
|
|
|
cout << "export REPOINDEX_RESULTS=(";
|
|
|
|
for(const auto &pkgName : results) {
|
|
|
|
cout << ' ' << '\'' << pkgName.toLocal8Bit().data() << '\'';
|
|
|
|
}
|
|
|
|
cout << ' ' << ')' << endl;
|
|
|
|
} else {
|
|
|
|
cout << "Results: ";
|
|
|
|
for(const auto &pkgName : results) {
|
|
|
|
cout << pkgName.toLocal8Bit().data() << ' ';
|
|
|
|
}
|
|
|
|
cout << endl;
|
2015-08-19 02:13:28 +02:00
|
|
|
}
|
|
|
|
} else if(configArgs.mingwBundleArg.isPresent()) {
|
2015-09-04 14:37:01 +02:00
|
|
|
MingwBundle bundle(manager, configArgs.mingwBundleArg.values(), configArgs.iconThemesArg.values());
|
|
|
|
bundle.createBundle(configArgs.targetDirArg.isPresent() ? configArgs.targetDirArg.values().front() : string("."),
|
|
|
|
configArgs.targetNameArg.values().front(),
|
|
|
|
configArgs.targetFormatArg.isPresent() ? configArgs.targetFormatArg.values().front() : string("zip"));
|
2015-09-05 17:25:05 +02:00
|
|
|
} else if(configArgs.upgradeLookupArg.isPresent()) {
|
|
|
|
cerr << shchar << "TODO" << endl;
|
|
|
|
}
|
|
|
|
} else if(!configArgs.helpArg.isPresent()) {
|
|
|
|
if(useShSyntax) {
|
|
|
|
cerr << "export REPOINDEX_ERROR='No command line arguments specified. See --help for available commands.'" << endl;
|
|
|
|
} else {
|
|
|
|
cerr << "No command line arguments specified. See --help for available commands." << endl;
|
2015-08-19 02:13:28 +02:00
|
|
|
}
|
2015-08-10 22:46:01 +02:00
|
|
|
}
|
|
|
|
} catch (std::exception &e) {
|
2015-09-05 17:25:05 +02:00
|
|
|
if(useShSyntax) {
|
|
|
|
string error = e.what();
|
|
|
|
ConversionUtilities::findAndReplace<string>(error, "'", "\'");
|
|
|
|
cerr << "export REPOINDEX_ERROR='" << error << '\'' << endl;
|
|
|
|
} else {
|
|
|
|
cerr << shchar << "Error: " << e.what() << endl;
|
|
|
|
}
|
2015-08-10 22:46:01 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|