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