Package pulp :: Package server :: Package api :: Module base
[hide private]
[frames] | no frames]

Source Code for Module pulp.server.api.base

 1  #!/usr/bin/python 
 2  # 
 3  # Copyright (c) 2010 Red Hat, Inc. 
 4  # 
 5  # This software is licensed to you under the GNU General Public License, 
 6  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 7  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 8  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 9  # along with this software; if not, see 
10  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
11  # 
12  # Red Hat trademarks are not licensed under GPLv2. No permission is 
13  # granted to use or replicate Red Hat trademarks that are incorporated 
14  # in this software or its documentation. 
15   
16  import logging 
17   
18  # logging and db connection 
19   
20  log = logging.getLogger(__name__) 
21 22 # base api class -------------------------------------------------------------- 23 24 -class BaseApi(object):
25
26 - def __init__(self):
27 self.objectdb = self._getcollection()
28 29 @property
30 - def _unique_indexes(self):
31 return ["id"]
32 33 @property
34 - def _indexes(self):
35 return []
36
37 - def clean(self):
38 """ 39 Delete all the Objects in the database. WARNING: Destructive 40 """ 41 self.objectdb.remove(safe=True)
42
43 - def insert(self, object, check_keys=False):
44 """ 45 Insert the object document to the database 46 """ 47 self.objectdb.insert(object, check_keys=check_keys, safe=True) 48 return object
49
50 - def update(self, object):
51 """ 52 Write the object document to the database 53 """ 54 self.objectdb.save(object, safe=True) 55 return object
56
57 - def delete(self, **kwargs):
58 """ 59 Delete a single stored Object 60 """ 61 self.objectdb.remove(kwargs, safe=True)
62
63 - def _getcollection(self):
64 raise NotImplementedError()
65