~ubuntu-branches/ubuntu/hardy/apturl/hardy-updates

« back to all changes in this revision

Viewing changes to AptUrl/Parser.py

  • Committer: Bazaar Package Importer
  • Author(s): Sasa Bodiroza
  • Date: 2007-10-27 13:42:45 UTC
  • Revision ID: james.westby@ubuntu.com-20071027134245-3a8ara1wyuqjjz4d
Tags: 0.1.1ubuntu1
* AptUrl/Parser.py:
  - Implemented multipackage installation (LP: #154593)
* tests/apturlparse.py:
  - add test for the new multipackage feature

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
def parse(full_url):
39
39
    " parse a apt url and return a list of AptUrl objects "
 
40
    # apt:pkg1?k11=v11?k12=v12,pkg2?k21=v21?k22=v22,...
40
41
    res = []
41
42
 
42
43
    for url in full_url.split(";"):
43
44
        if not ":" in url:
44
45
            raise InvalidUrlException
45
 
        apt_url = AptUrl()
46
46
 
47
47
        # now parse it
48
 
        (schema, rem) = url.split(":", 1)
49
 
        apt_url.schema = schema
50
 
        # check for schemas of the form: apt+http://
51
 
        if schema.startswith("apt+"):
52
 
            apt_url.repo_url = schema[len("apt+"):] + ":" + rem.split("?",1)[0]
53
 
        else:
54
 
            if "?" in rem:
55
 
                rem = rem.split("?")[0]
56
 
            apt_url.package = rem.lstrip("/")
57
 
 
58
 
        # now parse the ?... bits
59
 
        if "?" in url:
60
 
            key_value_pairs = url.split("?")
61
 
            if len(key_value_pairs) > 1:
62
 
                # first one is invalid
63
 
                del key_value_pairs[0]
64
 
                for s in key_value_pairs:
65
 
                    (k,v) = s.split("=")
66
 
                    # for list defaults, add to list
67
 
                    try:
68
 
                        if type(getattr(apt_url, k)) == type([]):
69
 
                            getattr(apt_url, k).append(v)
70
 
                        else:
71
 
                            setattr(apt_url, k, v)
72
 
                    except Exception, e:
73
 
                        raise InvalidUrlException
74
 
        res.append(apt_url)
 
48
 
 
49
        (schema, packages) = url.split(":", 1)
 
50
        packages = packages.split(",")
 
51
 
 
52
        for package in packages:
 
53
            apt_url = AptUrl()
 
54
            apt_url.schema = schema
 
55
            # check for schemas of the form: apt+http://
 
56
            if schema.startswith("apt+"):
 
57
                apt_url.repo_url = schema[len("apt+"):] + ":" + package.split("?",1)[0]
 
58
            else:
 
59
                if "?" in package:
 
60
                    apt_url.package = package.split("?")[0].lstrip("/")
 
61
                else:
 
62
                    apt_url.package = package.lstrip("/")
 
63
 
 
64
            # now parse the ?... bits
 
65
            if "?" in package:
 
66
                key_value_pairs = package.split("?")
 
67
                if len(key_value_pairs) > 1:
 
68
                    # first one is invalid
 
69
                    del key_value_pairs[0]
 
70
                    for s in key_value_pairs:
 
71
                        (k,v) = s.split("=")
 
72
                        # for list defaults, add to list
 
73
                        try:
 
74
                            if type(getattr(apt_url, k)) == type([]):
 
75
                                getattr(apt_url, k).append(v)
 
76
                            else:
 
77
                                setattr(apt_url, k, v)
 
78
                        except Exception, e:
 
79
                            raise InvalidUrlException
 
80
            res.append(apt_url)
75
81
    return res