From 275db14b9ff52f358ce9c2eb79056aa38466c630 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 8 Jan 2014 17:40:04 +0400 Subject: [PATCH] Package.getDependencies method. --- debian/package.go | 17 +++++++++++++++++ debian/package_test.go | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/debian/package.go b/debian/package.go index 0f43909e..139f0a24 100644 --- a/debian/package.go +++ b/debian/package.go @@ -148,6 +148,23 @@ func (p *Package) MatchesArchitecture(arch string) bool { return p.Architecture == arch } +// GetDependencies compiles list of dependenices by flags from options +func (p *Package) GetDependencies(options int) (dependencies []string) { + dependencies = make([]string, 0, 30) + dependencies = append(dependencies, p.Depends...) + dependencies = append(dependencies, p.PreDepends...) + + if options&DepFollowRecommends == DepFollowRecommends { + dependencies = append(dependencies, p.Recommends...) + } + + if options&DepFollowSuggests == DepFollowSuggests { + dependencies = append(dependencies, p.Suggests...) + } + + return +} + // Stanza creates original stanza from package func (p *Package) Stanza() (result Stanza) { result = p.Extra.Copy() diff --git a/debian/package_test.go b/debian/package_test.go index b73f3696..bec3f5ce 100644 --- a/debian/package_test.go +++ b/debian/package_test.go @@ -7,7 +7,7 @@ import ( "path/filepath" ) -var packageStanza = Stanza{"Source": "alien-arena", "Depends": "libc6 (>= 2.7), alien-arena-data (>= 7.40)", "Filename": "pool/contrib/a/alien-arena/alien-arena-common_7.40-2_i386.deb", "SHA1": "46955e48cad27410a83740a21d766ce362364024", "SHA256": "eb4afb9885cba6dc70cccd05b910b2dbccc02c5900578be5e99f0d3dbf9d76a5", "Priority": "extra", "Maintainer": "Debian Games Team ", "Description": "Common files for Alien Arena client and server ALIEN ARENA is a standalone 3D first person online deathmatch shooter\n crafted from the original source code of Quake II and Quake III, released\n by id Software under the GPL license. With features including 32 bit\n graphics, new particle engine and effects, light blooms, reflective water,\n hi resolution textures and skins, hi poly models, stain maps, ALIEN ARENA\n pushes the envelope of graphical beauty rivaling today's top games.\n .\n This package installs the common files for Alien Arena.\n", "Homepage": "http://red.planetarena.org", "Tag": "role::app-data, role::shared-lib, special::auto-inst-parts", "Installed-Size": "456", "Version": "7.40-2", "Replaces": "alien-arena (<< 7.33-1)", "Size": "187518", "MD5sum": "1e8cba92c41420aa7baa8a5718d67122", "Package": "alien-arena-common", "Section": "contrib/games", "Architecture": "i386"} +var packageStanza = Stanza{"Source": "alien-arena", "Pre-Depends": "dpkg (>= 1.6)", "Suggests": "alien-arena-mars", "Recommends": "aliean-arena-luna", "Depends": "libc6 (>= 2.7), alien-arena-data (>= 7.40)", "Filename": "pool/contrib/a/alien-arena/alien-arena-common_7.40-2_i386.deb", "SHA1": "46955e48cad27410a83740a21d766ce362364024", "SHA256": "eb4afb9885cba6dc70cccd05b910b2dbccc02c5900578be5e99f0d3dbf9d76a5", "Priority": "extra", "Maintainer": "Debian Games Team ", "Description": "Common files for Alien Arena client and server ALIEN ARENA is a standalone 3D first person online deathmatch shooter\n crafted from the original source code of Quake II and Quake III, released\n by id Software under the GPL license. With features including 32 bit\n graphics, new particle engine and effects, light blooms, reflective water,\n hi resolution textures and skins, hi poly models, stain maps, ALIEN ARENA\n pushes the envelope of graphical beauty rivaling today's top games.\n .\n This package installs the common files for Alien Arena.\n", "Homepage": "http://red.planetarena.org", "Tag": "role::app-data, role::shared-lib, special::auto-inst-parts", "Installed-Size": "456", "Version": "7.40-2", "Replaces": "alien-arena (<< 7.33-1)", "Size": "187518", "MD5sum": "1e8cba92c41420aa7baa8a5718d67122", "Package": "alien-arena-common", "Section": "contrib/games", "Architecture": "i386"} type PackageSuite struct { stanza Stanza @@ -125,6 +125,13 @@ func (s *PackageSuite) TestMatchesArchitecture(c *C) { c.Check(p.MatchesArchitecture("amd64"), Equals, true) } +func (s *PackageSuite) TestGetDependencies(c *C) { + p := NewPackageFromControlFile(s.stanza) + c.Check(p.GetDependencies(0), DeepEquals, []string{"libc6 (>= 2.7)", "alien-arena-data (>= 7.40)", "dpkg (>= 1.6)"}) + c.Check(p.GetDependencies(DepFollowSuggests), DeepEquals, []string{"libc6 (>= 2.7)", "alien-arena-data (>= 7.40)", "dpkg (>= 1.6)", "alien-arena-mars"}) + c.Check(p.GetDependencies(DepFollowSuggests|DepFollowRecommends), DeepEquals, []string{"libc6 (>= 2.7)", "alien-arena-data (>= 7.40)", "dpkg (>= 1.6)", "aliean-arena-luna", "alien-arena-mars"}) +} + func (s *PackageSuite) TestPoolDirectory(c *C) { p := NewPackageFromControlFile(s.stanza) dir, err := p.PoolDirectory()