Package pulp :: Package server :: Package db :: Module model
[hide private]
[frames] | no frames]

Source Code for Module pulp.server.db.model

  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 datetime 
 17  import uuid 
 18   
 19  from pulp.server.pexceptions import PulpException 
 20   
21 -class Base(dict):
22 ''' 23 Base object that has convenience methods to get and put 24 attrs into the base dict object with dot notation 25 ''' 26
27 - def __init__(self):
28 self._id = str(uuid.uuid4()) 29 self.id = self._id
30
31 - def __getattr__(self, attr):
32 return self.get(attr, None)
33 __setattr__= dict.__setitem__ 34 __delattr__= dict.__delitem__
35
36 -class Repo(Base):
37 - def __init__(self, id, name, arch, source=None):
38 self._id = id 39 self.id = id 40 if source: 41 self.source = RepoSource(source) 42 else: 43 self.source = None 44 self.name = name 45 self.arch = arch 46 self.packages = dict() 47 self.packagegroups = dict() 48 self.packagegroupcategories = dict() 49 self.repomd_xml_path = "" 50 self.group_xml_path = "" 51 self.group_gz_xml_path = "" 52 self.sync_schedule = None 53 self.use_symlinks = None 54 self.ca = None 55 self.cert = None 56 self.key = None 57 self.errata = {} 58 self.productid = [] 59 self.relative_path = None
60
61 - def get_repo_source(self):
62 if not self.source: 63 return None 64 return RepoSource(self.source)
65 66
67 -class RepoSource(Base):
68 # yum:http://blah.bloop.com 69
70 - def __init__(self, url):
71 self.supported_types = ['yum', 'local', 'rhn'] 72 self.type = None 73 self.url = None 74 self.parse_feed(url)
75
76 - def parse_feed(self, source):
77 parts = source.split(':') 78 if (len(parts) < 2): 79 msg = "Invalid feed url. Must be <type>:<path> where types are: %s" 80 raise PulpException(msg % self.supported_types) 81 if (self.supported_types.count(parts[0]) < 1): 82 raise PulpException("Invalid type. valid types are %s" 83 % self.supported_types) 84 self.type = parts[0] 85 self.url = source.replace((self.type + ":"), "")
86
87 -class Package(Base):
88 - def __init__(self, name, epoch, version, release, arch, description, 89 checksum_type, checksum, filename, vendor=None):
90 Base.__init__(self) 91 # ID is initialized in Base.__init__() 92 self.name = name 93 self.epoch = epoch 94 self.version = version 95 self.release = release 96 self.arch = arch 97 self.description = description 98 self.vendor = vendor 99 self.filename = filename 100 self.checksum = {checksum_type: checksum} 101 self.download_url = None 102 # Add gpg keys 103 self.requires = [] 104 self.provides = []
105
106 -class PackageGroup(Base):
107 """ 108 Class represents a yum.comps.Group 109 """
110 - def __init__(self, id, name, description, user_visible=True, 111 display_order=1024, default=True, langonly=None, 112 immutable=False, repo_defined=False):
113 self._id = id 114 self.id = id 115 self.name = name 116 self.description = description 117 self.user_visible = user_visible 118 self.display_order = display_order 119 self.default = default 120 self.langonly = langonly 121 self.mandatory_package_names = [] 122 self.optional_package_names = [] 123 self.default_package_names = [] 124 self.conditional_package_names = {} 125 self.translated_name = {} 126 self.translated_description = {} 127 self.immutable = immutable 128 self.repo_defined = repo_defined
129
130 -class PackageGroupCategory(Base):
131
132 - def __init__(self, id, name, description, display_order=99, 133 immutable=False, repo_defined=False):
134 self._id = id 135 self.id = id 136 self.name = name 137 self.description = description 138 self.display_order = display_order 139 self.translated_name = {} 140 self.translated_description = {} 141 self.packagegroupids = [] 142 self.immutable = immutable 143 self.repo_defined = repo_defined
144
145 -class Consumer(Base):
146 - def __init__(self, id, description):
147 self._id = id 148 self.id = id 149 self.description = description 150 self.package_profile = [] 151 self.repoids = []
152
153 -class ConsumerGroup(Base):
154 - def __init__(self, id, description, consumerids = []):
155 self._id = id 156 self.id = id 157 self.description = description 158 self.consumerids = consumerids
159
160 -class ConsumerHistoryEvent(Base):
161 - def __init__(self, consumer_id, originator, type_name, details):
162 Base.__init__(self) 163 self.consumer_id = consumer_id 164 self.originator = originator 165 self.type_name = type_name 166 self.details = details 167 self.timestamp = datetime.datetime.now()
168
169 -class User(Base):
170 - def __init__(self, login, id, password, name):
171 self._id = id 172 self.id = id 173 self.login = login 174 self.password = password 175 self.name = name
176
177 - def __unicode__(self):
178 return unicode(self.name)
179
180 -class Event(Base):
181 """ 182 Auditing models used to log and persist events in the database 183 """
184 - def __init__(self, principal, action, api=None, method=None, params=[]):
185 super(Event, self).__init__() 186 self.timestamp = datetime.datetime.now() 187 self.principal_type = unicode(type(principal)) 188 self.principal = unicode(principal) 189 self.action = action 190 self.api = api 191 self.method = method 192 self.params = params 193 self.result = None 194 self.exception = None 195 self.traceback = None
196
197 -class Errata(Base):
198 """ 199 Errata model to represent software updates 200 maps to yum.update_md.UpdateNotice fields 201 """
202 - def __init__(self, id, title, description, version, release, type, status="", 203 updated="", issued="", pushcount="", from_str="", 204 reboot_suggested="", references=[], pkglist=[], repo_defined=False, 205 immutable=False):
206 self._id = id 207 self.id = id 208 self.title = title 209 self.description = description 210 self.version = version 211 self.release = release 212 self.type = type 213 self.status = status 214 self.updated = updated 215 self.issued = issued 216 self.pushcount = pushcount 217 self.from_str = from_str 218 self.reboot_suggested = reboot_suggested 219 self.references = references 220 self.pkglist = pkglist 221 self.repo_defined = repo_defined 222 self.immutable = immutable
223