From 1b4bdda0659d2f725955eba1c325203e8e93975f Mon Sep 17 00:00:00 2001 From: Alexander Lenhardt Date: Fri, 9 Mar 2012 12:06:05 +0100 Subject: added --include option allows to specify whitelists for the inclusion into the repository. --include and --exclude are mutually exclusive. Change-Id: I3148482250234e44dd34b6ad2dadedc8923adc36 Reviewed-by: Niels Weber Reviewed-by: Tim Jenssen --- installerbuilder/binarycreator/binarycreator.cpp | 24 +++++++++++++++++++----- installerbuilder/common/repositorygen.cpp | 22 +++++++++++++++------- installerbuilder/common/repositorygen.h | 7 ++++++- installerbuilder/repogen/repogen.cpp | 22 ++++++++++++++++++---- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/installerbuilder/binarycreator/binarycreator.cpp b/installerbuilder/binarycreator/binarycreator.cpp index 088236a4b..d9477829e 100644 --- a/installerbuilder/binarycreator/binarycreator.cpp +++ b/installerbuilder/binarycreator/binarycreator.cpp @@ -536,7 +536,8 @@ int main(int argc, char **argv) bool offlineOnly = false; QStringList resources; QStringList components; - QStringList excludedPackages; + QStringList filteredPackages; + FilterType ftype = Exclude; const QStringList args = app.arguments().mid(1); for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -555,10 +556,23 @@ int main(int argc, char **argv) packagesDirectory = *it; } else if (*it == QLatin1String("-e") || *it == QLatin1String("--exclude")) { ++it; + if (!filteredPackages.isEmpty()) + return printErrorAndUsageAndExit(QObject::tr("Error: --include and --exclude are mutually " + "exclusive. Use either one or the other.")); if (it == args.end() || it->startsWith(QLatin1String("-"))) return printErrorAndUsageAndExit(QObject::tr("Error: Package to exclude missing.")); - excludedPackages = it->split(QLatin1Char(',')); - } else if (*it == QLatin1String("-v") || *it == QLatin1String("--verbose")) { + filteredPackages = it->split(QLatin1Char(',')); + } else if (*it == QLatin1String("-i") || *it == QLatin1String("--include")) { + ++it; + if (!filteredPackages.isEmpty()) + return printErrorAndUsageAndExit(QObject::tr("Error: --include and --exclude are mutually " + "exclusive. Use either one or the other.")); + if (it == args.end() || it->startsWith(QLatin1String("-"))) + return printErrorAndUsageAndExit(QObject::tr("Error: Package to include missing.")); + filteredPackages = it->split(QLatin1Char(',')); + ftype = Include; + } + else if (*it == QLatin1String("-v") || *it == QLatin1String("--verbose")) { QInstaller::setVerbose(true); } else if (*it == QLatin1String("-n") || *it == QLatin1String("--nodeps")) { nodeps = true; @@ -617,8 +631,8 @@ int main(int argc, char **argv) qDebug() << "Parsed arguments, ok."; try { - PackageInfoVector packages = createListOfPackages(components, packagesDirectory, excludedPackages, - !nodeps); + PackageInfoVector packages = createListOfPackages(components, packagesDirectory, filteredPackages, + ftype, !nodeps); const QString metaDir = createMetaDataDirectory(packages, packagesDirectory, configDir); { QSettings confInternal(metaDir + "/config/config-internal.ini", QSettings::IniFormat); diff --git a/installerbuilder/common/repositorygen.cpp b/installerbuilder/common/repositorygen.cpp index 8f565b3b4..d68e6e4c6 100644 --- a/installerbuilder/common/repositorygen.cpp +++ b/installerbuilder/common/repositorygen.cpp @@ -52,12 +52,13 @@ void QInstaller::printRepositoryGenOptions() std::cout << " -p|--packages dir The directory containing the available packages." << std::endl; std::cout << " Defaults to the current working directory." << std::endl; - std::cout << " -e|--exclude p1,...,pn exclude the given packages" << std::endl; + std::cout << " -e|--exclude p1,...,pn Exclude the given packages." << std::endl; + std::cout << " -i|--include p1,...,pn Include the given packages and their dependencies from the " + << "repository." << std::endl; std::cout << " --ignore-translations Don't use any translation" << std::endl; std::cout << " --ignore-invalid-packages Ignore all invalid packages instead of aborting." << std::endl; } - QT_BEGIN_NAMESPACE static bool operator==(const PackageInfo &lhs, const PackageInfo &rhs) { @@ -65,7 +66,8 @@ static bool operator==(const PackageInfo &lhs, const PackageInfo &rhs) } QT_END_NAMESPACE -static PackageInfoVector collectAvailablePackages(const QString &packagesDirectory, const QStringList &excludedPackages) +static PackageInfoVector collectAvailablePackages(const QString &packagesDirectory, + const QStringList &filteredPackages, FilterType ftype) { qDebug() << "Collecting information about available packages..."; @@ -75,8 +77,13 @@ static PackageInfoVector collectAvailablePackages(const QString &packagesDirecto const QFileInfoList entries = QDir(packagesDirectory) .entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for (QFileInfoList::const_iterator it = entries.begin(); it != entries.end(); ++it) { - if (excludedPackages.contains(it->fileName())) - continue; + if (ftype == Exclude) { + if (filteredPackages.contains(it->fileName())) + continue; + } else { + if (!filteredPackages.contains(it->fileName())) + continue; + } qDebug() << QString::fromLatin1("\tfound subdirectory %1").arg(it->fileName()); // because the filter is QDir::Dirs - filename means the name of the subdirectory if (it->fileName().contains(QLatin1Char('-'))) { @@ -616,9 +623,10 @@ void QInstaller::generateMetaDataDirectory(const QString &outDir, const QString } PackageInfoVector QInstaller::createListOfPackages(const QStringList &components, - const QString &packagesDirectory, const QStringList &excludedPackages, bool addDependencies) + const QString &packagesDirectory, const QStringList &filteredPackages, FilterType ftype, bool addDependencies) { - const PackageInfoVector availablePackageInfos = collectAvailablePackages(packagesDirectory, excludedPackages); + const PackageInfoVector availablePackageInfos = collectAvailablePackages(packagesDirectory, + filteredPackages, ftype); if (!addDependencies) { PackageInfoVector packageInfos; foreach (const PackageInfo &info, availablePackageInfos) { diff --git a/installerbuilder/common/repositorygen.h b/installerbuilder/common/repositorygen.h index b77ae2fc7..64290856b 100644 --- a/installerbuilder/common/repositorygen.h +++ b/installerbuilder/common/repositorygen.h @@ -51,6 +51,11 @@ struct PackageInfo }; typedef QVector PackageInfoVector; +enum FilterType { + Include, + Exclude +}; + QMap buildPathToVersionMap(const PackageInfoVector &info); void compressMetaDirectories(const QString &repoDir); @@ -65,7 +70,7 @@ void generateMetaDataDirectory(const QString &outDir, const QString &dataDir, const QString& appVersion, const QString &redirectUpdateUrl = QString()); PackageInfoVector createListOfPackages(const QStringList &components, const QString &packagesDirectory, - const QStringList &excludedPackages, bool addDependencies = true); + const QStringList &filteredPackages, FilterType ftype, bool addDependencies = true); } // namespace QInstaller diff --git a/installerbuilder/repogen/repogen.cpp b/installerbuilder/repogen/repogen.cpp index 0a72c6649..e79621c02 100644 --- a/installerbuilder/repogen/repogen.cpp +++ b/installerbuilder/repogen/repogen.cpp @@ -92,11 +92,12 @@ int main(int argc, char** argv) QStringList args = app.arguments().mid(1); - QStringList excludedPackages; + QStringList filteredPackages; bool replaceSingleComponent = false; QString packagesDir; QString configDir; QString redirectUpdateUrl; + FilterType ftype = Exclude; //TODO: use a for loop without removing values from args like it is in binarycreator.cpp //for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -106,10 +107,23 @@ int main(int argc, char** argv) setVerbose(true); } else if (args.first() == QLatin1String("--exclude") || args.first() == QLatin1String("-e")) { args.removeFirst(); + if (!filteredPackages.isEmpty()) + return printErrorAndUsageAndExit(QObject::tr("Error: --include and --exclude are mutually " + "exclusive. Use either one or the other.")); if (args.isEmpty() || args.first().startsWith(QLatin1Char('-'))) return printErrorAndUsageAndExit(QObject::tr("Error: Package to exclude missing")); - excludedPackages = args.first().split(QLatin1Char(',')); + filteredPackages = args.first().split(QLatin1Char(',')); args.removeFirst(); + } else if (args.first() == QLatin1String("--include") || args.first() == QLatin1String("-i")) { + args.removeFirst(); + if (!filteredPackages.isEmpty()) + return printErrorAndUsageAndExit(QObject::tr("Error: --include and --exclude are mutual " + "exclusive options. Use either one or the other.")); + if (args.isEmpty() || args.first().startsWith(QLatin1Char('-'))) + return printErrorAndUsageAndExit(QObject::tr("Error: Package to include missing")); + filteredPackages = args.first().split(QLatin1Char(',')); + args.removeFirst(); + ftype = Include; } else if (args.first() == QLatin1String("--single")) { args.removeFirst(); replaceSingleComponent = true; @@ -193,8 +207,8 @@ int main(int argc, char** argv) .arg(repositoryDir)); } - PackageInfoVector packages = createListOfPackages(components, packagesDir, excludedPackages, - !replaceSingleComponent); + PackageInfoVector packages = createListOfPackages(components, packagesDir, filteredPackages, + ftype, !replaceSingleComponent); QMap pathToVersionMapping = buildPathToVersionMap(packages); for (PackageInfoVector::const_iterator it = packages.begin(); it != packages.end(); ++it) { -- cgit v1.2.3