package list: also support package info files
This commit is contained in:
@@ -21,6 +21,89 @@ using BPackageKit::BHPKG::BUserSettingsFileInfoData;
|
|||||||
|
|
||||||
class PackageInfoPrinter {
|
class PackageInfoPrinter {
|
||||||
public:
|
public:
|
||||||
|
void PrintPackageInfo(const BPackageInfo& info)
|
||||||
|
{
|
||||||
|
PrintName(info.Name());
|
||||||
|
PrintSummary(info.Summary());
|
||||||
|
PrintDescription(info.Description());
|
||||||
|
PrintVendor(info.Vendor());
|
||||||
|
PrintPackager(info.Packager());
|
||||||
|
|
||||||
|
if (!info.BasePackage().IsEmpty())
|
||||||
|
PrintBasePackage(info.BasePackage());
|
||||||
|
|
||||||
|
PrintFlags(info.Flags());
|
||||||
|
PrintArchitecture((uint32)info.Architecture());
|
||||||
|
PrintVersion(info.Version());
|
||||||
|
|
||||||
|
int32 count = info.CopyrightList().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintCopyright(info.CopyrightList().StringAt(i));
|
||||||
|
|
||||||
|
count = info.LicenseList().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintLicense(info.LicenseList().StringAt(i));
|
||||||
|
|
||||||
|
count = info.URLList().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintUrl(info.URLList().StringAt(i));
|
||||||
|
|
||||||
|
count = info.SourceURLList().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintSourceUrl(info.SourceURLList().StringAt(i));
|
||||||
|
|
||||||
|
count = info.ProvidesList().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintProvides(*info.ProvidesList().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.RequiresList().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintRequires(*info.RequiresList().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.SupplementsList().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintSupplements(*info.SupplementsList().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.ConflictsList().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintConflicts(*info.ConflictsList().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.FreshensList().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintFreshens(*info.FreshensList().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.ReplacesList().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintReplaces(info.ReplacesList().StringAt(i));
|
||||||
|
|
||||||
|
count = info.GlobalWritableFileInfos().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintGlobalWritableFile(*info.GlobalWritableFileInfos().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.UserSettingsFileInfos().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintUserSettingsFile(*info.UserSettingsFileInfos().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.Users().CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintUser(*info.Users().ItemAt(i));
|
||||||
|
|
||||||
|
count = info.Groups().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintGroup(info.Groups().StringAt(i));
|
||||||
|
|
||||||
|
count = info.PostInstallScripts().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintPostInstallScript(info.PostInstallScripts().StringAt(i));
|
||||||
|
|
||||||
|
count = info.PostInstallScripts().CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
PrintPostInstallScript(info.PostInstallScripts().StringAt(i));
|
||||||
|
|
||||||
|
if (!info.InstallPath().IsEmpty())
|
||||||
|
PrintInstallPath(info.InstallPath());
|
||||||
|
}
|
||||||
|
|
||||||
bool PrintAttribute(const BPackageInfoAttributeValue& value)
|
bool PrintAttribute(const BPackageInfoAttributeValue& value)
|
||||||
{
|
{
|
||||||
switch (value.attributeID) {
|
switch (value.attributeID) {
|
||||||
@@ -181,11 +264,9 @@ public:
|
|||||||
: "<invalid>");
|
: "<invalid>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVersion(const BPackageVersionData& version) const
|
void PrintVersion(const BPackageVersion& version) const
|
||||||
{
|
{
|
||||||
printf("\tversion: ");
|
printf("\tversion: %s\n", version.ToString().String());
|
||||||
_PrintPackageVersion(version);
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintCopyright(const char* copyright) const
|
void PrintCopyright(const char* copyright) const
|
||||||
@@ -208,38 +289,36 @@ public:
|
|||||||
printf("\tsource URL: %s\n", sourceUrl);
|
printf("\tsource URL: %s\n", sourceUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintProvides(const BPackageResolvableData& provides) const
|
void PrintProvides(const BPackageResolvable& provides) const
|
||||||
{
|
{
|
||||||
printf("\tprovides: %s", provides.name);
|
printf("\tprovides: %s", provides.Name().String());
|
||||||
if (provides.haveVersion) {
|
if (provides.Version().InitCheck() == B_OK)
|
||||||
printf(" = ");
|
printf(" = %s", provides.Version().ToString().String());
|
||||||
_PrintPackageVersion(provides.version);
|
|
||||||
}
|
if (provides.CompatibleVersion().InitCheck() == B_OK) {
|
||||||
if (provides.haveCompatibleVersion) {
|
printf(" (compatible >= %s)",
|
||||||
printf(" (compatible >= ");
|
provides.CompatibleVersion().ToString().String());
|
||||||
_PrintPackageVersion(provides.compatibleVersion);
|
|
||||||
printf(")");
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintRequires(const BPackageResolvableExpressionData& requires) const
|
void PrintRequires(const BPackageResolvableExpression& requires) const
|
||||||
{
|
{
|
||||||
_PrintResolvableExpression("requires", requires);
|
_PrintResolvableExpression("requires", requires);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintSupplements(const BPackageResolvableExpressionData& supplements)
|
void PrintSupplements(const BPackageResolvableExpression& supplements)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
_PrintResolvableExpression("supplements", supplements);
|
_PrintResolvableExpression("supplements", supplements);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintConflicts(const BPackageResolvableExpressionData& conflicts) const
|
void PrintConflicts(const BPackageResolvableExpression& conflicts) const
|
||||||
{
|
{
|
||||||
_PrintResolvableExpression("conflicts", conflicts);
|
_PrintResolvableExpression("conflicts", conflicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFreshens(const BPackageResolvableExpressionData& freshens) const
|
void PrintFreshens(const BPackageResolvableExpression& freshens) const
|
||||||
{
|
{
|
||||||
_PrintResolvableExpression("freshens", freshens);
|
_PrintResolvableExpression("freshens", freshens);
|
||||||
}
|
}
|
||||||
@@ -249,40 +328,42 @@ public:
|
|||||||
printf("\treplaces: %s\n", replaces);
|
printf("\treplaces: %s\n", replaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintGlobalWritableFile(const BGlobalWritableFileInfoData& info) const
|
void PrintGlobalWritableFile(const BGlobalWritableFileInfo& info) const
|
||||||
{
|
{
|
||||||
printf("\tglobal writable file: %s", info.path);
|
printf("\tglobal writable file: %s", info.Path().String());
|
||||||
if (info.isDirectory)
|
if (info.IsDirectory())
|
||||||
printf( " directory");
|
printf( " directory");
|
||||||
if (info.updateType < B_WRITABLE_FILE_UPDATE_TYPE_ENUM_COUNT) {
|
if (info.UpdateType() < B_WRITABLE_FILE_UPDATE_TYPE_ENUM_COUNT) {
|
||||||
printf(" %s\n",
|
printf(" %s\n",
|
||||||
BPackageInfo::kWritableFileUpdateTypes[info.updateType]);
|
BPackageInfo::kWritableFileUpdateTypes[info.UpdateType()]);
|
||||||
} else
|
} else
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintUserSettingsFile(const BUserSettingsFileInfoData& info) const
|
void PrintUserSettingsFile(const BUserSettingsFileInfo& info) const
|
||||||
{
|
{
|
||||||
printf("\tuser settings file: %s", info.path);
|
printf("\tuser settings file: %s", info.Path().String());
|
||||||
if (info.isDirectory)
|
if (info.IsDirectory())
|
||||||
printf( " directory\n");
|
printf( " directory\n");
|
||||||
else if (info.templatePath != NULL)
|
else if (!info.TemplatePath().IsEmpty())
|
||||||
printf(" template %s\n", info.templatePath);
|
printf(" template %s\n", info.TemplatePath().String());
|
||||||
else
|
else
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintUser(const BUserData& user) const
|
void PrintUser(const BUser& user) const
|
||||||
{
|
{
|
||||||
printf("\tuser: %s\n", user.name);
|
printf("\tuser: %s\n", user.Name().String());
|
||||||
if (user.realName != NULL)
|
if (!user.RealName().IsEmpty())
|
||||||
printf("\t\treal name: %s\n", user.realName);
|
printf("\t\treal name: %s\n", user.RealName().String());
|
||||||
if (user.home != NULL)
|
if (!user.Home().IsEmpty())
|
||||||
printf("\t\thome: %s\n", user.home);
|
printf("\t\thome: %s\n", user.Home().String());
|
||||||
if (user.shell != NULL)
|
if (!user.Shell().IsEmpty())
|
||||||
printf("\t\tshell: %s\n", user.shell);
|
printf("\t\tshell: %s\n", user.Shell().String());
|
||||||
for (size_t i = 0; i < user.groupCount; i++)
|
|
||||||
printf("\t\tgroup: %s\n", user.groups[i]);
|
int32 groupCount = user.Groups().CountStrings();
|
||||||
|
for (int32 i = 0; i < groupCount; i++)
|
||||||
|
printf("\t\tgroup: %s\n", user.Groups().StringAt(i).String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintGroup(const char* group) const
|
void PrintGroup(const char* group) const
|
||||||
@@ -301,24 +382,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void _PrintPackageVersion(const BPackageVersionData& version)
|
|
||||||
{
|
|
||||||
printf("%s", BPackageVersion(version).ToString().String());
|
|
||||||
}
|
|
||||||
|
|
||||||
void _PrintResolvableExpression(const char* fieldName,
|
void _PrintResolvableExpression(const char* fieldName,
|
||||||
const BPackageResolvableExpressionData& expression) const
|
const BPackageResolvableExpression& expression) const
|
||||||
{
|
{
|
||||||
printf("\t%s: %s", fieldName, expression.name);
|
printf("\t%s: %s\n", fieldName, expression.ToString().String());
|
||||||
if (expression.haveOpAndVersion) {
|
|
||||||
printf(" %s ",
|
|
||||||
expression.op < B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT
|
|
||||||
? BPackageResolvableExpression::kOperatorNames[
|
|
||||||
expression.op]
|
|
||||||
: "<invalid operator>");
|
|
||||||
_PrintPackageVersion(expression.version);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <Entry.h>
|
||||||
#include <package/hpkg/PackageContentHandler.h>
|
#include <package/hpkg/PackageContentHandler.h>
|
||||||
#include <package/hpkg/PackageEntry.h>
|
#include <package/hpkg/PackageEntry.h>
|
||||||
#include <package/hpkg/PackageEntryAttribute.h>
|
#include <package/hpkg/PackageEntryAttribute.h>
|
||||||
@@ -357,6 +358,31 @@ command_list(int argc, const char* const* argv)
|
|||||||
|
|
||||||
const char* packageFileName = argv[optind++];
|
const char* packageFileName = argv[optind++];
|
||||||
|
|
||||||
|
// If the file doesn't look like a package file, try to load it as a
|
||||||
|
// package info file.
|
||||||
|
if (!BString(packageFileName).EndsWith(".hpkg")) {
|
||||||
|
struct ErrorListener : BPackageInfo::ParseErrorListener {
|
||||||
|
virtual void OnError(const BString& msg, int line, int col)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s:%d:%d: %s\n", fPath, line, col,
|
||||||
|
msg.String());
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* fPath;
|
||||||
|
} errorListener;
|
||||||
|
errorListener.fPath = packageFileName;
|
||||||
|
|
||||||
|
BPackageInfo info;
|
||||||
|
if (info.ReadFromConfigFile(BEntry(packageFileName), &errorListener)
|
||||||
|
!= B_OK) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("package-attributes:\n");
|
||||||
|
PackageInfoPrinter().PrintPackageInfo(info);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
BHPKG::BStandardErrorOutput errorOutput;
|
BHPKG::BStandardErrorOutput errorOutput;
|
||||||
|
|
||||||
// current package file format version
|
// current package file format version
|
||||||
|
|||||||
Reference in New Issue
Block a user