Reorganize codebase #10
@ -43,7 +43,10 @@ var doCleanup = false
|
|||||||
var showRepoInfo = false
|
var showRepoInfo = false
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bpmlib.ReadConfig()
|
err := bpmlib.ReadConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error: could not read BPM config: %s", err)
|
||||||
|
}
|
||||||
resolveFlags()
|
resolveFlags()
|
||||||
resolveCommand()
|
resolveCommand()
|
||||||
}
|
}
|
||||||
@ -244,6 +247,12 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
log.Fatalf("Error: could not setup operation: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit if operation contains no actions
|
||||||
|
if len(operation.Actions) == 0 {
|
||||||
|
fmt.Println("No action needs to be taken")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
operation.ShowOperationSummary()
|
operation.ShowOperationSummary()
|
||||||
|
|
||||||
@ -289,6 +298,12 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
log.Fatalf("Error: could not setup operation: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit if operation contains no actions
|
||||||
|
if len(operation.Actions) == 0 {
|
||||||
|
fmt.Println("No action needs to be taken")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
operation.ShowOperationSummary()
|
operation.ShowOperationSummary()
|
||||||
|
|
||||||
@ -358,6 +373,12 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
log.Fatalf("Error: could not setup operation: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit if operation contains no actions
|
||||||
|
if len(operation.Actions) == 0 {
|
||||||
|
fmt.Println("No action needs to be taken")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
operation.ShowOperationSummary()
|
operation.ShowOperationSummary()
|
||||||
|
|
||||||
@ -398,6 +419,12 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
log.Fatalf("Error: could not setup operation: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit if operation contains no actions
|
||||||
|
if len(operation.Actions) == 0 {
|
||||||
|
fmt.Println("No action needs to be taken")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
operation.ShowOperationSummary()
|
operation.ShowOperationSummary()
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package bpmlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,14 +16,16 @@ type BPMConfigStruct struct {
|
|||||||
|
|
||||||
var BPMConfig BPMConfigStruct
|
var BPMConfig BPMConfigStruct
|
||||||
|
|
||||||
func ReadConfig() {
|
func ReadConfig() (err error) {
|
||||||
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
if _, err = os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := os.ReadFile("/etc/bpm.conf")
|
bytes, err := os.ReadFile("/etc/bpm.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
BPMConfig = BPMConfigStruct{
|
BPMConfig = BPMConfigStruct{
|
||||||
CompilationEnv: make([]string, 0),
|
CompilationEnv: make([]string, 0),
|
||||||
SilentCompilation: false,
|
SilentCompilation: false,
|
||||||
@ -33,19 +34,23 @@ func ReadConfig() {
|
|||||||
}
|
}
|
||||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
||||||
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
||||||
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, repo := range BPMConfig.Repositories {
|
for _, repo := range BPMConfig.Repositories {
|
||||||
repo.Entries = make(map[string]*RepositoryEntry)
|
repo.Entries = make(map[string]*RepositoryEntry)
|
||||||
repo.VirtualPackages = make(map[string][]string)
|
repo.VirtualPackages = make(map[string][]string)
|
||||||
err := repo.ReadLocalDatabase()
|
err := repo.ReadLocalDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,10 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload config and local databases
|
// Reload config and local databases
|
||||||
ReadConfig()
|
err = ReadConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not read BPM config: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Get installed packages and check for updates
|
// Get installed packages and check for updates
|
||||||
pkgs, err := GetInstalledPackages(rootDir)
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
|
@ -195,7 +195,7 @@ func (operation *BPMOperation) Cleanup(verbose bool) error {
|
|||||||
// Get all installed packages
|
// Get all installed packages
|
||||||
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not get installed packages: %s\n", err)
|
return fmt.Errorf("could not get installed packages: %s", err)
|
||||||
}
|
}
|
||||||
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
||||||
for i, value := range installedPackageNames {
|
for i, value := range installedPackageNames {
|
||||||
@ -329,8 +329,8 @@ func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error)
|
|||||||
|
|
||||||
func (operation *BPMOperation) ShowOperationSummary() {
|
func (operation *BPMOperation) ShowOperationSummary() {
|
||||||
if len(operation.Actions) == 0 {
|
if len(operation.Actions) == 0 {
|
||||||
fmt.Println("All packages are up to date!")
|
fmt.Println("No action needs to be taken")
|
||||||
os.Exit(0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range operation.Actions {
|
for _, value := range operation.Actions {
|
||||||
@ -348,9 +348,6 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||||
sourceInfo := ""
|
sourceInfo := ""
|
||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
if operation.RootDir != "/" {
|
|
||||||
log.Fatalf("cannot compile and install source packages to a different root directory")
|
|
||||||
}
|
|
||||||
sourceInfo = "(From Source)"
|
sourceInfo = "(From Source)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user