Пример #1
0
    def __init__(self, shell_name='pypsi', width=80, exit_rc=-1024, ctx=None):
        '''
        :param str shell_name: the name of the shell; used in error messages
        :param int exit_rc: the exit return code that is returned from a command
            when the shell needs to end execution
        :param pypsi.namespace.Namespace ctx: the base context
        '''
        self.real_stdout = sys.stdout
        self.real_stdin = sys.stdin
        self.real_stderr = sys.stderr
        self.width = width
        self.shell_name = shell_name
        self.exit_rc = exit_rc
        self.errno = 0
        self.commands = {}
        self.preprocessors = []
        self.postprocessors = []
        self.plugins = []
        self.prompt = "{name} )> ".format(name=shell_name)
        self.ctx = ctx or Namespace()

        self.parser = StatementParser()
        self.default_cmd = None
        self.register_base_plugins()
        self.fallback_cmd = None

        self.on_shell_ready()
Пример #2
0
 def __init__(self, name, description, steps=None):
     '''
     :param str name: the prompt wizard name to display to the user
     :param str description: a short description of what the wizard does
     :param list steps: a list of :class:`WizardStep` objects
     '''
     self.name = name
     self.description = description
     self.steps = steps
     self.values = Namespace()
     self.parser = StatementParser()
Пример #3
0
def _merge_namespaces(*namespaces):
    from pypsi.namespace import Namespace

    merged_namespace = Namespace()
    for namespace in namespaces:
        for k, v in namespace.__dict__.items():
            if k in merged_namespace:
                raise ValueError(
                    'Duplicate key in Namespace: {key}'.format(key=k))
        merged_namespace.__dict__.update(namespace.__dict__)
    return merged_namespace
Пример #4
0
 def setUp(self):
     self.addon_info = Namespace(
         package_name='mypackagename',
         version='1.2.3',
         description='this is my one-line summary',
         long_description='this is my long description',
         maintainer='I Am Maintainer',
         maintainer_email='*****@*****.**',
         install_requires='some_package==1.2.3',
         entrypoint='ThisIsMyEntryPoint',
         command=MOCK_COMMAND,
     )
Пример #5
0
def test():
    shell = Namespace(width=80)
    ns = PromptWizard(
        name="Datastore Configuration",
        description="Setup Metasponse Datastore",
        steps=(
            WizardStep('host', 'Hostname', '', 'localhost', validators=required_validator),
            WizardStep('port', "Port", '', 3306, validators=(required_validator, int_validator(0, 0xffff)))
        )
    ).run(shell)

    print(ns.host)
    print(ns.port)
Пример #6
0
    def __init__(self,
                 shell_name='pypsi',
                 width=79,
                 exit_rc=-1024,
                 ctx=None,
                 features=None,
                 completer_delims=None):
        '''
        Subclasses need to call the Shell constructor to properly initialize
        it.

        :param str shell_name: the name of the shell; used in error messages
        :param int exit_rc: the exit return code that is returned from a
            command when the shell needs to end execution
        :param pypsi.namespace.Namespace ctx: the base context
        '''
        self.backup_stdout = None
        self.backup_stdin = None
        self.backup_stderr = None
        self.backup_print = None

        self.width = width
        self.shell_name = shell_name
        self.exit_rc = exit_rc
        self.errno = 0
        self.commands = {}
        self.preprocessors = []
        self.postprocessors = []
        self.plugins = []
        self.prompt = "{name} )> ".format(name=shell_name)
        self.ctx = ctx or Namespace()
        self.features = features or BashFeatures()
        self.running = False
        self.completion_matches = None
        self.completer_delims = completer_delims

        self.default_cmd = None
        self.register_base_plugins()
        self.fallback_cmd = None

        self.eof_is_sigint = False
        self._backup_completer = readline.get_completer()

        self.bootstrap()

        self.on_shell_ready()
