Package copr_cli :: Module main
[hide private]
[frames] | no frames]

Source Code for Module copr_cli.main

  1  #-*- coding: UTF-8 -*- 
  2   
  3  import argparse 
  4  import sys 
  5   
  6  import subcommands 
  7  import copr_exceptions 
  8   
  9  __version__ = '0.1.0' 
 10  __description__ = "CLI tool to run copr" 
 11   
 12   
13 -def action_build(args):
14 """ Method called when the 'build' action has been selected by the 15 user. 16 17 :param args: argparse arguments provided by the user 18 19 """ 20 subcommands.build(args.copr, args.pkgs, 21 args.memory, args.timeout)
22 23
24 -def action_create(args):
25 """ Method called when the 'create' action has been selected by the 26 user. 27 28 :param args: argparse arguments provided by the user 29 30 """ 31 subcommands.create(args.name, args.chroots, args.description, 32 args.instructions, args.repos, 33 args.initial_pkgs)
34 35
36 -def action_list(args):
37 """ Method called when the 'list' action has been selected by the 38 user. 39 40 :param args: argparse arguments provided by the user 41 42 """ 43 subcommands.listcoprs(args.username)
44 45
46 -def setup_parser():
47 """ 48 Set the main arguments. 49 """ 50 parser = argparse.ArgumentParser(prog="copr-cli") 51 # General connection options 52 parser.add_argument('--version', action='version', 53 version='copr-cli %s' % (__version__)) 54 55 subparsers = parser.add_subparsers(title='actions') 56 57 # create the parser for the "list" command 58 parser_list = subparsers.add_parser('list', 59 help='List all the copr of the ' 60 'provided ' 61 ) 62 parser_list.add_argument("username", nargs='?', 63 help='The username that you would like to ' 64 'list the copr of (defaults to current user)' 65 ) 66 parser_list.set_defaults(func=action_list) 67 68 # create the parser for the "create" command 69 parser_create = subparsers.add_parser('create', 70 help='Create a new copr') 71 parser_create.add_argument('name', 72 help='The name of the copr to create') 73 parser_create.add_argument("--chroot", dest="chroots", action='append', 74 help="Chroot to use for this copr") 75 parser_create.add_argument('--repo', dest='repos', action='append', 76 help="Repository to add to this copr") 77 parser_create.add_argument('--initial-pkgs', dest='initial_pkgs', 78 action='append', 79 help="List of packages to build in this " 80 "new copr") 81 parser_create.add_argument('--description', 82 help="Description of the copr") 83 parser_create.add_argument('--instructions', 84 help="Instructions for the copr") 85 parser_create.set_defaults(func=action_create) 86 87 # create the parser for the "build" command 88 parser_build = subparsers.add_parser('build', 89 help='Build packages to a ' 90 'specified copr') 91 parser_build.add_argument('copr', 92 help='The copr repo to build the package in' 93 ) 94 parser_build.add_argument('pkgs', nargs='+', action='append') 95 parser_build.add_argument('--memory', dest='memory', 96 help="") 97 parser_build.add_argument('--timeout', dest='timeout', 98 help="") 99 parser_build.set_defaults(func=action_build) 100 101 return parser
102 103
104 -def main(argv=sys.argv[1:]):
105 """ Main function """ 106 try: 107 # Set up parser for global args 108 parser = setup_parser() 109 # Parse the commandline 110 arg = parser.parse_args() 111 arg.func(arg) 112 except KeyboardInterrupt: 113 print "\nInterrupted by user." 114 sys.exit(1) 115 except argparse.ArgumentTypeError, e: 116 print "\nError: {0}".format(e) 117 sys.exit(2) 118 except copr_exceptions.CoprCliException, e: 119 print "\nError: {0}".format(e) 120 sys.exit(3)
121 #except Exception, e: 122 #print 'Error: {0}'.format(e) 123 #sys.exit(100) 124 125 126 if __name__ == '__main__': 127 main() 128