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

Source Code for Module pulp.server.updateinfo

 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   
17  import sys 
18  import logging 
19   
20  from yum.update_md import UpdateMetadata 
21   
22  from pulp.server.db.model import Errata 
23   
24  log = logging.getLogger(__name__) 
25   
26   
27 -def get_update_notices(path_to_updateinfo):
28 """ 29 path_to_updateinfo: path to updateinfo.xml 30 31 Returns a list of dictionaries 32 Dictionary is based on keys from yum.update_md.UpdateNotice 33 """ 34 um = UpdateMetadata() 35 um.add(path_to_updateinfo) 36 notices = [] 37 for info in um.get_notices(): 38 notices.append(info.get_metadata()) 39 return notices
40
41 -def get_errata(path_to_updateinfo):
42 """ 43 @param path_to_updateinfo: path to updateinfo metadata xml file 44 45 Returns a list of pulp.model.Errata objects 46 Parses updateinfo xml file and converts yum.update_md.UpdateNotice 47 objects to pulp.model.Errata objects 48 """ 49 errata = [] 50 uinfos = get_update_notices(path_to_updateinfo) 51 for u in uinfos: 52 e = _translate_updatenotice_to_erratum(u) 53 errata.append(e) 54 return errata
55
56 -def _translate_updatenotice_to_erratum(unotice):
57 id = unotice['update_id'] 58 title = unotice['title'] 59 description = unotice['description'] 60 version = unotice['version'] 61 release = unotice['release'] 62 type = unotice['type'] 63 status = unotice['status'] 64 updated = unotice['updated'] 65 issued = unotice['issued'] 66 pushcount = unotice['pushcount'] 67 from_str = unotice['from'] 68 reboot_suggested = unotice['reboot_suggested'] 69 references = unotice['references'] 70 pkglist = unotice['pkglist'] 71 erratum = Errata(id, title, description, version, release, type, 72 status, updated, issued, pushcount, from_str, reboot_suggested, 73 references, pkglist) 74 return erratum
75 76 if __name__ == "__main__": 77 if len(sys.argv) < 2: 78 print "Usage: %s <PATH_TO/updateinfo.xml>" 79 sys.exit(1) 80 updateinfo_path = sys.argv[1] 81 notices = get_update_notices(updateinfo_path) 82 if len(notices) < 1: 83 print "Error parsing %s" % (updateinfo_path) 84 print "Ensure you are specifying the path to updateinfo.xml" 85 sys.exit(1) 86 print "UpdateInfo has been parsed for %s notices." % (len(notices)) 87 example = notices[0] 88 for key in example.keys(): 89 print "%s: %s" % (key, example[key]) 90 print "Available keys are: %s" % (example.keys()) 91