forked from dbharris/repoman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from repoman_client.subcommand import SubCommand | ||
from repoman_client.client import RepomanClient, RepomanError | ||
from repoman_client.config import config | ||
from argparse import ArgumentParser | ||
import sys | ||
|
||
def yes_or_no(): | ||
answer = raw_input("Confirm deletion [yes]/[n]o: ") | ||
attempts = 1 | ||
while answer in ['y', 'ye']: | ||
if attempts >= 3: | ||
break | ||
answer = raw_input("Type the full word 'yes' to confirm deletion: ") | ||
attempts = attempts + 1 | ||
|
||
if answer.lower() in ['yes']: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
|
||
class RemoveUser(SubCommand): | ||
command_group = "advanced" | ||
command = "remove-user" | ||
alias = None | ||
description = 'Remove an existing user from the repository' | ||
|
||
def get_parser(self): | ||
p = ArgumentParser(self.description) | ||
p.add_argument('user', help='The user you wish to remove') | ||
p.add_argument('-f', '--force', action='store_true', default=False, | ||
help='Do not ask for conformation before deleting') | ||
return p | ||
|
||
def __call__(self, args, extra_args=None): | ||
repo = RepomanClient(config.host, config.port, config.proxy) | ||
if not args.force: | ||
print ("WARNING:\n" | ||
"\tAll images owned by the user will be removed.\n" | ||
"\tThis operation cannot be undone!") | ||
if not yes_or_no(): | ||
print "Aborting user deletion" | ||
return | ||
try: | ||
repo.remove_user(args.user) | ||
except RepomanError, e: | ||
print e | ||
sys.exit(1) | ||
|
||
|
||
|
||
|
||
class RemoveGroup(SubCommand): | ||
command_group = "advanced" | ||
command = "remove-group" | ||
alias = None | ||
description = 'Remove an existing group from the repository' | ||
|
||
def get_parser(self): | ||
p = ArgumentParser(self.description) | ||
p.add_argument('group', help='The group you wish to remove') | ||
p.add_argument('-f', '--force', action='store_true', default=False, | ||
help='Do not ask for conformation before deleting') | ||
return p | ||
|
||
def __call__(self, args, extra_args=None): | ||
repo = RepomanClient(config.host, config.port, config.proxy) | ||
if not args.force: | ||
if not yes_or_no(): | ||
print "Aborting group deletion" | ||
return | ||
|
||
try: | ||
repo.remove_group(args.group) | ||
except RepomanError, e: | ||
print e | ||
sys.exit(1) | ||
|
||
|
||
class RemoveImage(SubCommand): | ||
command_group = "advanced" | ||
command = 'remove-image' | ||
alias = None | ||
description = 'Delete an image from the repository' | ||
|
||
def get_parser(self): | ||
p = ArgumentParser(self.description) | ||
p.add_argument('image', metavar='[USER/]IMAGE', | ||
help='name of image to delete') | ||
p.add_argument('-f', '--force', action='store_true', default=False, | ||
help='Delete image without prompting') | ||
return p | ||
|
||
def __call__(self, args, extra_args=None): | ||
repo = RepomanClient(config.host, config.port, config.proxy) | ||
if not args.force: | ||
print ("WARNING:\n" | ||
"\tdeleting an image cannot be undone.\n") | ||
if not yes_or_no(): | ||
print "Aborting user deletion" | ||
return | ||
|
||
try: | ||
repo.remove_image(args.image) | ||
except RepomanError, e: | ||
print e | ||
sys.exit(1) | ||
|
||
|
||
|
||
class Delete(RemoveImage): | ||
# subclass RemoveImage because they are the same command. | ||
command_group = None | ||
command = "delete" | ||
alias = None | ||
|