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

Source Code for Module commands.alter_chroot

 1  import datetime 
 2  import click 
 3   
 4  from coprs import db_session_scope 
 5  from coprs import app 
 6  from coprs import exceptions 
 7  from coprs.logic import coprs_logic 
 8  from commands.create_chroot import print_invalid_format, print_doesnt_exist 
 9   
10   
11  @click.command() 
12  @click.argument( 
13      "chroot_names", 
14      nargs=-1 
15  ) 
16  @click.option( 
17      "--action", "-a", "action", 
18      help="Action to take - currently activate or deactivate", 
19      required=True, 
20      type=click.Choice(["activate", "deactivate", "eol"]) 
21  ) 
22 -def alter_chroot(chroot_names, action):
23 """Activates or deactivates a chroot""" 24 activate = (action == "activate") 25 for chroot_name in chroot_names: 26 try: 27 with db_session_scope(): 28 mock_chroot = coprs_logic.MockChrootsLogic.edit_by_name( 29 chroot_name, activate) 30 31 if action != "eol": 32 continue 33 34 for copr_chroot in mock_chroot.copr_chroots: 35 delete_after_days = app.config["DELETE_EOL_CHROOTS_AFTER"] + 1 36 delete_after_timestamp = datetime.datetime.now() + datetime.timedelta(delete_after_days) 37 # Workarounding an auth here 38 coprs_logic.CoprChrootsLogic.update_chroot(copr_chroot.copr.user, copr_chroot, 39 delete_after=delete_after_timestamp) 40 except exceptions.MalformedArgumentException: 41 print_invalid_format(chroot_name) 42 except exceptions.NotFoundException: 43 print_doesnt_exist(chroot_name)
44