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

Source Code for Module commands.delete_outdated_chroots

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