~ubuntuone-pqm-team/convoy/trunk

« back to all changes in this revision

Viewing changes to convoy/combo.py

  • Committer: Rick Harding
  • Date: 2012-01-27 01:46:44 UTC
  • mfrom: (16.1.4 convoy_directories)
  • Revision ID: rick.harding@canonical.com-20120127014644-mmmcel9qgiryh1ev
Add support for routing a path as part of the combo url

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
CHUNK_SIZE = 2 << 12
10
10
URL_RE = re.compile("url\([ \"\']*([^ \"\']+)[ \"\']*\)")
 
11
URL_PARSE = re.compile("/([^/]*).*?$")
11
12
 
12
13
 
13
14
def relative_path(from_file, to_file):
29
30
    return parse_qs(query)
30
31
 
31
32
 
 
33
def parse_path_hint(url):
 
34
    """Parse the url for the path hint to find files on disk"""
 
35
    scheme, loc, path, query, frag = urlparse.urlsplit(url)
 
36
    combo_end = URL_PARSE.match(path)
 
37
    path_hint = path.replace(combo_end.group(1), "").strip('/')
 
38
    return path_hint
 
39
 
 
40
 
32
41
def parse_qs(query):
33
42
    """Parse a query string.
34
43
 
99
108
    """
100
109
    root = os.path.abspath(root)
101
110
    def app(environ, start_response, root=root):
 
111
        path_hint = parse_path_hint(environ['PATH_INFO'])
102
112
        fnames = parse_qs(environ["QUERY_STRING"])
103
113
        content_type = "text/plain"
104
114
        if fnames:
110
120
            start_response("404 Not Found", [("Content-Type", content_type)])
111
121
            return ("Not Found",)
112
122
        start_response("200 OK", [("Content-Type", content_type)])
113
 
        return combine_files(fnames, root, resource_prefix,
 
123
 
 
124
        # take any prefix in the url route into consideration for the root to
 
125
        # find files at
 
126
        updated_root = os.path.join(root, path_hint)
 
127
        return combine_files(fnames, updated_root, resource_prefix,
114
128
                             rewrite_urls=rewrite_urls)
115
129
    return app