Пример #7
0
 def __init__(self,
              name,
              description,
              steps=None,
              features=None,
              complete_single_token=False):
     '''
     :param str name: the prompt wizard name to display to the user
     :param str description: a short description of what the wizard does
     :param list steps: a list of :class:`WizardStep` objects
     :param bool complete_single_token: treat tab completion requests as a literal string and
         do not tokenize the input (complete args will always be a single item list)
     '''
     self.name = name
     self.description = description
     self.steps = steps
     self.features = features
     self.complete_single_token = complete_single_token
     self.values = Namespace()
     self.completions = None
     self.old_completer = None
     self.active_step = None
Пример #8
0
 def test_package_name_validator_valid(self):
     validator = wiz.package_name_validator('package')
     assert validator(Namespace(), 'package_name') == 'package_name'
Пример #9
0
 def test_module_name_validator_int(self):
     validator = wiz.module_name_validator('mod')
     assert validator(Namespace(), 10) == 10
Пример #10
0
 def test_module_name_validator_empty(self):
     validator = wiz.module_name_validator('mod')
     assert validator(Namespace(), '   ') == ''
Пример #11
0
 def test_int_validator_none(self):
     validator = wiz.int_validator()
     assert validator(Namespace(), None) is None
Пример #12
0
 def __init__(self, name, description, steps=None):
     self.name = name
     self.description = description
     self.steps = steps
     self.values = Namespace()
     self.parser = StatementParser()
Пример #13
0
 def test_required_validator_nonstring(self):
     assert wiz.required_validator(Namespace(), 10) == 10
Пример #14
0
 def test_int_validator_plain_valid(self):
     validator = wiz.int_validator()
     assert validator(Namespace(), '10') == 10
Пример #15
0
 def test_hostname_validator_invalid(self):
     with pytest.raises(ValueError):
         wiz.hostname_or_ip_validator(Namespace(), 'asdf\x1b')
Пример #16
0
 def test_ip_validator_valid(self):
     assert wiz.hostname_or_ip_validator(Namespace(), '192.168.0.1') == '192.168.0.1'
Пример #17
0
 def test_hostname_validator_valid(self):
     assert wiz.hostname_or_ip_validator(Namespace(), 'google.com') == 'google.com'
Пример #18
0
 def test_directory_validator_file(self):
     with pytest.raises(ValueError):
         wiz.directory_validator(Namespace(), __file__)
Пример #19
0
 def test_directory_validator_directory(self):
     assert wiz.directory_validator(Namespace(), "." + os.path.sep) == "." + os.path.sep
Пример #20
0
 def test_file_validator_directory(self):
     with pytest.raises(ValueError):
         wiz.file_validator(Namespace(), "." + os.path.sep)
Пример #21
0
 def test_file_validator_file(self):
     assert wiz.file_validator(Namespace(), __file__) == __file__
Пример #22
0
 def test_package_name_validator_invalid(self):
     validator = wiz.package_name_validator('package')
     with pytest.raises(ValueError):
         validator(Namespace(), 'package.name')
Пример #23
0
 def test_int_validator_max(self):
     validator = wiz.int_validator(max=11)
     with pytest.raises(ValueError):
         validator(Namespace(), '15')
Пример #24
0
 def test_boolean_validator_invalid(self):
     with pytest.raises(ValueError):
         assert wiz.boolean_validator(Namespace(), 'asdf')
Пример #25
0
 def test_required_validator_none(self):
     with pytest.raises(ValueError):
         wiz.required_validator(Namespace(), None)
Пример #26
0
 def test_module_name_validator_valid(self):
     validator = wiz.module_name_validator('mod')
     assert validator(Namespace(), '  somemod.package.mod') == 'somemod.package.mod'
Пример #27
0
 def test_module_name_validator_invalid(self):
     validator = wiz.module_name_validator('mod')
     with pytest.raises(ValueError):
         validator(Namespace(), 'not-valid..module')
Пример #28
0
 def test_required_validator_empty_str(self):
     with pytest.raises(ValueError):
         wiz.required_validator(Namespace(), '')
Пример #29
0
 def test_hostname_validator_empty(self):
     assert wiz.hostname_or_ip_validator(Namespace(), '   ') == ''
Пример #30
0
 def test_int_validator_range(self):
     validator = wiz.int_validator(min=10, max=20)
     assert validator(Namespace(), '15') == 15