Skip to content

Commit

Permalink
subcommands to modify existing objects in repoman
Browse files Browse the repository at this point in the history
  • Loading branch information
mvliet committed Jan 25, 2011
1 parent 6feaeae commit 1e89410
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions repoman-client/repoman_client/subcommands/modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from repoman_client.subcommand import SubCommand
from repoman_client.client import RepomanClient, RepomanError
from repoman_client.config import config
from repoman_client.parsers import parse_unknown_args, ArgumentFormatError
from argparse import ArgumentParser
import sys

class ModifyUser(SubCommand):
command_group = "advanced"
command = "modify-user"
alias = None
description = 'Modify an existing user with the given information'
parse_known_args = True

def get_parser(self):
p = ArgumentParser(self.description)
p.add_argument('user', help='The existing user you want to modify')
return p

def __call__(self, args, extra_args=None):
repo = RepomanClient(config.host, config.port, config.proxy)
if extra_args:
try:
kwargs = parse_unknown_args(extra_args)
except ArgumentFormatError, e:
print e.message
sys.exit(1)
else:
kwargs={}

try:
repo.modify_user(args.user, **kwargs)
print "[OK] Modifying user."
except RepomanError, e:
print "[FAILED] Modifying user.\n\t-%s" % e
sys.exit(1)



class ModifyGroup(SubCommand):
command_group = "advanced"
command = "modify-group"
alias = None
description = 'Modify an existing group with the given information'
parse_known_args = True

def get_parser(self):
p = ArgumentParser(self.description)
p.add_argument('group', help='The existing group you want to modify')
return p

def __call__(self, args, extra_args=None):
repo = RepomanClient(config.host, config.port, config.proxy)
if extra_args:
try:
kwargs = parse_unknown_args(extra_args)
except ArgumentFormatError, e:
print e.message
sys.exit(1)
else:
kwargs={}

try:
repo.modify_group(args.group, **kwargs)
print "[OK] Modifying group."
except RepomanError, e:
print "[FAILED] Modifying group.\n\t-%s" % e
sys.exit(1)



class ModifyImage(SubCommand):
command_group = "advanced"
command = "modify-image"
alias = None
description = 'Modify an existing image with the given information'
parse_known_args = True

def get_parser(self):
p = ArgumentParser(self.description)
p.add_argument('image', help='The existing image you want to modify')
return p

def __call__(self, args, extra_args=None):
repo = RepomanClient(config.host, config.port, config.proxy)
if extra_args:
try:
kwargs = parse_unknown_args(extra_args)
except ArgumentFormatError, e:
print e.message
sys.exit(1)
else:
kwargs={}

try:
repo.modify_image(args.image, **kwargs)
print "[OK] Modifying image."
except RepomanError, e:
print "[FAILED] Modifying image.\n\t-%s" % e
sys.exit(1)



class Rename(SubCommand):
command = 'rename'
alias = None
description = "rename an existing image from 'old' to 'new'"

def get_parser(self):
p = ArgumentParser(self.description)
p.add_argument('old', help='name of exiting image')
p.add_argument('new', help='new name that existing image will get')
return p

def __call__(self, args, extra_args=None):
repo = RepomanClient(config.host, config.port, config.proxy)

kwargs = {'name':args.new}
try:
repo.modify_image(args.old, **kwargs)
print "[OK] Renaming image."
except RepomanError, e:
print "[FAILED] Renaming image.\n\t-%s" % e
sys.exit(1)

0 comments on commit 1e89410

Please sign in to comment.