Mirror update, show and list.

This commit is contained in:
Andrey Smirnov
2013-12-19 17:34:40 +04:00
parent 8e08b09aca
commit 08f045d503

View File

@@ -10,7 +10,17 @@ import (
)
func aptlyMirrorList(cmd *commander.Command, args []string) {
fmt.Printf("MIRROR LIST\n")
if len(args) != 0 {
cmd.Usage()
return
}
fmt.Printf("List of mirrors:\n")
repoCollection := debian.NewRemoteRepoCollection(context.database)
repoCollection.ForEach(func(repo *debian.RemoteRepo) {
fmt.Printf(" * %s\n", repo)
})
}
func aptlyMirrorCreate(cmd *commander.Command, args []string) {
@@ -42,7 +52,53 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) {
log.Fatalf("Unable to add mirror: %s", err)
}
log.Printf("Mirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
fmt.Printf("\nMirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
}
func aptlyMirrorShow(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
name := args[0]
repoCollection := debian.NewRemoteRepoCollection(context.database)
repo, err := repoCollection.ByName(name)
if err != nil {
log.Fatalf("Unable to show: %s", err)
}
fmt.Printf("Name: %s\n", repo.Name)
fmt.Printf("Archive Root URL: %s\n", repo.ArchiveRoot)
fmt.Printf("Distribution: %s\n", repo.Distribution)
fmt.Printf("Components: %s\n", strings.Join(repo.Components, ", "))
fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, ", "))
}
func aptlyMirrorUpdate(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
name := args[0]
repoCollection := debian.NewRemoteRepoCollection(context.database)
repo, err := repoCollection.ByName(name)
if err != nil {
log.Fatalf("Unable to update: %s", err)
}
err = repo.Fetch(context.downloader)
if err != nil {
log.Fatalf("Unable to update: %s", err)
}
err = repo.Download(context.downloader, context.database, context.packageRepository)
if err != nil {
log.Fatalf("Unable to update: %s", err)
}
}
func makeCmdMirrorCreate() *commander.Command {
@@ -82,6 +138,40 @@ ex:
return cmd
}
func makeCmdMirrorShow() *commander.Command {
cmd := &commander.Command{
Run: aptlyMirrorShow,
UsageLine: "show",
Short: "show details about remote repository mirror",
Long: `
show shows full information about mirror.
ex:
$ aptly mirror show <name>
`,
Flag: *flag.NewFlagSet("aptly-mirror-show", flag.ExitOnError),
}
return cmd
}
func makeCmdMirrorUpdate() *commander.Command {
cmd := &commander.Command{
Run: aptlyMirrorUpdate,
UsageLine: "update",
Short: "update packages from remote mirror",
Long: `
Update downloads list of packages and packages themselves.
ex:
$ aptly mirror update <name>
`,
Flag: *flag.NewFlagSet("aptly-mirror-update", flag.ExitOnError),
}
return cmd
}
func makeCmdMirror() *commander.Commander {
return &commander.Commander{
Name: "mirror",
@@ -89,9 +179,9 @@ func makeCmdMirror() *commander.Commander {
Commands: []*commander.Command{
makeCmdMirrorCreate(),
makeCmdMirrorList(),
//makeCmdMirrorShow(),
makeCmdMirrorShow(),
//makeCmdMirrorDelete(),
//makeCmdMirrorUpdate(),
makeCmdMirrorUpdate(),
},
Flag: flag.NewFlagSet("aptly-mirror", flag.ExitOnError),
}