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 import app 
 4  from coprs.logic import coprs_logic, actions_logic 
 5   
 6   
 7  @click.command() 
 8  @click.option( 
 9      "--dry-run/--no-dry-run", 
10      default=False, 
11      help="Do not actually remove any data, but rather print information on stdout" 
12  ) 
13 -def delete_outdated_chroots(dry_run):
14 return delete_outdated_chroots_function(dry_run)
15
16 17 -def delete_outdated_chroots_function(dry_run):
18 """ 19 Delete data in all chroots that are considered as outdated. That means, the chroot is EOL 20 and the preservation period is over because admin of the project didn't extend its duration. 21 """ 22 23 deleter = DryRunDeleter() if dry_run else Deleter() 24 25 chroots = coprs_logic.CoprChrootsLogic \ 26 .filter_outdated_to_be_deleted(coprs_logic.CoprChrootsLogic.get_multiple()) 27 for i, chroot in enumerate(chroots, start=1): 28 29 # This shouldn't happen but we should play it safe, not just hope 30 if not chroot.delete_notify: 31 app.logger.error("Refusing to delete {0}/{1} because any notification was sent about its deletion", 32 chroot.copr.full_name, chroot.name) 33 continue 34 35 # This command will possibly delete a lot of chroots and can be a performance issue when committing 36 # all at once. We are going to commit every x actions to avoid that. 37 if i % 1000 == 0: 38 deleter.commit() 39 deleter.delete(chroot) 40 deleter.commit()
41
42 43 -class Deleter(object):
44 - def delete(self, chroot):
47
48 - def commit(self):
49 db.session.commit()
50
51 52 -class DryRunDeleter(object):
53 - def delete(self, chroot):
54 print("Add delete_chroot action for {} in {}".format(chroot.name, chroot.copr.full_name))
55
56 - def commit(self):
57 pass
58