Beispiel #1
0
 def _modules(self):
     home = os.getcwd()
     modules_dir = os.path.join(home, 'modules')
     filenames = willie.loader.enumerate_modules(self)
     os.sys.path.insert(0, modules_dir)
     for name, mod_spec in iteritems(filenames):
         path, type_ = mod_spec
         try:
             module, _ = willie.loader.load_module(name, path, type_)
         except Exception as e:
             filename, lineno = willie.tools.get_raising_file_and_line()
             rel_path = os.path.relpath(filename, os.path.dirname(__file__))
             raising_stmt = "%s:%d" % (rel_path, lineno)
             stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt))
         else:
             if hasattr(module, 'configure'):
                 prompt = name + ' module'
                 if module.__doc__:
                     doc = module.__doc__.split('\n', 1)[0]
                     if doc:
                         prompt = doc
                 prompt = 'Configure {} (y/n)? [n]'.format(prompt)
                 do_configure = get_input(prompt)
                 do_configure = do_configure and do_configure.lower() == 'y'
                 if do_configure:
                     module.configure(self)
     self.save()
Beispiel #2
0
 def _modules(self):
     home = os.getcwd()
     modules_dir = os.path.join(home, 'modules')
     filenames = willie.loader.enumerate_modules(self)
     os.sys.path.insert(0, modules_dir)
     for name, mod_spec in iteritems(filenames):
         path, type_ = mod_spec
         try:
             module, _ = willie.loader.load_module(name, path, type_)
         except Exception as e:
             filename, lineno = willie.tools.get_raising_file_and_line()
             rel_path = os.path.relpath(filename, os.path.dirname(__file__))
             raising_stmt = "%s:%d" % (rel_path, lineno)
             stderr("Error loading %s: %s (%s)" % (name, e, raising_stmt))
         else:
             if hasattr(module, 'configure'):
                 prompt = name + ' module'
                 if module.__doc__:
                     doc = module.__doc__.split('\n', 1)[0]
                     if doc:
                         prompt = doc
                 prompt = 'Configure {} (y/n)? [n]'.format(prompt)
                 do_configure = get_input(prompt)
                 do_configure = do_configure and do_configure.lower() == 'y'
                 if do_configure:
                     module.configure(self)
     self.save()
Beispiel #3
0
    def configure(self, prompt, default):
        each_prompt = '?'
        if isinstance(prompt, tuple):
            each_prompt = prompt[1]
            prompt = prompt[0]

        if default is not NO_DEFAULT:
            default = ','.join(default)
            prompt = '{} [{}]'.format(prompt, default)
        else:
            default = ''
        print(prompt)
        values = []
        value = get_input(each_prompt + ' ') or default
        while value:
            values.append(value)
            value = get_input(each_prompt + ' ')
        return self.parse(','.join(values))
Beispiel #4
0
    def configure(self, prompt, default):
        each_prompt = "?"
        if isinstance(prompt, tuple):
            each_prompt = prompt[1]
            prompt = prompt[0]

        if default is not NO_DEFAULT:
            default = ",".join(default)
            prompt = "{} [{}]".format(prompt, default)
        else:
            default = ""
        print(prompt)
        values = []
        value = get_input(each_prompt + " ") or default
        while value:
            values.append(value)
            value = get_input(each_prompt + " ")
        return self.parse(",".join(values))
Beispiel #5
0
    def configure(self, prompt, default):
        each_prompt = '?'
        if isinstance(prompt, tuple):
            each_prompt = prompt[1]
            prompt = prompt[0]

        if default is not NO_DEFAULT:
            default = ','.join(default)
            prompt = '{} [{}]'.format(prompt, default)
        else:
            default = ''
        print(prompt)
        values = []
        value = get_input(each_prompt + ' ') or default
        while value:
            values.append(value)
            value = get_input(each_prompt + ' ')
        return self.parse(','.join(values))
Beispiel #6
0
 def configure(self, prompt, default):
     """With the prompt and default, parse and return a value from terminal.
     """
     if default is not NO_DEFAULT and default is not None:
         prompt = '{} [{}]'.format(prompt, default)
     value = get_input(prompt + ' ')
     if not value and default is NO_DEFAULT:
         raise ValueError("You must provide a value for this option.")
     value = value or default
     return self.parse(value)
Beispiel #7
0
 def configure(self, prompt, default):
     """With the prompt and default, parse and return a value from terminal.
     """
     if default is not NO_DEFAULT and default is not None:
         prompt = '{} [{}]'.format(prompt, default)
     value = get_input(prompt + ' ')
     if not value and default is NO_DEFAULT:
         raise ValueError("You must provide a value for this option.")
     value = value or default
     return self.parse(value)
Beispiel #8
0
    def option(self, question, default=False):
        """Ask "y/n" and return the corresponding boolean answer.

        Show user in terminal a "y/n" prompt, and return true or false based on
        the response. If default is passed as true, the default will be shown
        as ``[y]``, else it will be ``[n]``. ``question`` should be phrased as
        a question, but without a question mark at the end.

        """
        d = 'n'
        if default:
            d = 'y'
        ans = get_input(question + ' (y/n)? [' + d + '] ')
        if not ans:
            ans = d
        return ans.lower() == 'y'
Beispiel #9
0
    def option(self, question, default=False):
        """Ask "y/n" and return the corresponding boolean answer.

        Show user in terminal a "y/n" prompt, and return true or false based on
        the response. If default is passed as true, the default will be shown
        as ``[y]``, else it will be ``[n]``. ``question`` should be phrased as
        a question, but without a question mark at the end.

        """
        d = 'n'
        if default:
            d = 'y'
        ans = get_input(question + ' (y/n)? [' + d + '] ')
        if not ans:
            ans = d
        return ans.lower() == 'y'