More improvements for the readable info functions

This commit is contained in:
2026-01-27 12:47:25 +02:00
parent b3dc6e3e34
commit dd20574470
2 changed files with 40 additions and 34 deletions
+21 -16
View File
@@ -326,6 +326,11 @@ func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string { func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
builder := strings.Builder{} builder := strings.Builder{}
builderWriteStringNotEmpty := func(label string, value string) {
if value != "" {
builder.WriteString(label + ": " + value + "\n")
}
}
builderWriteArray := func(label string, array []string, sort bool) { builderWriteArray := func(label string, array []string, sort bool) {
if len(array) == 0 { if len(array) == 0 {
return return
@@ -342,22 +347,21 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
} }
} }
// Main information
builder.WriteString("Name: " + entry.Info.Name + "\n") builder.WriteString("Name: " + entry.Info.Name + "\n")
builder.WriteString("Database: " + entry.Database.Name + "\n") builder.WriteString("Database: " + entry.Database.Name + "\n")
builder.WriteString("Description: " + entry.Info.Description + "\n") builder.WriteString("Description: " + entry.Info.Description + "\n")
builder.WriteString("Version: " + entry.Info.GetFullVersion() + "\n") builder.WriteString("Version: " + entry.Info.GetFullVersion() + "\n")
if entry.Info.Url != "" { builderWriteStringNotEmpty("URL", entry.Info.Url)
builder.WriteString("URL: " + entry.Info.Url + "\n") builderWriteStringNotEmpty("License", entry.Info.License)
}
if entry.Info.License != "" {
builder.WriteString("License: " + entry.Info.License + "\n")
}
builderWriteArray("Maintainers", entry.Info.Maintainers, false) builderWriteArray("Maintainers", entry.Info.Maintainers, false)
builder.WriteString("Architecture: " + entry.Info.Arch + "\n") builder.WriteString("Architecture: " + entry.Info.Arch + "\n")
if entry.Info.Type == "source" && entry.Info.OutputArch != "" && entry.Info.OutputArch != GetArch() { if entry.Info.Type == "source" && entry.Info.OutputArch != "" && entry.Info.OutputArch != GetArch() {
builder.WriteString("Output architecture: " + entry.Info.OutputArch + "\n") builder.WriteString("Output architecture: " + entry.Info.OutputArch + "\n")
} }
builder.WriteString("Type: " + entry.Info.Type + "\n") builder.WriteString("Type: " + entry.Info.Type + "\n")
// Dependencies
builderWriteArray("Dependencies", entry.Info.Depends, true) builderWriteArray("Dependencies", entry.Info.Depends, true)
if entry.Info.Type == "source" { if entry.Info.Type == "source" {
builderWriteArray("Make dependencies", entry.Info.MakeDepends, true) builderWriteArray("Make dependencies", entry.Info.MakeDepends, true)
@@ -374,26 +378,24 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
} }
} }
} }
dependants := entry.GetEntryDependants() builderWriteArray("Dependant packages", entry.GetEntryDependants(), true)
if len(dependants) > 0 { builderWriteArray("Optionally dependant packages", entry.GetEntryOptionalDependants(), true)
builderWriteArray("Dependant packages", dependants, false)
} // Other package relations
optionalDependants := entry.GetEntryOptionalDependants()
if len(optionalDependants) > 0 {
builderWriteArray("Optionally dependant packages", optionalDependants, false)
}
builderWriteArray("Conflicting packages", entry.Info.Conflicts, true) builderWriteArray("Conflicting packages", entry.Info.Conflicts, true)
builderWriteArray("Provided packages", entry.Info.Provides, true) builderWriteArray("Provided packages", entry.Info.Provides, true)
builderWriteArray("Replaces packages", entry.Info.Replaces, true) builderWriteArray("Replaces packages", entry.Info.Replaces, true)
// Split packages
if entry.Info.Type == "source" && len(entry.Info.SplitPackages) != 0 { if entry.Info.Type == "source" && len(entry.Info.SplitPackages) != 0 {
splitPkgs := make([]string, len(entry.Info.SplitPackages)) splitPkgs := make([]string, len(entry.Info.SplitPackages))
for i, splitPkgInfo := range entry.Info.SplitPackages { for i, splitPkgInfo := range entry.Info.SplitPackages {
splitPkgs[i] = splitPkgInfo.Name splitPkgs[i] = splitPkgInfo.Name
} }
builderWriteArray("Split Packages", splitPkgs, true) builderWriteArray("Split packages", splitPkgs, true)
} }
// Installation reason
if rootDir != "" && IsPackageInstalled(entry.Info.Name, rootDir) { if rootDir != "" && IsPackageInstalled(entry.Info.Name, rootDir) {
installationReason := GetInstallationReason(entry.Info.Name, rootDir) installationReason := GetInstallationReason(entry.Info.Name, rootDir)
var installationReasonString string var installationReasonString string
@@ -407,8 +409,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
default: default:
installationReasonString = "Unknown" installationReasonString = "Unknown"
} }
builder.WriteString("Installation Reason: " + installationReasonString + "\n") builder.WriteString("Installation reason: " + installationReasonString + "\n")
} }
// Installed size
if entry.Info.Type == "binary" { if entry.Info.Type == "binary" {
installedSize := entry.InstalledSize installedSize := entry.InstalledSize
var installedSizeStr string var installedSizeStr string
@@ -419,5 +423,6 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
} }
builder.WriteString("Installed size: " + installedSizeStr + "\n") builder.WriteString("Installed size: " + installedSizeStr + "\n")
} }
return strings.TrimSpace(builder.String()) return strings.TrimSpace(builder.String())
} }
+19 -18
View File
@@ -541,6 +541,11 @@ func ReadPackageInfo(contents string) (*PackageInfo, error) {
func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string { func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
builder := strings.Builder{} builder := strings.Builder{}
builderWriteStringNotEmpty := func(label string, value string) {
if value != "" {
builder.WriteString(label + ": " + value + "\n")
}
}
builderWriteArray := func(label string, array []string, sort bool) { builderWriteArray := func(label string, array []string, sort bool) {
if len(array) == 0 { if len(array) == 0 {
return return
@@ -557,24 +562,22 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
} }
} }
// Main information
builder.WriteString("Name: " + pkgInfo.Name + "\n") builder.WriteString("Name: " + pkgInfo.Name + "\n")
builder.WriteString("Description: " + pkgInfo.Description + "\n") builder.WriteString("Description: " + pkgInfo.Description + "\n")
builder.WriteString("Version: " + pkgInfo.GetFullVersion() + "\n") builder.WriteString("Version: " + pkgInfo.GetFullVersion() + "\n")
if pkgInfo.Url != "" { builderWriteStringNotEmpty("URL", pkgInfo.Url)
builder.WriteString("URL: " + pkgInfo.Url + "\n") builderWriteStringNotEmpty("License", pkgInfo.License)
}
if pkgInfo.License != "" {
builder.WriteString("License: " + pkgInfo.License + "\n")
}
builderWriteArray("Maintainers", pkgInfo.Maintainers, false) builderWriteArray("Maintainers", pkgInfo.Maintainers, false)
builder.WriteString("Architecture: " + pkgInfo.Arch + "\n") builder.WriteString("Architecture: " + pkgInfo.Arch + "\n")
if pkgInfo.Type == "source" && pkgInfo.OutputArch != "" && pkgInfo.OutputArch != GetArch() { if pkgInfo.Type == "source" && pkgInfo.OutputArch != "" && pkgInfo.OutputArch != GetArch() {
builder.WriteString("Output architecture: " + pkgInfo.Arch + "\n") builder.WriteString("Output architecture: " + pkgInfo.OutputArch + "\n")
} }
builder.WriteString("Type: " + pkgInfo.Type + "\n") builder.WriteString("Type: " + pkgInfo.Type + "\n")
// Dependencies
builderWriteArray("Dependencies", pkgInfo.Depends, true) builderWriteArray("Dependencies", pkgInfo.Depends, true)
if pkgInfo.Type == "source" { if pkgInfo.Type == "source" {
builderWriteArray("Runtime dependencies", pkgInfo.RuntimeDepends, true)
builderWriteArray("Make dependencies", pkgInfo.MakeDepends, true) builderWriteArray("Make dependencies", pkgInfo.MakeDepends, true)
} }
builderWriteArray("Runtime dependencies", pkgInfo.RuntimeDepends, true) builderWriteArray("Runtime dependencies", pkgInfo.RuntimeDepends, true)
@@ -589,26 +592,24 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
} }
} }
} }
dependants := pkgInfo.GetPackageDependants(rootDir) builderWriteArray("Dependant packages", pkgInfo.GetPackageDependants(rootDir), true)
if len(dependants) > 0 { builderWriteArray("Optionally dependant packages", pkgInfo.GetPackageOptionalDependants(rootDir), true)
builderWriteArray("Dependant packages", dependants, true)
} // Other package relations
optionalDependants := pkgInfo.GetPackageOptionalDependants(rootDir)
if len(optionalDependants) > 0 {
builderWriteArray("Optionally dependant packages", optionalDependants, true)
}
builderWriteArray("Conflicting packages", pkgInfo.Conflicts, true) builderWriteArray("Conflicting packages", pkgInfo.Conflicts, true)
builderWriteArray("Provided packages", pkgInfo.Provides, true) builderWriteArray("Provided packages", pkgInfo.Provides, true)
builderWriteArray("Replaces packages", pkgInfo.Replaces, true) builderWriteArray("Replaces packages", pkgInfo.Replaces, true)
// Split packages
if pkgInfo.Type == "source" && len(pkgInfo.SplitPackages) != 0 { if pkgInfo.Type == "source" && len(pkgInfo.SplitPackages) != 0 {
splitPkgs := make([]string, len(pkgInfo.SplitPackages)) splitPkgs := make([]string, len(pkgInfo.SplitPackages))
for i, splitPkgInfo := range pkgInfo.SplitPackages { for i, splitPkgInfo := range pkgInfo.SplitPackages {
splitPkgs[i] = splitPkgInfo.Name splitPkgs[i] = splitPkgInfo.Name
} }
builderWriteArray("Split Packages", splitPkgs, true) builderWriteArray("Split packages", splitPkgs, true)
} }
// Installation reason
if rootDir != "" && IsPackageInstalled(pkgInfo.Name, rootDir) { if rootDir != "" && IsPackageInstalled(pkgInfo.Name, rootDir) {
installationReason := GetInstallationReason(pkgInfo.Name, rootDir) installationReason := GetInstallationReason(pkgInfo.Name, rootDir)
var installationReasonString string var installationReasonString string
@@ -622,7 +623,7 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
default: default:
installationReasonString = "Unknown" installationReasonString = "Unknown"
} }
builder.WriteString("Installation Reason: " + installationReasonString + "\n") builder.WriteString("Installation reason: " + installationReasonString + "\n")
} }
return strings.TrimSpace(builder.String()) return strings.TrimSpace(builder.String())