mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-05 22:08:27 +00:00
Listing of packages in snapshot.
This commit is contained in:
@@ -87,6 +87,14 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
||||
fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
|
||||
fmt.Printf("Description: %s\n", snapshot.Description)
|
||||
fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())
|
||||
fmt.Printf("Packages:\n")
|
||||
|
||||
packageCollection := debian.NewPackageCollection(context.database)
|
||||
|
||||
snapshot.RefList().ForEach(func(key []byte) {
|
||||
p, _ := packageCollection.ByKey(key)
|
||||
fmt.Printf(" %s\n", p)
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
9
debian/list.go
vendored
9
debian/list.go
vendored
@@ -103,3 +103,12 @@ func (l *PackageRefList) Decode(input []byte) error {
|
||||
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||
return decoder.Decode(l)
|
||||
}
|
||||
|
||||
// ForEach calls handler for each package ref in list
|
||||
//
|
||||
// TODO: Error handling
|
||||
func (l *PackageRefList) ForEach(handler func([]byte)) {
|
||||
for _, p := range l.Refs {
|
||||
handler(p)
|
||||
}
|
||||
}
|
||||
|
||||
16
debian/list_test.go
vendored
16
debian/list_test.go
vendored
@@ -90,3 +90,19 @@ func (s *PackageListSuite) TestPackageRefListEncodeDecode(c *C) {
|
||||
c.Check(reflist2.Len(), Equals, reflist.Len())
|
||||
c.Check(reflist2.Refs, DeepEquals, reflist.Refs)
|
||||
}
|
||||
|
||||
func (s *PackageListSuite) TestPackageRefListForeach(c *C) {
|
||||
s.list.Add(s.p1)
|
||||
s.list.Add(s.p3)
|
||||
s.list.Add(s.p5)
|
||||
s.list.Add(s.p6)
|
||||
|
||||
reflist := NewPackageRefListFromPackageList(s.list)
|
||||
|
||||
Len := 0
|
||||
reflist.ForEach(func([]byte) {
|
||||
Len++
|
||||
})
|
||||
|
||||
c.Check(Len, Equals, 4)
|
||||
}
|
||||
|
||||
5
debian/snapshot.go
vendored
5
debian/snapshot.go
vendored
@@ -56,6 +56,11 @@ func (s *Snapshot) NumPackages() int {
|
||||
return s.packageRefs.Len()
|
||||
}
|
||||
|
||||
// RefList returns list of package refs in snapshot
|
||||
func (s *Snapshot) RefList() *PackageRefList {
|
||||
return s.packageRefs
|
||||
}
|
||||
|
||||
// Key is a unique id in DB
|
||||
func (s *Snapshot) Key() []byte {
|
||||
return []byte("S" + s.UUID)
|
||||
|
||||
1
debian/snapshot_test.go
vendored
1
debian/snapshot_test.go
vendored
@@ -22,6 +22,7 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
|
||||
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
|
||||
c.Check(snapshot.Name, Equals, "snap1")
|
||||
c.Check(snapshot.NumPackages(), Equals, 3)
|
||||
c.Check(snapshot.RefList().Len(), Equals, 3)
|
||||
|
||||
s.repo.packageRefs = nil
|
||||
_, err := NewSnapshotFromRepository("snap2", s.repo)
|
||||
|
||||
Reference in New Issue
Block a user