Package portage :: Package _emirrordist :: Module DeletionIterator
[hide private]

Source Code for Module portage._emirrordist.DeletionIterator

 1  # Copyright 2013 Gentoo Foundation 
 2  # Distributed under the terms of the GNU General Public License v2 
 3   
 4  import logging 
 5  import stat 
 6   
 7  from portage import os 
 8  from .DeletionTask import DeletionTask 
 9   
10 -class DeletionIterator(object):
11
12 - def __init__(self, config):
13 self._config = config
14
15 - def __iter__(self):
16 distdir = self._config.options.distfiles 17 file_owners = self._config.file_owners 18 whitelist = self._config.whitelist 19 distfiles_local = self._config.options.distfiles_local 20 deletion_db = self._config.deletion_db 21 deletion_delay = self._config.options.deletion_delay 22 start_time = self._config.start_time 23 distfiles_set = set(os.listdir(self._config.options.distfiles)) 24 for filename in distfiles_set: 25 try: 26 st = os.stat(os.path.join(distdir, filename)) 27 except OSError as e: 28 logging.error("stat failed on '%s' in distfiles: %s\n" % 29 (filename, e)) 30 continue 31 if not stat.S_ISREG(st.st_mode): 32 continue 33 elif filename in file_owners: 34 if deletion_db is not None: 35 try: 36 del deletion_db[filename] 37 except KeyError: 38 pass 39 elif whitelist is not None and filename in whitelist: 40 if deletion_db is not None: 41 try: 42 del deletion_db[filename] 43 except KeyError: 44 pass 45 elif distfiles_local is not None and \ 46 os.path.exists(os.path.join(distfiles_local, filename)): 47 if deletion_db is not None: 48 try: 49 del deletion_db[filename] 50 except KeyError: 51 pass 52 else: 53 self._config.scheduled_deletion_count += 1 54 55 if deletion_db is None or deletion_delay is None: 56 57 yield DeletionTask(background=True, 58 distfile=filename, 59 config=self._config) 60 61 else: 62 deletion_entry = deletion_db.get(filename) 63 64 if deletion_entry is None: 65 logging.debug("add '%s' to deletion db" % filename) 66 deletion_db[filename] = start_time 67 68 elif deletion_entry + deletion_delay <= start_time: 69 70 yield DeletionTask(background=True, 71 distfile=filename, 72 config=self._config) 73 74 if deletion_db is not None: 75 for filename in list(deletion_db): 76 if filename not in distfiles_set: 77 try: 78 del deletion_db[filename] 79 except KeyError: 80 pass 81 else: 82 logging.debug("drop '%s' from deletion db" % 83 filename)
84