Package portage :: Package emaint :: Package modules :: Package binhost :: Module binhost
[hide private]

Source Code for Module portage.emaint.modules.binhost.binhost

  1  # Copyright 2005-2014 Gentoo Foundation 
  2  # Distributed under the terms of the GNU General Public License v2 
  3   
  4  import errno 
  5  import stat 
  6   
  7  import portage 
  8  from portage import os 
  9  from portage.util import writemsg 
 10   
 11  import sys 
 12   
 13  if sys.hexversion >= 0x3000000: 
 14          # pylint: disable=W0622 
 15          long = int 
 16   
17 -class BinhostHandler(object):
18 19 short_desc = "Generate a metadata index for binary packages" 20
21 - def name():
22 return "binhost"
23 name = staticmethod(name) 24
25 - def __init__(self):
26 eroot = portage.settings['EROOT'] 27 self._bintree = portage.db[eroot]["bintree"] 28 self._bintree.populate() 29 self._pkgindex_file = self._bintree._pkgindex_file 30 self._pkgindex = self._bintree._load_pkgindex()
31
32 - def _need_update(self, cpv, data):
33 34 if "MD5" not in data: 35 return True 36 37 size = data.get("SIZE") 38 if size is None: 39 return True 40 41 mtime = data.get("MTIME") 42 if mtime is None: 43 return True 44 45 pkg_path = self._bintree.getname(cpv) 46 try: 47 s = os.lstat(pkg_path) 48 except OSError as e: 49 if e.errno not in (errno.ENOENT, errno.ESTALE): 50 raise 51 # We can't update the index for this one because 52 # it disappeared. 53 return False 54 55 try: 56 if long(mtime) != s[stat.ST_MTIME]: 57 return True 58 if long(size) != long(s.st_size): 59 return True 60 except ValueError: 61 return True 62 63 return False
64
65 - def check(self, **kwargs):
66 onProgress = kwargs.get('onProgress', None) 67 missing = [] 68 cpv_all = self._bintree.dbapi.cpv_all() 69 cpv_all.sort() 70 maxval = len(cpv_all) 71 if onProgress: 72 onProgress(maxval, 0) 73 pkgindex = self._pkgindex 74 missing = [] 75 metadata = {} 76 for d in pkgindex.packages: 77 metadata[d["CPV"]] = d 78 for i, cpv in enumerate(cpv_all): 79 d = metadata.get(cpv) 80 if not d or self._need_update(cpv, d): 81 missing.append(cpv) 82 if onProgress: 83 onProgress(maxval, i+1) 84 errors = ["'%s' is not in Packages" % cpv for cpv in missing] 85 stale = set(metadata).difference(cpv_all) 86 for cpv in stale: 87 errors.append("'%s' is not in the repository" % cpv) 88 return errors
89
90 - def fix(self, **kwargs):
91 onProgress = kwargs.get('onProgress', None) 92 bintree = self._bintree 93 cpv_all = self._bintree.dbapi.cpv_all() 94 cpv_all.sort() 95 missing = [] 96 maxval = 0 97 if onProgress: 98 onProgress(maxval, 0) 99 pkgindex = self._pkgindex 100 missing = [] 101 metadata = {} 102 for d in pkgindex.packages: 103 metadata[d["CPV"]] = d 104 105 for i, cpv in enumerate(cpv_all): 106 d = metadata.get(cpv) 107 if not d or self._need_update(cpv, d): 108 missing.append(cpv) 109 110 stale = set(metadata).difference(cpv_all) 111 if missing or stale: 112 from portage import locks 113 pkgindex_lock = locks.lockfile( 114 self._pkgindex_file, wantnewlockfile=1) 115 try: 116 # Repopulate with lock held. 117 bintree._populate() 118 cpv_all = self._bintree.dbapi.cpv_all() 119 cpv_all.sort() 120 121 pkgindex = bintree._load_pkgindex() 122 self._pkgindex = pkgindex 123 124 metadata = {} 125 for d in pkgindex.packages: 126 metadata[d["CPV"]] = d 127 128 # Recount missing packages, with lock held. 129 del missing[:] 130 for i, cpv in enumerate(cpv_all): 131 d = metadata.get(cpv) 132 if not d or self._need_update(cpv, d): 133 missing.append(cpv) 134 135 maxval = len(missing) 136 for i, cpv in enumerate(missing): 137 try: 138 metadata[cpv] = bintree._pkgindex_entry(cpv) 139 except portage.exception.InvalidDependString: 140 writemsg("!!! Invalid binary package: '%s'\n" % \ 141 bintree.getname(cpv), noiselevel=-1) 142 143 if onProgress: 144 onProgress(maxval, i+1) 145 146 for cpv in set(metadata).difference( 147 self._bintree.dbapi.cpv_all()): 148 del metadata[cpv] 149 150 # We've updated the pkgindex, so set it to 151 # repopulate when necessary. 152 bintree.populated = False 153 154 del pkgindex.packages[:] 155 pkgindex.packages.extend(metadata.values()) 156 bintree._pkgindex_write(self._pkgindex) 157 158 finally: 159 locks.unlockfile(pkgindex_lock) 160 161 if onProgress: 162 if maxval == 0: 163 maxval = 1 164 onProgress(maxval, maxval) 165 return None
166