def run(self): """""" # late import because of setup.py from gpypi.enamer import Enamer from gpypi.ebuild import Ebuild from gpypi.config import Config, ConfigManager # TODO: configure logging (handlers and stuff) self.argparse_config.update({ 'up_pn': self.distribution.get_name(), 'up_pv': self.distribution.get_version(), }) mgr = ConfigManager.load_from_ini(self.config_file) mgr.configs['argparse'] = Config(self.argparse_config) mgr.configs['setup_py'] = Config.from_setup_py( Enamer.parse_setup_py(self.distribution)) ebuild = Ebuild(mgr) ebuild.unpacked_dir = os.getcwd() to = os.path.join(self.dist_dir, ebuild['p'] + '.ebuild') ebuild.create(to) print 'ebuild saved to %s' % to
def run(self): """""" # late import because of setup.py from gpypi.enamer import Enamer from gpypi.ebuild import Ebuild from gpypi.config import Config, ConfigManager # TODO: configure logging (handlers and stuff) self.argparse_config.update({ 'up_pn': self.distribution.get_name(), 'up_pv': self.distribution.get_version(), }) mgr = ConfigManager.load_from_ini(self.config_file) mgr.configs['argparse'] = Config(self.argparse_config) mgr.configs['setup_py'] = Config.from_setup_py(Enamer.parse_setup_py(self.distribution)) ebuild = Ebuild(mgr) ebuild.unpacked_dir = os.getcwd() to = os.path.join(self.dist_dir, ebuild['p'] + '.ebuild') ebuild.create(to) print 'ebuild saved to %s' % to
def main(args=sys.argv[1:]): """Parse command-line options and do it. Core function for gpypi command. Dispatches commands to :class:`gpypi.cli.CLI` """ main_parser = argparse.ArgumentParser(prog='gpypi', description="Builds ebuilds from PyPi.") main_parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) # global options parser = argparse.ArgumentParser(add_help=False) parser.add_argument("-P", "--PN", action='store', dest="pn", help=Config.allowed_options['pn'][0]) parser.add_argument("-V", "--PV", action='store', dest="pv", help=Config.allowed_options['pv'][0]) parser.add_argument("--MY-PV", action='store', dest="my_pv", help=Config.allowed_options['my_pv'][0]) parser.add_argument("--MY-PN", action='store', dest="my_pn", help=Config.allowed_options['my_pn'][0]) parser.add_argument("--MY-P", action='store', dest="my_p", help=Config.allowed_options['my_p'][0]) parser.add_argument("--homepage", action='store', dest="homepage", help=Config.allowed_options['homepage'][0]) parser.add_argument("--keywords", action='store', dest="keywords", help=Config.allowed_options['keywords'][0]) parser.add_argument("--license", action='store', dest="license", help=Config.allowed_options['license'][0]) parser.add_argument("--description", action='store', dest="description", help=Config.allowed_options['description'][0]) # TODO: set long_description in pypi/setup_py parser.add_argument("--long-description", action='store', dest="long_description", help=Config.allowed_options['long_description'][0]) parser.add_argument("-u", "--uri", action='store', dest="uri", help=Config.allowed_options['uri'][0]) parser.add_argument("-i", "--index-url", action='store', dest="index_url", help=Config.allowed_options['index_url'][0]) # TODO: release yolk with support to query third party PyPi # TODO: test --index-url is always taken in account parser.add_argument('--nocolors', action='store_true', dest='nocolors', help=Config.allowed_options['nocolors'][0]) parser.add_argument("--config-file", action='store', dest="config_file", default="/etc/gpypi", help="Absolute path to a config file") logging_group = parser.add_mutually_exclusive_group() logging_group.add_argument("-q", "--quiet", action='store_true', dest="quiet", default=False, help="Show less output.") logging_group.add_argument("-d", "--debug", action='store_true', dest="debug", default=False, help="Show debug information.") # ebuild handling options ebuild_parser = argparse.ArgumentParser(add_help=False) ebuild_parser.add_argument('up_pn', action='store', metavar="package name") ebuild_parser.add_argument('up_pv', nargs='?', default=None, metavar="package version") # create & install options create_install_parser = argparse.ArgumentParser(add_help=False) create_install_parser.add_argument("-l", "--overlay", action='store', dest='overlay', metavar='OVERLAY_NAME', help=Config.allowed_options['overlay'][0]) create_install_parser.add_argument("-o", "--overwrite", action='store_true', dest="overwrite", help=Config.allowed_options['overwrite'][0]) create_install_parser.add_argument("--no-deps", action='store_true', dest="no_deps", help=Config.allowed_options['no_deps'][0]) create_install_parser.add_argument("-c", "--category", default='dev-python', action='store', dest="category", help=Config.allowed_options['category'][0]) # TODO: pretend #create_install_parser.add_argument("-p", "--pretend", action='store_true', #dest="pretend", default=False, help="Print ebuild to stdout, " #"don't write ebuild file, don't download SRC_URI.") # workflow workflow_parser = create_install_parser.add_argument_group('Workflow control', 'Generate metadata, manifest, changelog ...') workflow_parser.add_argument("--metadata-disable", action="store_true", dest="metadata_disable", help=Config.allowed_options['metadata_disable'][0]) workflow_parser.add_argument("--metadata-disable-echangelog-user", action="store_true", dest="metadata_use_echangelog_user", help=Config.allowed_options['metadata_use_echangelog_user'][0]) workflow_parser.add_argument("--metadata-herd", action="store", dest="metadata_herd", help=Config.allowed_options['metadata_herd'][0]) workflow_parser.add_argument("--metadata-maintainer-description", action="store", dest="metadata_maintainer_description", help=Config.allowed_options['metadata_maintainer_description'][0]) workflow_parser.add_argument("--metadata-maintainer-email", action="store", dest="metadata_maintainer_email", help=Config.allowed_options['metadata_maintainer_email'][0]) workflow_parser.add_argument("--metadata-maintainer-name", action="store", dest="metadata_maintainer_name", help=Config.allowed_options['metadata_maintainer_name'][0]) # echangelog workflow_parser.add_argument("--echangelog-disable", action="store_true", dest="echangelog_disable", help=Config.allowed_options['echangelog_disable'][0]) workflow_parser.add_argument("--echangelog-message", action="store", dest="echangelog_message", help=Config.allowed_options['echangelog_message'][0]) # repoman workflow_parser.add_argument("--repoman-commands", action="store", dest="repoman_commands", help=Config.allowed_options['repoman_commands'][0]) ## subcommands subparsers = main_parser.add_subparsers(title="commands", dest="command") parser_create = subparsers.add_parser('create', help="Write ebuild and it's dependencies to an overlay", description="Write ebuild and it's dependencies to an overlay", parents=[parser, ebuild_parser, create_install_parser]) parser_echo = subparsers.add_parser('echo', help="Echo ebuild to stdout", description="Echo ebuild to stdout", parents=[parser, ebuild_parser]) parser_echo.add_argument("--format", action='store', dest="format", help=Config.allowed_options['format'][0]) parser_echo.add_argument("--background", action='store', dest="background", help=Config.allowed_options['background'][0]) parser_install = subparsers.add_parser('install', help="Install ebuild and it's dependencies", description="Install ebuild and it's dependencies", parents=[parser, ebuild_parser, create_install_parser]) parser_pypi = subparsers.add_parser('sync', help="Populate all packages from pypi into an overlay", description="Populate all packages from pypi into an overlay", parents=[parser, create_install_parser]) args = main_parser.parse_args(args) # TODO: configurable logging if args.nocolors: ch = logging.StreamHandler() ch.setFormatter(logging.Formatter("%(message)s")) else: ch = PortageStreamHandler() ch.setFormatter(PortageFormatter("%(message)s")) logger = logging.getLogger() logger.addHandler(ch) if args.debug: logger.setLevel(logging.DEBUG) elif args.quiet: logger.setLevel(logging.WARN) else: logger.setLevel(logging.INFO) # portage group access must be used for write permission in overlay and for # unpacking of ebuilds if secpass < 1: log.warn('Should be run as root or in group ' + str(portage_gid) + ". Expect more problems to come.\n") config_mgr = ConfigManager.load_from_ini(args.config_file) config_mgr.configs['argparse'] = Config.from_argparse(args) # handle command try: CLI(config_mgr) except: # enter pdb debugger when debugging is enabled if args.debug: pdb.post_mortem() else: raise
def main(args=sys.argv[1:]): """Parse command-line options and do it. Core function for gpypi command. Dispatches commands to :class:`gpypi.cli.CLI` """ main_parser = argparse.ArgumentParser( prog='gpypi', description="Builds ebuilds from PyPi.") main_parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) # global options parser = argparse.ArgumentParser(add_help=False) parser.add_argument("-P", "--PN", action='store', dest="pn", help=Config.allowed_options['pn'][0]) parser.add_argument("-V", "--PV", action='store', dest="pv", help=Config.allowed_options['pv'][0]) parser.add_argument("--MY-PV", action='store', dest="my_pv", help=Config.allowed_options['my_pv'][0]) parser.add_argument("--MY-PN", action='store', dest="my_pn", help=Config.allowed_options['my_pn'][0]) parser.add_argument("--MY-P", action='store', dest="my_p", help=Config.allowed_options['my_p'][0]) parser.add_argument("--homepage", action='store', dest="homepage", help=Config.allowed_options['homepage'][0]) parser.add_argument("--keywords", action='store', dest="keywords", help=Config.allowed_options['keywords'][0]) parser.add_argument("--license", action='store', dest="license", help=Config.allowed_options['license'][0]) parser.add_argument("--description", action='store', dest="description", help=Config.allowed_options['description'][0]) # TODO: set long_description in pypi/setup_py parser.add_argument("--long-description", action='store', dest="long_description", help=Config.allowed_options['long_description'][0]) parser.add_argument("-u", "--uri", action='store', dest="uri", help=Config.allowed_options['uri'][0]) parser.add_argument("-i", "--index-url", action='store', dest="index_url", help=Config.allowed_options['index_url'][0]) # TODO: release yolk with support to query third party PyPi # TODO: test --index-url is always taken in account parser.add_argument('--nocolors', action='store_true', dest='nocolors', help=Config.allowed_options['nocolors'][0]) parser.add_argument("--config-file", action='store', dest="config_file", default="/etc/gpypi", help="Absolute path to a config file") logging_group = parser.add_mutually_exclusive_group() logging_group.add_argument("-q", "--quiet", action='store_true', dest="quiet", default=False, help="Show less output.") logging_group.add_argument("-d", "--debug", action='store_true', dest="debug", default=False, help="Show debug information.") # ebuild handling options ebuild_parser = argparse.ArgumentParser(add_help=False) ebuild_parser.add_argument('up_pn', action='store', metavar="package name") ebuild_parser.add_argument('up_pv', nargs='?', default=None, metavar="package version") # create & install options create_install_parser = argparse.ArgumentParser(add_help=False) create_install_parser.add_argument( "-l", "--overlay", action='store', dest='overlay', metavar='OVERLAY_NAME', help=Config.allowed_options['overlay'][0]) create_install_parser.add_argument( "-o", "--overwrite", action='store_true', dest="overwrite", help=Config.allowed_options['overwrite'][0]) create_install_parser.add_argument( "--no-deps", action='store_true', dest="no_deps", help=Config.allowed_options['no_deps'][0]) create_install_parser.add_argument( "-c", "--category", action='store', dest="category", help=Config.allowed_options['category'][0]) # TODO: pretend #create_install_parser.add_argument("-p", "--pretend", action='store_true', #dest="pretend", default=False, help="Print ebuild to stdout, " #"don't write ebuild file, don't download SRC_URI.") # workflow workflow_parser = create_install_parser.add_argument_group( 'Workflow control', 'Generate metadata, manifest, changelog ...') workflow_parser.add_argument( "--metadata-disable", action="store_true", dest="metadata_disable", help=Config.allowed_options['metadata_disable'][0]) workflow_parser.add_argument( "--metadata-disable-echangelog-user", action="store_true", dest="metadata_use_echangelog_user", help=Config.allowed_options['metadata_use_echangelog_user'][0]) workflow_parser.add_argument( "--metadata-herd", action="store", dest="metadata_herd", help=Config.allowed_options['metadata_herd'][0]) workflow_parser.add_argument( "--metadata-maintainer-description", action="store", dest="metadata_maintainer_description", help=Config.allowed_options['metadata_maintainer_description'][0]) workflow_parser.add_argument( "--metadata-maintainer-email", action="store", dest="metadata_maintainer_email", help=Config.allowed_options['metadata_maintainer_email'][0]) workflow_parser.add_argument( "--metadata-maintainer-name", action="store", dest="metadata_maintainer_name", help=Config.allowed_options['metadata_maintainer_name'][0]) # echangelog workflow_parser.add_argument( "--echangelog-disable", action="store_true", dest="echangelog_disable", help=Config.allowed_options['echangelog_disable'][0]) workflow_parser.add_argument( "--echangelog-message", action="store", dest="echangelog_message", help=Config.allowed_options['echangelog_message'][0]) # repoman workflow_parser.add_argument( "--repoman-commands", action="store", dest="repoman_commands", help=Config.allowed_options['repoman_commands'][0]) ## subcommands subparsers = main_parser.add_subparsers(title="commands", dest="command") parser_create = subparsers.add_parser( 'create', help="Write ebuild and it's dependencies to an overlay", description="Write ebuild and it's dependencies to an overlay", parents=[parser, ebuild_parser, create_install_parser]) parser_echo = subparsers.add_parser('echo', help="Echo ebuild to stdout", description="Echo ebuild to stdout", parents=[parser, ebuild_parser]) parser_echo.add_argument("--format", action='store', dest="format", help=Config.allowed_options['format'][0]) parser_echo.add_argument("--background", action='store', dest="background", help=Config.allowed_options['background'][0]) parser_install = subparsers.add_parser( 'install', help="Install ebuild and it's dependencies", description="Install ebuild and it's dependencies", parents=[parser, ebuild_parser, create_install_parser]) parser_pypi = subparsers.add_parser( 'sync', help="Populate all packages from pypi into an overlay", description="Populate all packages from pypi into an overlay", parents=[parser, create_install_parser]) args = main_parser.parse_args(args) # TODO: configurable logging if args.nocolors: ch = logging.StreamHandler() ch.setFormatter(logging.Formatter("%(message)s")) else: ch = PortageStreamHandler() ch.setFormatter(PortageFormatter("%(message)s")) logger = logging.getLogger() logger.addHandler(ch) if args.debug: logger.setLevel(logging.DEBUG) elif args.quiet: logger.setLevel(logging.WARN) else: logger.setLevel(logging.INFO) # portage group access must be used for write permission in overlay and for # unpacking of ebuilds if secpass < 1: log.warn('Should be run as root or in group ' + str(portage_gid) + ". Expect more problems to come.\n") config_mgr = ConfigManager.load_from_ini(args.config_file) config_mgr.configs['argparse'] = Config.from_argparse(args) # handle command try: CLI(config_mgr) except: # enter pdb debugger when debugging is enabled if args.debug: pdb.post_mortem() else: raise