Skip to content

Commit 6c75dc8

Browse files
committed
♻️ Synced dbin 📦 <-- 1.5: update AM metadata generator ⌚
1 parent f272da1 commit 6c75dc8

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

misc/cmd/dbinRepoIndexGenerators/1.5/generator.go

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sort"
99
"strconv"
1010
"strings"
11+
"path/filepath"
1112

1213
"github.com/fxamacker/cbor/v2"
1314
"github.com/goccy/go-json"
@@ -374,7 +375,7 @@ func saveAll(filename string, metadata DbinMetadata) error {
374375
if err := saveMsgp(filename, metadata); err != nil {
375376
return err
376377
}
377-
//genAMMeta(filename, dbinMetadata)
378+
genAMMeta(filename, metadata)
378379
return saveYAML(filename, metadata)
379380
}
380381

@@ -601,9 +602,10 @@ func t[T any](cond bool, vtrue, vfalse T) T {
601602
return vfalse
602603
}
603604

604-
/* The following is a _favor_ I'm doing to ivan-hc and everyone that contributes
605-
* And actively endorses or uses AM
606-
* They are a tremendous help to the Portable Linux Apps community!
605+
/* AM is one of the most relevant projects of the portable Linux apps community
606+
* And the AM repo is a thirdparty optional repo in `dbin`, so its only fair that
607+
* we help them distribute more programs too! -
608+
*/
607609
const pipeRepl = "ǀ" // Replacement for `|` to avoid breaking the MD table
608610
func replacePipeFields(pkg *DbinItem) {
609611
pkg.Name = strings.ReplaceAll(pkg.Name, "|", pipeRepl)
@@ -613,49 +615,57 @@ func replacePipeFields(pkg *DbinItem) {
613615
pkg.WebURLs[i] = strings.ReplaceAll(pkg.WebURLs[i], "|", pipeRepl)
614616
}
615617
}
616-
617618
func genAMMeta(filename string, metadata DbinMetadata) {
618-
replaceEmptyWithNil := func(value string) string {
619-
if value == "" {
620-
return "nil"
621-
}
622-
return value
623-
}
624-
625619
file, err := os.Create(filename + ".txt")
626620
if err != nil {
627621
fmt.Println("Error creating output file:", err)
628622
return
629623
}
630624
defer file.Close()
631625

632-
for _, items := range metadata {
633-
for _, pkg := range items {
634-
pkg.Name = replaceEmptyWithNil(pkg.Name)
635-
pkg.Description = replaceEmptyWithNil(pkg.Description)
636-
pkg.DownloadURL = replaceEmptyWithNil(pkg.DownloadURL)
637-
638-
webURL := pkg.DownloadURL
639-
if webURL == "nil" && len(pkg.WebURLs) > 0 {
640-
webURL = pkg.WebURLs[0]
641-
}
626+
file.WriteString("| appname | description | site | download | version |\n")
627+
file.WriteString("|---------|-------------|------|----------|---------|\n")
642628

643-
replacePipeFields(&pkg)
629+
var allEntries []DbinItem
630+
for _, entries := range metadata {
631+
allEntries = append(allEntries, entries...)
632+
}
644633

645-
pkgName := pkg.Name
646-
strings.ToLower(pkgName)
647-
strings.ReplaceAll(pkgName, " ", "-")
634+
sort.Slice(allEntries, func(i, j int) bool {
635+
return strings.ToLower(allEntries[i].Name) < strings.ToLower(allEntries[j].Pkg)
636+
})
648637

649-
bsum := pkg.Bsum
650-
if len(bsum) > 12 {
651-
bsum = bsum[:12]
652-
} else {
653-
bsum = "nil"
654-
}
638+
for _, entry := range allEntries {
639+
pkg := strings.TrimSuffix(entry.Pkg, filepath.Ext(entry.Pkg))
655640

656-
file.WriteString(fmt.Sprintf("| %s | %s | %s | %s | %s |\n",
657-
pkgName, pkg.Description, webURL, pkg.DownloadURL, bsum))
641+
if pkg != "" {
642+
entry.Pkg = pkg
658643
}
644+
645+
siteURL := ""
646+
if len(entry.SrcURLs) > 0 {
647+
siteURL = entry.SrcURLs[0]
648+
} else if len(entry.WebURLs) > 0 {
649+
siteURL = entry.WebURLs[0]
650+
} else {
651+
siteURL = "https://github.com/xplshn/dbin"
652+
}
653+
654+
version := entry.Version
655+
if version == "" && entry.BuildDate != "" {
656+
version = entry.BuildDate
657+
}
658+
if version == "" {
659+
version = "not_available"
660+
}
661+
662+
file.WriteString(fmt.Sprintf("| %s | %s | %s | %s | %s |\n",
663+
pkg,
664+
t(entry.Description != "", entry.Description, "not_available"),
665+
t(siteURL != "", siteURL, "not_available"),
666+
entry.DownloadURL,
667+
t(version != "", version, "not_available"),
668+
))
659669
}
660670
}
661-
*/
671+

0 commit comments

Comments
 (0)