def parse(self, non_cli_input=None):  # Allow input for testing purposes
        if not sys.argv[1:] and not non_cli_input:
            self.parser.print_help()
            sys.exit(-1)

        try:
            args = self.parser.parse_args(non_cli_input)
        except ArgumentParserError as error:
            if "-h" in sys.argv or "--help" in sys.argv:  # non cli input?
                commands = [cmd for (cmd, description) in Commands.methods.items() if description['visible'] is True]
                command = error.prog.split()[-1]
                if command in commands:
                    self.usage_helper(command)
                else:
                    self.parser.print_help()
                self.parser.exit(2)
            elif "-v" in sys.argv or "--ver" in sys.argv:
                print(version())
                self.parser.exit(0)
            else:
                self.parser.print_usage(sys.stderr)
                self.parser.exit(2, 'error: %s. Use -h for help.\n' % (error.error_message))

        self.cmd = args.command
        self.args = args
        return self.args
예제 #2
0
    def _read_config_snakebiterc(self,
                                 path=os.path.join(os.path.expanduser('~'),
                                                   '.snakebiterc')):
        old_version_info = "You're are using snakebite %s with Trash support together with old snakebiterc, please update/remove your %s file. By default Trash is %s." % (
            path, version(),
            'disabled' if not self.configs['use_trash'] else 'enabled')
        with open(path) as config_file:
            configs = json.load(config_file)

        if isinstance(configs, list):
            # Version 1: List of namenodes
            # config is a list of namenode(s) - possibly HA
            for config in configs:
                nn = Namenode(
                    config['namenode'],
                    self.__use_cl_port_first(
                        config.get('port', Namenode.DEFAULT_PORT)),
                    config.get('version', Namenode.DEFAULT_VERSION))
                self.namenodes.append(nn)
            if self.__usetrash_unset():
                # commandline setting has higher priority
                print_info(old_version_info)
                # There's no info about Trash in version 1, use default policy:
                self.args.usetrash = self.configs['use_trash']
        elif isinstance(configs, dict):
            # Version 2: {}
            # Can be either new configuration or just one namenode
            # which was the very first configuration syntax
            if 'config_version' in configs:
                # Config version => 2
                for nn_config in configs['namenodes']:
                    nn = Namenode(
                        nn_config['host'],
                        self.__use_cl_port_first(
                            nn_config.get('port', Namenode.DEFAULT_PORT)),
                        nn_config.get('version', Namenode.DEFAULT_VERSION))
                    self.namenodes.append(nn)

                if self.__usetrash_unset():
                    # commandline setting has higher priority
                    self.args.usetrash = configs.get("use_trash",
                                                     self.configs['use_trash'])

                self.user = configs.get("user")
            else:
                # config is a single namenode - no HA
                self.namenodes.append(
                    Namenode(
                        configs['namenode'],
                        self.__use_cl_port_first(
                            configs.get('port', Namenode.DEFAULT_PORT)),
                        configs.get('version', Namenode.DEFAULT_VERSION)))
                if self.__usetrash_unset():
                    # commandline setting has higher priority
                    print_info(old_version_info)
                    self.args.usetrash = self.configs['use_trash']
        else:
            print_error_exit(
                "Config retrieved from %s is corrupted! Remove it!" % path)
예제 #3
0
파일: setup.py 프로젝트: wxiang7/snakebite
        errno = tox.cmdline(args=self.tox_args.split())
        sys.exit(errno)

install_requires = [
    'protobuf>2.4.1',
    'argparse',
    'sasl',
    'python-krbV']

tests_require = [
    'tox',
    'virtualenv>=1.11.2']

setup(
    name='snakebite',
    version=version(),
    author=u'Wouter de Bie',
    author_email='*****@*****.**',
    description='Pure Python HDFS client',
    url='http://github.com/spotify/snakebite',
    packages=['snakebite', 'snakebite.protobuf'],
    scripts=['bin/snakebite'],
    license='Apache License 2.0',
    keywords='hadoop protobuf hdfs'.split(),
    classifiers=[
        'Topic :: Utilities',
        'Programming Language :: Python',
        'Operating System :: POSIX :: Linux',
        'Operating System :: MacOS',
        'Topic :: Software Development :: Libraries :: Application Frameworks',
        'Environment :: Other Environment'