source: TI03-DataExtractor/branches/old_stuff/dx-webservice/request.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx-webservice/request.py@793
Revision 793, 1.8 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
Line 
1"""
2request.py
3===========
4
5Request module for the data extractor package.
6
7This module holds the Requestdb class that is used
8to store the contents of user requests.
9
10"""
11
12# Import required modules
13
14import os
15import shelve
16
17# import package modules including global variables
18
19from config import *
20
21class Requestdb:
22    """
23    Requestdb method - An instance of this holds a user request that
24    is stored in a python shelve object.
25    """
26
27    def __init__(self, request_id=None):
28        """
29        __init__ method - generates a unique id for a request if the
30        requests object does not already exist.
31        """
32        if request_id==None:
33            pid=os.getpid()
34            request_id="request_%s" % pid
35        self.id=request_id
36        self.dict={"request_id":request_id}
37   
38    def getRequestID(self):
39        """
40        getRequestID method - returns the request ID.
41        """
42        return self.id
43       
44    def getNumDatasets(self):
45        """
46        getNumDatasets method - returns the current number of datasets
47        selected.
48        """
49        return self.num_datasets
50
51    def readRequest(self):
52        """
53        readRequest method - reads the current request from the python
54        shelve object.
55        """
56        dict_obj={}
57        shelve_obj=shelve.open(os.path.join(REQUEST_DIR, self.id))
58        for key in shelve_obj.keys():
59             dict_obj[key]=shelve_obj[key]
60        shelve_obj.close()
61        return dict_obj
62
63    def writeRequest(self, request):
64        """
65        writeRequest method - writes the current request to a python
66        shelve object.
67        """
68        shelve_obj=shelve.open(os.path.join(REQUEST_DIR, self.id))
69        for key in request.keys():
70            shelve_obj[key]=request[key]
71        return
72
73    def loadRequest(self):
74        """
75        loadRequest method - [not yet implemented]
76        """
77        pass
78
79    def saveRequest(self):
80        """
81        saveRequest method - [not yet implemented]
82        """
83        pass
84
85
Note: See TracBrowser for help on using the repository browser.