Merge pull request #497 from smira/repo-create-from-snap

Implement new command `aptly repo create ... from snapshot ...`
This commit is contained in:
Andrey Smirnov
2017-03-16 01:12:09 +03:00
committed by GitHub
6 changed files with 68 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/smira/aptly/deb"
"github.com/smira/commander"
"github.com/smira/flag"
@@ -9,7 +10,7 @@ import (
func aptlyRepoCreate(cmd *commander.Command, args []string) error {
var err error
if len(args) != 1 {
if !(len(args) == 1 || (len(args) == 4 && args[1] == "from" && args[2] == "snapshot")) {
cmd.Usage()
return commander.ErrCommandError
}
@@ -26,6 +27,22 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error {
}
}
if len(args) == 4 {
var snapshot *deb.Snapshot
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(args[3])
if err != nil {
return fmt.Errorf("unable to load source snapshot: %s", err)
}
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
if err != nil {
return fmt.Errorf("unable to load source snapshot: %s", err)
}
repo.UpdateRefList(snapshot.RefList())
}
err = context.CollectionFactory().LocalRepoCollection().Add(repo)
if err != nil {
return fmt.Errorf("unable to add local repo: %s", err)
@@ -38,16 +55,21 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error {
func makeCmdRepoCreate() *commander.Command {
cmd := &commander.Command{
Run: aptlyRepoCreate,
UsageLine: "create <name>",
UsageLine: "create <name> [ from snapshot <snapshot> ]",
Short: "create local repository",
Long: `
Create local package repository. Repository would be empty when
created, packages could be added from files, copied or moved from
another local repository or imported from the mirror.
If local package repository is created from snapshot, repo initial
contents are copied from snapsot contents.
Example:
$ aptly repo create testing
$ aptly repo create mysql35 from snapshot mysql-35-2017
`,
Flag: *flag.NewFlagSet("aptly-repo-create", flag.ExitOnError),
}

View File

@@ -633,18 +633,24 @@ don\(cqt copy, just show what would be copied
follow dependencies when processing package\-spec
.
.SH "CREATE LOCAL REPOSITORY"
\fBaptly\fR \fBrepo\fR \fBcreate\fR \fIname\fR
\fBaptly\fR \fBrepo\fR \fBcreate\fR \fIname\fR [ \fBfrom\fR \fBsnapshot\fR \fIsnapshot\fR ]
.
.P
Create local package repository\. Repository would be empty when created, packages could be added from files, copied or moved from another local repository or imported from the mirror\.
.
.P
If local package repository is created from snapshot, repo initial contents are copied from snapsot contents\.
.
.P
Example:
.
.P
$ aptly repo create testing
.
.P
$ aptly repo create mysql35 from snapshot mysql\-35\-2017
.
.P
Options:
.
.TP

View File

@@ -0,0 +1,3 @@
Local repo [repo2] successfully added.
You can run 'aptly repo add repo2 ...' to add packages to repository.

View File

@@ -0,0 +1,9 @@
Name: repo2
Comment:
Default Distribution:
Default Component: main
Number of packages: 3
Packages:
libboost-program-options-dev_1.49.0.1_i386
pyspi_0.6.1-1.3_source
pyspi_0.6.1-1.4_source

View File

@@ -0,0 +1 @@
ERROR: unable to load source snapshot: snapshot with name snap-missing not found

View File

@@ -63,3 +63,27 @@ class CreateRepo6Test(BaseTest):
runCmd = "aptly repo create -uploaders-file=${changes}/uploaders-not-found.json repo6"
expectedCode = 1
outputMatchPrepare = changesRemove
class CreateRepo7Test(BaseTest):
"""
create local repo: from snapshot
"""
fixtureCmds = [
"aptly repo create repo1",
"aptly repo add repo1 ${files}",
"aptly snapshot create snap1 from repo repo1",
]
runCmd = "aptly repo create repo2 from snapshot snap1"
def check(self):
self.check_output()
self.check_cmd_output("aptly repo show -with-packages repo2", "repo_show")
class CreateRepo8Test(BaseTest):
"""
create local repo: from missing snapshot
"""
runCmd = "aptly repo create repo2 from snapshot snap-missing"
expectedCode = 1