katja: Show only updates

This commit is contained in:
Eugen Wissner 2025-03-12 13:04:58 +01:00
parent dfa5a732ba
commit 67d798dcb0
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
6 changed files with 111 additions and 21 deletions

View File

@ -6,25 +6,19 @@
int main(int argc, const char **argv)
{
std::vector<katja::info_file> info_files;
std::multimap<std::string, katja::database_package> installed_database = katja::read_installed_database();
if (argc > 1)
{
std::filesystem::path slackbuild_repository{ argv[1] };
katja::sbo_repository repository{ slackbuild_repository };
auto updates = repository.get_updates(installed_database);
katja::search_for_slackbuilds(info_files, slackbuild_repository);
for (const auto& slackbuild_info : info_files)
for (const auto& package_identifier : updates)
{
std::multimap<std::string, katja::database_package>::const_iterator installed_package =
installed_database.find(slackbuild_info.program_name);
if (installed_package != installed_database.cend())
{
std::cout << slackbuild_info.program_name << " " << slackbuild_info.version
<< " (installed " << installed_package->second.version << ")" << std::endl;
}
std::cout << package_identifier.to_string() << std::endl;
}
std::cout << "SlackBuilds found: " << updates.size() << std::endl;
}
return 0;
}

View File

@ -20,10 +20,10 @@ namespace katja
static database_package create_database_package(const std::string& fullname);
public:
const std::string build_tag;
const std::string architecture;
const std::string version;
const std::string name;
const std::string version;
const std::string architecture;
const std::string build_tag;
database_package(const std::string& fullname);
@ -33,5 +33,7 @@ namespace katja
std::string to_string() const;
};
std::multimap<std::string, database_package> read_installed_database();
using package_database = std::multimap<std::string, database_package>;
package_database read_installed_database();
}

View File

@ -5,6 +5,26 @@
*/
#pragma once
#include <string>
#include <vector>
#include "katja/database.hpp"
namespace katja
{
struct package_identifier
{
const std::string name;
const std::string version;
const std::string architecture;
const std::string data;
std::string to_string() const;
};
class repository
{
public:
virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
};
}

View File

@ -10,6 +10,8 @@
#include <filesystem>
#include <optional>
#include "katja/repository.hpp"
namespace katja
{
struct info_file
@ -24,6 +26,18 @@ namespace katja
const std::string homepage, const std::string& email, const std::string& maintainer);
};
class sbo_repository final : public repository
{
std::map<std::string, std::filesystem::path> info_paths;
public:
sbo_repository(const std::filesystem::path& repository_path);
std::vector<package_identifier> get_updates(const package_database& database) override;
};
std::optional<info_file> read_slackbuild_info(const std::filesystem::path& info_filepath);
void search_for_slackbuilds(std::vector<info_file>& info_files, const std::filesystem::path& directory);
void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
const std::filesystem::path& directory);
}

View File

@ -3,6 +3,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "katja/repository.hpp"
namespace katja
{
std::string package_identifier::to_string() const
{
std::string identifier;
const std::size_t total_size = this->name.size() + this->version.size()
+ this->architecture.size() + this->data.size() + 3;
identifier.reserve(total_size);
identifier.append(this->name);
identifier.push_back(';');
identifier.append(this->version);
identifier.push_back(';');
identifier.append(this->architecture);
identifier.push_back(';');
identifier.append(this->data);
return identifier;
}
}

View File

@ -17,6 +17,35 @@ namespace katja
{
}
sbo_repository::sbo_repository(const std::filesystem::path& repository_path)
{
search_for_slackbuilds(this->info_paths, repository_path);
}
std::vector<package_identifier> sbo_repository::get_updates(const package_database& database)
{
std::vector<package_identifier> identifiers;
for (const auto& [package_name, package] : database)
{
auto looked_up_info_path = this->info_paths.find(package_name);
if (looked_up_info_path != this->info_paths.cend())
{
auto slackbuild_info = read_slackbuild_info(looked_up_info_path->second);
if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
{
identifiers.push_back({
slackbuild_info->program_name, slackbuild_info->version, package.architecture, "SBo"
});
}
}
}
return identifiers;
}
bool trim_info_line(std::string& info_value)
{
if (boost::algorithm::ends_with(info_value, "\""))
@ -112,6 +141,23 @@ namespace katja
}
void search_for_slackbuilds(std::vector<info_file>& info_files, const std::filesystem::path& directory)
{
std::map<std::string, std::filesystem::path> info_paths;
search_for_slackbuilds(info_paths, directory);
for (const auto& [_, info_filepath] : info_paths)
{
auto slackbuild_info = read_slackbuild_info(info_filepath);
if (slackbuild_info.has_value())
{
info_files.emplace_back(std::move(slackbuild_info.value()));
}
}
}
void search_for_slackbuilds(std::map<std::string, std::filesystem::path>& info_files,
const std::filesystem::path& directory)
{
for (const auto& entry : std::filesystem::directory_iterator(directory))
{
@ -123,12 +169,7 @@ namespace katja
if (std::filesystem::exists(info_filepath))
{
auto slackbuild_info = read_slackbuild_info(info_filepath);
if (slackbuild_info.has_value())
{
info_files.emplace_back(std::move(slackbuild_info.value()));
}
info_files.emplace(entry_path.filename(), info_filepath);
}
else if (std::filesystem::is_directory(entry_path))
{