From 54421a9377f76233ea3d4015a9d641a3423992b4 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 20 Feb 2014 16:39:58 +0400 Subject: [PATCH] Command aptly repo show. --- cmd/cmd.go | 4 ++ cmd/repo.go | 1 + cmd/repo_show.go | 59 +++++++++++++++++++++++ system/t09_repo/CreateRepo1Test_repo_show | 3 ++ system/t09_repo/CreateRepo2Test_repo_show | 3 ++ system/t09_repo/ShowRepo1Test_gold | 3 ++ system/t09_repo/ShowRepo2Test_gold | 4 ++ system/t09_repo/ShowRepo3Test_gold | 1 + system/t09_repo/__init__.py | 1 + system/t09_repo/create.py | 4 +- system/t09_repo/show.py | 25 ++++++++++ 11 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 cmd/repo_show.go create mode 100644 system/t09_repo/CreateRepo1Test_repo_show create mode 100644 system/t09_repo/CreateRepo2Test_repo_show create mode 100644 system/t09_repo/ShowRepo1Test_gold create mode 100644 system/t09_repo/ShowRepo2Test_gold create mode 100644 system/t09_repo/ShowRepo3Test_gold create mode 100644 system/t09_repo/show.py diff --git a/cmd/cmd.go b/cmd/cmd.go index c0907cf5..9ddce99e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -13,6 +13,10 @@ import ( func ListPackagesRefList(reflist *debian.PackageRefList) (err error) { fmt.Printf("Packages:\n") + if reflist == nil { + return + } + packageCollection := debian.NewPackageCollection(context.database) err = reflist.ForEach(func(key []byte) error { diff --git a/cmd/repo.go b/cmd/repo.go index 168ac8b2..61611534 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -11,6 +11,7 @@ func makeCmdRepo() *commander.Command { Short: "manage local package repositories", Subcommands: []*commander.Command{ makeCmdRepoCreate(), + makeCmdRepoShow(), }, Flag: *flag.NewFlagSet("aptly-repo", flag.ExitOnError), } diff --git a/cmd/repo_show.go b/cmd/repo_show.go new file mode 100644 index 00000000..b6683015 --- /dev/null +++ b/cmd/repo_show.go @@ -0,0 +1,59 @@ +package cmd + +import ( + "fmt" + "github.com/gonuts/commander" + "github.com/gonuts/flag" + "github.com/smira/aptly/debian" +) + +func aptlyRepoShow(cmd *commander.Command, args []string) error { + var err error + if len(args) != 1 { + cmd.Usage() + return err + } + + name := args[0] + + localRepoCollection := debian.NewLocalRepoCollection(context.database) + repo, err := localRepoCollection.ByName(name) + if err != nil { + return fmt.Errorf("unable to show: %s", err) + } + + err = localRepoCollection.LoadComplete(repo) + if err != nil { + return fmt.Errorf("unable to show: %s", err) + } + + fmt.Printf("Name: %s\n", repo.Name) + fmt.Printf("Comment: %s\n", repo.Comment) + fmt.Printf("Number of packages: %d\n", repo.NumPackages()) + + withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool) + if withPackages { + ListPackagesRefList(repo.RefList()) + } + + return err +} + +func makeCmdRepoShow() *commander.Command { + cmd := &commander.Command{ + Run: aptlyRepoShow, + UsageLine: "show ", + Short: "show details about local repository", + Long: ` +Show shows full information about local package repository. + +ex: + $ aptly repo show testing +`, + Flag: *flag.NewFlagSet("aptly-repo-show", flag.ExitOnError), + } + + cmd.Flag.Bool("with-packages", false, "show list of packages") + + return cmd +} diff --git a/system/t09_repo/CreateRepo1Test_repo_show b/system/t09_repo/CreateRepo1Test_repo_show new file mode 100644 index 00000000..37a3ecec --- /dev/null +++ b/system/t09_repo/CreateRepo1Test_repo_show @@ -0,0 +1,3 @@ +Name: repo1 +Comment: +Number of packages: 0 diff --git a/system/t09_repo/CreateRepo2Test_repo_show b/system/t09_repo/CreateRepo2Test_repo_show new file mode 100644 index 00000000..968a0bee --- /dev/null +++ b/system/t09_repo/CreateRepo2Test_repo_show @@ -0,0 +1,3 @@ +Name: repo2 +Comment: Repository2 +Number of packages: 0 diff --git a/system/t09_repo/ShowRepo1Test_gold b/system/t09_repo/ShowRepo1Test_gold new file mode 100644 index 00000000..99344499 --- /dev/null +++ b/system/t09_repo/ShowRepo1Test_gold @@ -0,0 +1,3 @@ +Name: repo1 +Comment: Cool +Number of packages: 0 diff --git a/system/t09_repo/ShowRepo2Test_gold b/system/t09_repo/ShowRepo2Test_gold new file mode 100644 index 00000000..22763100 --- /dev/null +++ b/system/t09_repo/ShowRepo2Test_gold @@ -0,0 +1,4 @@ +Name: repo2 +Comment: Cool +Number of packages: 0 +Packages: diff --git a/system/t09_repo/ShowRepo3Test_gold b/system/t09_repo/ShowRepo3Test_gold new file mode 100644 index 00000000..28d2a94b --- /dev/null +++ b/system/t09_repo/ShowRepo3Test_gold @@ -0,0 +1 @@ +ERROR: unable to show: local repo with name repo3 not found diff --git a/system/t09_repo/__init__.py b/system/t09_repo/__init__.py index 0cd0f16e..6f39242e 100644 --- a/system/t09_repo/__init__.py +++ b/system/t09_repo/__init__.py @@ -3,3 +3,4 @@ Testing local repo management """ from .create import * +from .show import * diff --git a/system/t09_repo/create.py b/system/t09_repo/create.py index 91a4b9b7..e3ac7ba2 100644 --- a/system/t09_repo/create.py +++ b/system/t09_repo/create.py @@ -9,7 +9,7 @@ class CreateRepo1Test(BaseTest): def check(self): self.check_output() - #self.check_cmd_output("aptly mirror show mirror1", "mirror_show") + self.check_cmd_output("aptly repo show repo1", "repo_show") class CreateRepo2Test(BaseTest): @@ -20,7 +20,7 @@ class CreateRepo2Test(BaseTest): def check(self): self.check_output() - #self.check_cmd_output("aptly mirror show mirror1", "mirror_show") + self.check_cmd_output("aptly repo show repo2", "repo_show") class CreateRepo3Test(BaseTest): diff --git a/system/t09_repo/show.py b/system/t09_repo/show.py new file mode 100644 index 00000000..e28f1a86 --- /dev/null +++ b/system/t09_repo/show.py @@ -0,0 +1,25 @@ +from lib import BaseTest + + +class ShowRepo1Test(BaseTest): + """ + show local repo: regular + """ + fixtureCmds = ["aptly repo create -comment=Cool repo1"] + runCmd = "aptly repo show repo1" + + +class ShowRepo2Test(BaseTest): + """ + show local repo: -with-packages + """ + fixtureCmds = ["aptly repo create -comment=Cool repo2"] + runCmd = "aptly repo show -with-packages repo2" + + +class ShowRepo3Test(BaseTest): + """ + show local repo: not found + """ + expectedCode = 1 + runCmd = "aptly repo show repo3"