mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Commands aptly repo move, copy, import.
This commit is contained in:
@@ -11,9 +11,12 @@ func makeCmdRepo() *commander.Command {
|
|||||||
Short: "manage local package repositories",
|
Short: "manage local package repositories",
|
||||||
Subcommands: []*commander.Command{
|
Subcommands: []*commander.Command{
|
||||||
makeCmdRepoAdd(),
|
makeCmdRepoAdd(),
|
||||||
|
makeCmdRepoCopy(),
|
||||||
makeCmdRepoCreate(),
|
makeCmdRepoCreate(),
|
||||||
makeCmdRepoDrop(),
|
makeCmdRepoDrop(),
|
||||||
|
makeCmdRepoImport(),
|
||||||
makeCmdRepoList(),
|
makeCmdRepoList(),
|
||||||
|
makeCmdRepoMove(),
|
||||||
makeCmdRepoRemove(),
|
makeCmdRepoRemove(),
|
||||||
makeCmdRepoShow(),
|
makeCmdRepoShow(),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gonuts/commander"
|
||||||
|
"github.com/gonuts/flag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeCmdRepoCopy() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyRepoMoveCopyImport,
|
||||||
|
UsageLine: "copy <src-name> <dst-name> <package-spec> ...",
|
||||||
|
Short: "copy packages between source repos",
|
||||||
|
Long: `
|
||||||
|
Commands copy copies packages matching <package-spec> from local repo
|
||||||
|
<src-name> to local repo <dst-name>.
|
||||||
|
|
||||||
|
ex:
|
||||||
|
$ aptly repo copy testing stable 'myapp (=0.1.12)'
|
||||||
|
`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly-repo-copy", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("dry-run", false, "don't copy, just show what would be copied")
|
||||||
|
cmd.Flag.Bool("with-deps", false, "follow dependencies when processing package-spec")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gonuts/commander"
|
||||||
|
"github.com/gonuts/flag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeCmdRepoImport() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyRepoMoveCopyImport,
|
||||||
|
UsageLine: "import <src-mirror> <dst-repo> <package-spec> ...",
|
||||||
|
Short: "import package from mirror and put it into local repo",
|
||||||
|
Long: `
|
||||||
|
Commands import looks up packages matching <package-spec> in mirror <src-mirror>
|
||||||
|
and copies them to local repo <dst-repo>.
|
||||||
|
|
||||||
|
ex:
|
||||||
|
$ aptly repo import wheezy-main testing nginx
|
||||||
|
`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly-repo-import", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("dry-run", false, "don't import, just show what would be imported")
|
||||||
|
cmd.Flag.Bool("with-deps", false, "follow dependencies when processing package-spec")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gonuts/commander"
|
||||||
|
"github.com/gonuts/flag"
|
||||||
|
"github.com/smira/aptly/debian"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
if len(args) < 3 {
|
||||||
|
cmd.Usage()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
command := cmd.Name()
|
||||||
|
|
||||||
|
localRepoCollection := debian.NewLocalRepoCollection(context.database)
|
||||||
|
|
||||||
|
dstRepo, err := localRepoCollection.ByName(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = localRepoCollection.LoadComplete(dstRepo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
srcRefList *debian.PackageRefList
|
||||||
|
srcRepo *debian.LocalRepo
|
||||||
|
)
|
||||||
|
|
||||||
|
if command == "copy" || command == "move" {
|
||||||
|
srcRepo, err = localRepoCollection.ByName(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if srcRepo.UUID == dstRepo.UUID {
|
||||||
|
return fmt.Errorf("unable to %s: source and destination are the same", command)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = localRepoCollection.LoadComplete(srcRepo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
srcRefList = srcRepo.RefList()
|
||||||
|
} else if command == "import" {
|
||||||
|
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||||
|
|
||||||
|
srcRepo, err := repoCollection.ByName(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repoCollection.LoadComplete(srcRepo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if srcRepo.RefList() == nil {
|
||||||
|
return fmt.Errorf("unable to %s: mirror not updated", command)
|
||||||
|
}
|
||||||
|
|
||||||
|
srcRefList = srcRepo.RefList()
|
||||||
|
} else {
|
||||||
|
panic("unexpected command")
|
||||||
|
}
|
||||||
|
|
||||||
|
context.progress.Printf("Loading packages...\n")
|
||||||
|
|
||||||
|
packageCollection := debian.NewPackageCollection(context.database)
|
||||||
|
dstList, err := debian.NewPackageListFromRefList(dstRepo.RefList(), packageCollection)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
srcList, err := debian.NewPackageListFromRefList(srcRefList, packageCollection)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
srcList.PrepareIndex()
|
||||||
|
|
||||||
|
var architecturesList []string
|
||||||
|
|
||||||
|
withDeps := cmd.Flag.Lookup("with-deps").Value.Get().(bool)
|
||||||
|
|
||||||
|
if withDeps {
|
||||||
|
dstList.PrepareIndex()
|
||||||
|
|
||||||
|
// Calculate architectures
|
||||||
|
if len(context.architecturesList) > 0 {
|
||||||
|
architecturesList = context.architecturesList
|
||||||
|
} else {
|
||||||
|
architecturesList = dstList.Architectures(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(architecturesList)
|
||||||
|
|
||||||
|
if len(architecturesList) == 0 {
|
||||||
|
return fmt.Errorf("unable to determine list of architectures, please specify explicitly")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toProcess, err := srcList.Filter(args[2:], withDeps, dstList, context.dependencyOptions, architecturesList)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var verb string
|
||||||
|
|
||||||
|
if command == "move" {
|
||||||
|
verb = "moved"
|
||||||
|
} else if command == "copy" {
|
||||||
|
verb = "copied"
|
||||||
|
} else if command == "import" {
|
||||||
|
verb = "imported"
|
||||||
|
}
|
||||||
|
|
||||||
|
err = toProcess.ForEach(func(p *debian.Package) error {
|
||||||
|
err = dstList.Add(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if command == "move" {
|
||||||
|
srcList.Remove(p)
|
||||||
|
}
|
||||||
|
context.progress.ColoredPrintf("@g[o]@| %s %s", p, verb)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Flag.Lookup("dry-run").Value.Get().(bool) {
|
||||||
|
context.progress.Printf("\nChanges not saved, as dry run has been requested.\n")
|
||||||
|
} else {
|
||||||
|
dstRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(dstList))
|
||||||
|
|
||||||
|
err = localRepoCollection.Update(dstRepo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if command == "move" {
|
||||||
|
srcRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(srcList))
|
||||||
|
|
||||||
|
err = localRepoCollection.Update(srcRepo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCmdRepoMove() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyRepoMoveCopyImport,
|
||||||
|
UsageLine: "move <src-name> <dst-name> <package-spec> ...",
|
||||||
|
Short: "move packages between source repos",
|
||||||
|
Long: `
|
||||||
|
Commands move moves packages matching <package-spec> from local repo
|
||||||
|
<src-name> to local repo <dst-name>.
|
||||||
|
|
||||||
|
ex:
|
||||||
|
$ aptly repo move testing stable 'myapp (=0.1.12)'
|
||||||
|
`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly-repo-move", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("dry-run", false, "don't move, just show what would be moved")
|
||||||
|
cmd.Flag.Bool("with-deps", false, "follow dependencies when processing package-spec")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" {
|
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" {
|
||||||
// aptly snapshot create snap from repo mirror
|
// aptly snapshot create snap from repo repo
|
||||||
localRepoName, snapshotName := args[3], args[0]
|
localRepoName, snapshotName := args[3], args[0]
|
||||||
|
|
||||||
localRepoCollection := debian.NewLocalRepoCollection(context.database)
|
localRepoCollection := debian.NewLocalRepoCollection(context.database)
|
||||||
|
|||||||
Reference in New Issue
Block a user