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.
subcommands to modify existing objects in repoman
- Loading branch information
Showing
1 changed file
with
125 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,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) | ||
|