Katja: Add search_names function
This commit is contained in:
parent
a05bd27caf
commit
7906bd3ecb
@ -26,5 +26,7 @@ namespace katja
|
||||
{
|
||||
public:
|
||||
virtual std::vector<package_identifier> get_updates(const package_database& database) = 0;
|
||||
virtual std::vector<package_identifier> search_names(const std::string& architecture,
|
||||
const std::string& needle) = 0;
|
||||
};
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ namespace katja
|
||||
|
||||
info_file(const std::string& program_name, const std::string& version,
|
||||
const std::string homepage, const std::string& email, const std::string& maintainer);
|
||||
|
||||
package_identifier identifier_for(const std::string& architecture);
|
||||
};
|
||||
|
||||
class sbo_repository final : public repository
|
||||
@ -34,10 +36,9 @@ namespace katja
|
||||
sbo_repository(const std::filesystem::path& repository_path);
|
||||
|
||||
std::vector<package_identifier> get_updates(const package_database& database) override;
|
||||
std::vector<package_identifier> search_names(const std::string& architecture,
|
||||
const std::string& needle) 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);
|
||||
}
|
||||
|
106
katja/sbo.cpp
106
katja/sbo.cpp
@ -11,12 +11,57 @@
|
||||
|
||||
namespace katja
|
||||
{
|
||||
static
|
||||
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))
|
||||
{
|
||||
std::filesystem::path entry_path = entry;
|
||||
std::filesystem::path info_filename = entry_path.filename();
|
||||
info_filename.replace_extension(".info");
|
||||
|
||||
std::filesystem::path info_filepath = entry_path / info_filename;
|
||||
|
||||
if (std::filesystem::exists(info_filepath))
|
||||
{
|
||||
info_files.emplace(entry_path.filename(), info_filepath);
|
||||
}
|
||||
else if (std::filesystem::is_directory(entry_path))
|
||||
{
|
||||
search_for_slackbuilds(info_files, entry_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info_file::info_file(const std::string& program_name, const std::string& version,
|
||||
const std::string homepage, const std::string& email, const std::string& maintainer)
|
||||
: program_name(program_name), version(version), homepage(homepage), email(email), maintainer(maintainer)
|
||||
{
|
||||
}
|
||||
|
||||
package_identifier info_file::identifier_for(const std::string& architecture)
|
||||
{
|
||||
return package_identifier{ this->program_name, this->version, architecture, "SBo" };
|
||||
}
|
||||
|
||||
sbo_repository::sbo_repository(const std::filesystem::path& repository_path)
|
||||
{
|
||||
search_for_slackbuilds(this->info_paths, repository_path);
|
||||
@ -36,16 +81,31 @@ namespace katja
|
||||
|
||||
if (slackbuild_info.has_value() && slackbuild_info.value().version != package.version)
|
||||
{
|
||||
identifiers.push_back({
|
||||
slackbuild_info->program_name, slackbuild_info->version, package.architecture, "SBo"
|
||||
});
|
||||
identifiers.push_back(slackbuild_info->identifier_for(package.architecture));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
std::vector<package_identifier> sbo_repository::search_names(const std::string& architecture,
|
||||
const std::string& needle)
|
||||
{
|
||||
std::vector<package_identifier> identifiers;
|
||||
|
||||
for (const auto& [package_name, info_path] : this->info_paths)
|
||||
{
|
||||
if (package_name.find(needle) != std::string::npos)
|
||||
{
|
||||
auto slackbuild_info = read_slackbuild_info(info_path);
|
||||
|
||||
identifiers.push_back(slackbuild_info->identifier_for(architecture));
|
||||
}
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
static
|
||||
bool trim_info_line(std::string& info_value)
|
||||
{
|
||||
if (boost::algorithm::ends_with(info_value, "\""))
|
||||
@ -139,42 +199,4 @@ namespace katja
|
||||
}
|
||||
return std::make_optional<info_file>(program_name, version, homepage, email, maintainer);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
std::filesystem::path entry_path = entry;
|
||||
std::filesystem::path info_filename = entry_path.filename();
|
||||
info_filename.replace_extension(".info");
|
||||
|
||||
std::filesystem::path info_filepath = entry_path / info_filename;
|
||||
|
||||
if (std::filesystem::exists(info_filepath))
|
||||
{
|
||||
info_files.emplace(entry_path.filename(), info_filepath);
|
||||
}
|
||||
else if (std::filesystem::is_directory(entry_path))
|
||||
{
|
||||
search_for_slackbuilds(info_files, entry_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user