Package commands :: Module delete_outdated_chroots
[hide private]
[frames] | no frames]

Source Code for Module commands.delete_outdated_chroots

 1  from flask_script import Command, Option 
 2  from coprs import db 
 3  from coprs.logic import coprs_logic, actions_logic 
 4   
 5   
6 -class DeleteOutdatedChrootsCommand(Command):
7 """ 8 Delete data in all chroots that are considered as outdated. That means, the chroot is EOL 9 and the preservation period is over because admin of the project didn't extend its duration. 10 """ 11 option_list = [ 12 Option("--dry-run", action="store_true", 13 help="Do not actually remove any data, but rather print information on stdout"), 14 ] 15
16 - def run(self, dry_run):
17 deleter = DryRunDeleter() if dry_run else Deleter() 18 19 chroots = coprs_logic.CoprChrootsLogic \ 20 .filter_outdated_to_be_deleted(coprs_logic.CoprChrootsLogic.get_multiple()) 21 for i, chroot in enumerate(chroots, start=1): 22 # This command will possibly delete a lot of chroots and can be a performance issue when committing 23 # all at once. We are going to commit every x actions to avoid that. 24 if i % 1000 == 0: 25 deleter.commit() 26 deleter.delete(chroot) 27 deleter.commit()
28 29
30 -class Deleter(object):
31 - def delete(self, chroot):
34
35 - def commit(self):
36 db.session.commit()
37 38
39 -class DryRunDeleter(object):
40 - def delete(self, chroot):
41 print("Add delete_chroot action for {} in {}".format(chroot.name, chroot.copr.full_name))
42
43 - def commit(self):
44 pass
45