Improve internal tooling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -22,7 +23,34 @@ var rootCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
registry = &updater.ResourceRegistry{}
|
||||
return registry.Initialize(utils.NewDirStructure(absPath, 0o755))
|
||||
err = registry.Initialize(utils.NewDirStructure(absPath, 0o755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "stable.json",
|
||||
Stable: true,
|
||||
Beta: false,
|
||||
})
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "beta.json",
|
||||
Stable: false,
|
||||
Beta: true,
|
||||
})
|
||||
|
||||
err = registry.LoadIndexes(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = registry.ScanStorage("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/updater"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -29,28 +27,6 @@ func purge(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
defer log.Shutdown()
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "stable.json",
|
||||
Stable: true,
|
||||
Beta: false,
|
||||
})
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "beta.json",
|
||||
Stable: false,
|
||||
Beta: true,
|
||||
})
|
||||
|
||||
err = registry.LoadIndexes(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = scanStorage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
registry.SelectVersions()
|
||||
registry.Purge(3)
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -22,48 +19,21 @@ var scanCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func scan(cmd *cobra.Command, args []string) error {
|
||||
err := scanStorage()
|
||||
// Reset and rescan.
|
||||
registry.Reset()
|
||||
err := registry.ScanStorage("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// export beta
|
||||
data, err := json.MarshalIndent(exportSelected(true), "", " ")
|
||||
// Export latest versions.
|
||||
data, err := json.MarshalIndent(exportSelected(false), "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// print
|
||||
fmt.Println("beta:")
|
||||
// Print them.
|
||||
fmt.Println(string(data))
|
||||
|
||||
// export stable
|
||||
data, err = json.MarshalIndent(exportSelected(false), "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// print
|
||||
fmt.Println("\nstable:")
|
||||
fmt.Println(string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func scanStorage() error {
|
||||
files, err := ioutil.ReadDir(registry.StorageDir().Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// scan "all" and all "os_platform" dirs
|
||||
for _, file := range files {
|
||||
if file.IsDir() && (file.Name() == "all" || strings.Contains(file.Name(), "_")) {
|
||||
err := registry.ScanStorage(filepath.Join(registry.StorageDir().Path, file.Name()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/safing/portbase/updater"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -29,37 +27,14 @@ var stageCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func stage(cmd *cobra.Command, args []string) error {
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "stable.json",
|
||||
Stable: true,
|
||||
Beta: false,
|
||||
})
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "beta.json",
|
||||
Stable: false,
|
||||
Beta: true,
|
||||
})
|
||||
|
||||
err := registry.LoadIndexes(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = scanStorage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if we want to reset staging instead.
|
||||
if stageReset {
|
||||
for _, stagedPath := range exportStaging(true) {
|
||||
err = os.Remove(stagedPath)
|
||||
err := os.Remove(stagedPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -21,10 +22,8 @@ var updateCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func update(cmd *cobra.Command, args []string) error {
|
||||
err := scanStorage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Set stable and beta to latest version.
|
||||
updateToLatestVersion(true, true)
|
||||
|
||||
// Export versions.
|
||||
betaData, err := json.MarshalIndent(exportSelected(true), "", " ")
|
||||
@@ -75,3 +74,14 @@ func update(cmd *cobra.Command, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateToLatestVersion(stable, beta bool) error {
|
||||
for _, resource := range registry.Export() {
|
||||
sort.Sort(resource)
|
||||
err := resource.AddVersion(resource.Versions[0].VersionNumber, false, stable, beta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user