mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Refactor ppa parsing: take pointer to config.
This commit is contained in:
@@ -24,7 +24,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||
|
||||
mirrorName = args[0]
|
||||
if len(args) == 2 {
|
||||
archiveURL, distribution, components, err = debian.ParsePPA(args[1])
|
||||
archiveURL, distribution, components, err = debian.ParsePPA(args[1], context.Config())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
6
debian/ppa.go
vendored
6
debian/ppa.go
vendored
@@ -11,14 +11,14 @@ import (
|
||||
var ppaRegexp = regexp.MustCompile("^ppa:([^/]+)/(.+)$")
|
||||
|
||||
// ParsePPA converts ppa URL like ppa:user/ppa-name to full HTTP url
|
||||
func ParsePPA(ppaURL string) (url string, distribution string, components []string, err error) {
|
||||
func ParsePPA(ppaURL string, config *utils.ConfigStructure) (url string, distribution string, components []string, err error) {
|
||||
matches := ppaRegexp.FindStringSubmatch(ppaURL)
|
||||
if matches == nil {
|
||||
err = fmt.Errorf("unable to parse ppa URL: %v", ppaURL)
|
||||
return
|
||||
}
|
||||
|
||||
distributorID := utils.Config.PpaDistributorID
|
||||
distributorID := config.PpaDistributorID
|
||||
if distributorID == "" {
|
||||
distributorID, err = getDistributorID()
|
||||
if err != nil {
|
||||
@@ -27,7 +27,7 @@ func ParsePPA(ppaURL string) (url string, distribution string, components []stri
|
||||
}
|
||||
}
|
||||
|
||||
codename := utils.Config.PpaCodename
|
||||
codename := config.PpaCodename
|
||||
if codename == "" {
|
||||
codename, err = getCodename()
|
||||
if err != nil {
|
||||
|
||||
18
debian/ppa_test.go
vendored
18
debian/ppa_test.go
vendored
@@ -6,27 +6,19 @@ import (
|
||||
)
|
||||
|
||||
type PpaSuite struct {
|
||||
savedConfig utils.ConfigStructure
|
||||
config utils.ConfigStructure
|
||||
}
|
||||
|
||||
var _ = Suite(&PpaSuite{})
|
||||
|
||||
func (s *PpaSuite) SetUpTest(c *C) {
|
||||
s.savedConfig = utils.Config
|
||||
}
|
||||
|
||||
func (s *PpaSuite) TearDownTest(c *C) {
|
||||
utils.Config = s.savedConfig
|
||||
}
|
||||
|
||||
func (s *PpaSuite) TestParsePPA(c *C) {
|
||||
_, _, _, err := ParsePPA("ppa:dedeed")
|
||||
_, _, _, err := ParsePPA("ppa:dedeed", &s.config)
|
||||
c.Check(err, ErrorMatches, "unable to parse ppa URL.*")
|
||||
|
||||
utils.Config.PpaDistributorID = "debian"
|
||||
utils.Config.PpaCodename = "wheezy"
|
||||
s.config.PpaDistributorID = "debian"
|
||||
s.config.PpaCodename = "wheezy"
|
||||
|
||||
url, distribution, components, err := ParsePPA("ppa:user/project")
|
||||
url, distribution, components, err := ParsePPA("ppa:user/project", &s.config)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(url, Equals, "http://ppa.launchpad.net/user/project/debian")
|
||||
c.Check(distribution, Equals, "wheezy")
|
||||
|
||||
Reference in New Issue
Block a user