diff --git a/Makefile b/Makefile index eafb06c6..ef61bc84 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ coverage.out: for i in database debian files http utils; do go test -coverprofile=coverage.$$i.out -covermode=count ./$$i; done echo "mode: count" > coverage.out grep -v -h "mode: count" coverage.*.out >> coverage.out + rm -f coverage.*.out coverage: coverage.out go tool cover -html=coverage.out diff --git a/cmd/cmd.go b/cmd/cmd.go index 1cef6e95..c0907cf5 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -37,13 +37,15 @@ func RootCommand() *commander.Command { Short: "Debian repository management tool", Long: ` aptly is a tool to create partial and full mirrors of remote -repositories, filter them, merge, upgrade individual packages, -take snapshots and publish them back as Debian repositories.`, +repositories, manage local repositories, filter them, merge, +upgrade individual packages, take snapshots and publish them +back as Debian repositories.`, Flag: *flag.NewFlagSet("aptly", flag.ExitOnError), Subcommands: []*commander.Command{ makeCmdDb(), makeCmdGraph(), makeCmdMirror(), + makeCmdRepo(), makeCmdServe(), makeCmdSnapshot(), makeCmdPublish(), diff --git a/cmd/repo.go b/cmd/repo.go new file mode 100644 index 00000000..168ac8b2 --- /dev/null +++ b/cmd/repo.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/gonuts/commander" + "github.com/gonuts/flag" +) + +func makeCmdRepo() *commander.Command { + return &commander.Command{ + UsageLine: "repo", + Short: "manage local package repositories", + Subcommands: []*commander.Command{ + makeCmdRepoCreate(), + }, + Flag: *flag.NewFlagSet("aptly-repo", flag.ExitOnError), + } +} diff --git a/cmd/repo_create.go b/cmd/repo_create.go new file mode 100644 index 00000000..74b38b70 --- /dev/null +++ b/cmd/repo_create.go @@ -0,0 +1,47 @@ +package cmd + +import ( + "fmt" + "github.com/gonuts/commander" + "github.com/gonuts/flag" + "github.com/smira/aptly/debian" +) + +func aptlyRepoCreate(cmd *commander.Command, args []string) error { + var err error + if len(args) != 1 { + cmd.Usage() + return err + } + + repo := debian.NewLocalRepo(args[0], cmd.Flag.Lookup("comment").Value.String()) + + localRepoCollection := debian.NewLocalRepoCollection(context.database) + + err = localRepoCollection.Add(repo) + if err != nil { + return fmt.Errorf("unable to add local repo: %s", err) + } + + fmt.Printf("\nLocal repo %s successfully added.\nYou can run 'aptly repo add %s ...' to add packages to repository.\n", repo, repo.Name) + return err +} + +func makeCmdRepoCreate() *commander.Command { + cmd := &commander.Command{ + Run: aptlyRepoCreate, + UsageLine: "create ", + Short: "create new local package repository", + Long: ` +Creates new empty local package repository. + +ex: + $ aptly repo create testing +`, + Flag: *flag.NewFlagSet("aptly-repo-create", flag.ExitOnError), + } + + cmd.Flag.String("comment", "", "comment for the repository") + + return cmd +} diff --git a/system/t02_config/ConfigInFileTest_gold b/system/t02_config/ConfigInFileTest_gold index 5cf142ae..e366b77e 100644 --- a/system/t02_config/ConfigInFileTest_gold +++ b/system/t02_config/ConfigInFileTest_gold @@ -6,6 +6,7 @@ Commands: graph display graph of dependencies between aptly objects (requires graphviz) mirror manage mirrors of remote repositories publish manage published repositories + repo manage local package repositories serve start embedded HTTP server to serve published repositories snapshot manage snapshots of repositories version display version diff --git a/system/t03_help/MainHelpTest_gold b/system/t03_help/MainHelpTest_gold index d896908b..12772441 100644 --- a/system/t03_help/MainHelpTest_gold +++ b/system/t03_help/MainHelpTest_gold @@ -1,6 +1,7 @@ aptly is a tool to create partial and full mirrors of remote -repositories, filter them, merge, upgrade individual packages, -take snapshots and publish them back as Debian repositories. +repositories, manage local repositories, filter them, merge, +upgrade individual packages, take snapshots and publish them +back as Debian repositories. Options: -architectures="": list of architectures to consider during (comma-separated), default to all available diff --git a/system/t03_help/MainTest_gold b/system/t03_help/MainTest_gold index 5cf142ae..e366b77e 100644 --- a/system/t03_help/MainTest_gold +++ b/system/t03_help/MainTest_gold @@ -6,6 +6,7 @@ Commands: graph display graph of dependencies between aptly objects (requires graphviz) mirror manage mirrors of remote repositories publish manage published repositories + repo manage local package repositories serve start embedded HTTP server to serve published repositories snapshot manage snapshots of repositories version display version diff --git a/system/t09_repo/CreateRepo1Test_gold b/system/t09_repo/CreateRepo1Test_gold new file mode 100644 index 00000000..941ce9ec --- /dev/null +++ b/system/t09_repo/CreateRepo1Test_gold @@ -0,0 +1,3 @@ + +Local repo [repo1] successfully added. +You can run 'aptly repo add repo1 ...' to add packages to repository. diff --git a/system/t09_repo/CreateRepo2Test_gold b/system/t09_repo/CreateRepo2Test_gold new file mode 100644 index 00000000..b5933ca7 --- /dev/null +++ b/system/t09_repo/CreateRepo2Test_gold @@ -0,0 +1,3 @@ + +Local repo [repo2]: Repository2 successfully added. +You can run 'aptly repo add repo2 ...' to add packages to repository. diff --git a/system/t09_repo/CreateRepo3Test_gold b/system/t09_repo/CreateRepo3Test_gold new file mode 100644 index 00000000..3ad700be --- /dev/null +++ b/system/t09_repo/CreateRepo3Test_gold @@ -0,0 +1 @@ +ERROR: unable to add local repo: local repo with name repo3 already exists diff --git a/system/t09_repo/__init__.py b/system/t09_repo/__init__.py new file mode 100644 index 00000000..0cd0f16e --- /dev/null +++ b/system/t09_repo/__init__.py @@ -0,0 +1,5 @@ +""" +Testing local repo management +""" + +from .create import * diff --git a/system/t09_repo/create.py b/system/t09_repo/create.py new file mode 100644 index 00000000..91a4b9b7 --- /dev/null +++ b/system/t09_repo/create.py @@ -0,0 +1,32 @@ +from lib import BaseTest + + +class CreateRepo1Test(BaseTest): + """ + create local repo: regular repo + """ + runCmd = "aptly repo create repo1" + + def check(self): + self.check_output() + #self.check_cmd_output("aptly mirror show mirror1", "mirror_show") + + +class CreateRepo2Test(BaseTest): + """ + create local repo: regular repo with comment + """ + runCmd = "aptly repo create -comment=Repository2 repo2" + + def check(self): + self.check_output() + #self.check_cmd_output("aptly mirror show mirror1", "mirror_show") + + +class CreateRepo3Test(BaseTest): + """ + create local repo: duplicate name + """ + fixtureCmds = ["aptly repo create repo3"] + runCmd = "aptly repo create -comment=Repository3 repo3" + expectedCode = 1