Add support for dependency & architectures as common options.

This commit is contained in:
Andrey Smirnov
2014-01-12 23:55:58 +04:00
parent f9853de144
commit d684c87fd1
6 changed files with 50 additions and 35 deletions

View File

@@ -38,13 +38,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
return err
}
var architectures []string
archs := cmd.Flag.Lookup("architecture").Value.String()
if len(archs) > 0 {
architectures = strings.Split(archs, ",")
}
repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], architectures)
repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], context.architecturesList)
if err != nil {
return fmt.Errorf("unable to create mirror: %s", err)
}
@@ -155,10 +149,8 @@ Create only stores metadata about new mirror, and fetches Release files (it does
`,
Flag: *flag.NewFlagSet("aptly-mirror-create", flag.ExitOnError),
}
cmd.Flag.String("architecture", "", "limit architectures to download, comma-delimited list")
return cmd
}
func makeCmdMirrorList() *commander.Command {

View File

@@ -62,16 +62,10 @@ func aptlyPublishSnapshot(cmd *commander.Command, args []string) error {
}
}
var architecturesList []string
architectures := cmd.Flag.Lookup("architectures").Value.String()
if architectures != "" {
architecturesList = strings.Split(architectures, ",")
}
signer := &utils.GpgSigner{}
signer.SetKey(cmd.Flag.Lookup("gpg-key").Value.String())
published := debian.NewPublishedRepo(prefix, distribution, component, architecturesList, snapshot)
published := debian.NewPublishedRepo(prefix, distribution, component, context.architecturesList, snapshot)
packageCollection := debian.NewPackageCollection(context.database)
err = published.Publish(context.packageRepository, packageCollection, signer)
@@ -104,7 +98,6 @@ Publishes snapshot as Debian repository ready to be used by apt tools.
}
cmd.Flag.String("distribution", "", "distribution name to publish")
cmd.Flag.String("component", "", "component name to publish")
cmd.Flag.String("architectures", "", "list of architectures to publish (comma-separated)")
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
return cmd

View File

@@ -164,9 +164,8 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
var architecturesList []string
architectures := cmd.Flag.Lookup("architectures").Value.String()
if architectures != "" {
architecturesList = strings.Split(architectures, ",")
if len(context.architecturesList) > 0 {
architecturesList = context.architecturesList
} else {
architecturesList = packageList.Architectures()
}
@@ -175,7 +174,7 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
return fmt.Errorf("unable to determine list of architectures, please specify explicitly")
}
missing, err := packageList.VerifyDependencies(0, architecturesList, sourcePackageList)
missing, err := packageList.VerifyDependencies(context.dependencyOptions, architecturesList, sourcePackageList)
if err != nil {
return fmt.Errorf("unable to verify dependencies: %s", err)
}
@@ -248,9 +247,8 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
// Calculate architectures
var architecturesList []string
architectures := cmd.Flag.Lookup("architectures").Value.String()
if architectures != "" {
architecturesList = strings.Split(architectures, ",")
if len(context.architecturesList) > 0 {
architecturesList = context.architecturesList
} else {
architecturesList = packageList.Architectures()
}
@@ -306,7 +304,7 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
pL := debian.NewPackageList()
pL.Add(pkg)
missing, err := pL.VerifyDependencies(0, []string{arch}, packageList)
missing, err := pL.VerifyDependencies(context.dependencyOptions, []string{arch}, packageList)
if err != nil {
color.Printf("@y[!]@| @!Error while verifying dependencies for pkg %s: %s@|\n", pkg, err)
}
@@ -403,8 +401,6 @@ All unsatisfied dependencies are returned.
Flag: *flag.NewFlagSet("aptly-snapshot-verify", flag.ExitOnError),
}
cmd.Flag.String("architectures", "", "list of architectures to verify (comma-separated)")
return cmd
}
@@ -422,7 +418,6 @@ process.
Flag: *flag.NewFlagSet("aptly-snapshot-pull", flag.ExitOnError),
}
cmd.Flag.String("architectures", "", "list of architectures to consider during pull (comma-separated)")
cmd.Flag.Bool("dry-run", false, "don't create destination snapshot, just show what would be pulled")
cmd.Flag.Bool("no-deps", false, "don't process dependencies, just pull listed packages")

27
main.go
View File

@@ -9,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
)
// aptly version
@@ -32,12 +33,19 @@ take snapshots and publish them back as Debian repositories.`,
makeCmdVersion(),
},
}
cmd.Flag.Bool("dep-follow-suggests", false, "when processing dependencies, follow Suggests")
cmd.Flag.Bool("dep-follow-recommends", false, "when processing dependencies, follow Recommends")
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if depdency is 'a|b'")
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
}
var context struct {
downloader utils.Downloader
database database.Storage
packageRepository *debian.Repository
dependencyOptions int
architecturesList []string
}
func main() {
@@ -63,17 +71,32 @@ func main() {
utils.SaveConfig(configLocations[0], &utils.Config)
}
context.dependencyOptions = 0
if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) {
context.dependencyOptions |= debian.DepFollowSuggests
}
if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) {
context.dependencyOptions |= debian.DepFollowRecommends
}
if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) {
context.dependencyOptions |= debian.DepFollowAllVariants
}
context.architecturesList = utils.Config.Architectures
optionArchitectures := cmd.Flag.Lookup("architectures").Value.String()
if optionArchitectures != "" {
context.architecturesList = strings.Split(optionArchitectures, ",")
}
context.downloader = utils.NewDownloader(utils.Config.DownloadConcurrency)
defer context.downloader.Shutdown()
// TODO: configure DB dir
context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
if err != nil {
log.Fatalf("can't open database: %s", err)
}
defer context.database.Close()
// TODO:configure pool dir
context.packageRepository = debian.NewRepository(utils.Config.RootDir)
err = cmd.Dispatch(os.Args[1:])

View File

@@ -8,14 +8,22 @@ import (
// ConfigStructure is structure of main configuration
type ConfigStructure struct {
RootDir string `json:"rootDir"`
DownloadConcurrency int `json:"downloadConcurrency"`
RootDir string `json:"rootDir"`
DownloadConcurrency int `json:"downloadConcurrency"`
Architectures []string `json:"architectures"`
DepFollowSuggests bool `json:"dependencyFollowSuggests"`
DepFollowRecommends bool `json:"dependencyFollowRecommends"`
DepFollowAllVariants bool `json:"dependencyFollowAllVariants"`
}
// Config is configuration for aptly, shared by all modules
var Config = ConfigStructure{
RootDir: filepath.Join(os.Getenv("HOME"), ".aptly"),
DownloadConcurrency: 4,
RootDir: filepath.Join(os.Getenv("HOME"), ".aptly"),
DownloadConcurrency: 4,
Architectures: []string{},
DepFollowSuggests: false,
DepFollowRecommends: false,
DepFollowAllVariants: false,
}
// LoadConfig loads configuration from json file

View File

@@ -43,7 +43,11 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
c.Check(string(buf), Equals, ""+
"{\n"+
" \"rootDir\": \"/tmp/aptly\",\n"+
" \"downloadConcurrency\": 5\n"+
" \"downloadConcurrency\": 5,\n"+
" \"architectures\": null,\n"+
" \"dependencyFollowSuggests\": false,\n"+
" \"dependencyFollowRecommends\": false,\n"+
" \"dependencyFollowAllVariants\": false\n"+
"}")
}