source: cows_wps/trunk/cows_wps/controllers/dirlist.py @ 5985

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/controllers/dirlist.py@5985
Revision 5985, 1.3 KB checked in by astephen, 11 years ago (diff)

lots of new bits.

Line 
1import logging
2import os
3
4from pylons import request, response, session, tmpl_context as c
5from pylons.controllers.util import abort, redirect_to
6
7from cows_wps.renderer.ui_renderer import *
8from cows_wps.controllers import *
9from cows_wps.lib.ui.proc_config import *
10
11log = logging.getLogger(__name__)
12
13
14class DirlistController(BaseController):
15
16    def index(self, limit=20):
17        """
18        Takes in an argument and returns a JSON/text list of directories or matching paths.
19        """
20        path = request.params.get("path", None)
21        if path == None:
22            return "Please provide an argument path=<Something>"
23
24        dr = os.path.split(path)[0]
25        if not os.path.isdir(dr):
26            return "Please provide a valid directory."
27
28        items = [os.path.join(dr, x) for x in os.listdir(dr) if x[0] != "."]
29        items.sort()
30
31        if len(items) > limit:
32            items = items[:limit] + ["...more than I can be bothered to list..."]
33
34        if os.path.isdir(path):
35            return str([str(i) for i in items])
36
37        litems = [i.lower() for i in items]
38        lpath = path.lower()
39        resp = []
40
41        for (i, item) in enumerate(litems):
42            if item.find(lpath) == 0:
43                resp.append(items[i])
44
45        return str([str(i) for i in resp])
46
Note: See TracBrowser for help on using the repository browser.