Exemple #1
0
def ask_user(env, param, opts, directory_list=None, output_str=None):
    """ask the user for `param` to fill ``opts[param]``"""

    if output_str:
        # for better controling about the CLI-Output
        output_str = output_str
    else:
        output_str = param

    assert directory_list is not None  # needed ;)

    print _('\nThe following %s, found by Globby:\n') % _(output_str)
    i = 0
    for sub_directory in directory_list:
        i += 1
        print '(%d) -- %s' % (i, sub_directory)
    print _('\nNow fill in the number of the %s') % _(output_str)
    print colors.bold(_('To exit Globby fill in "END"!'))
    users_choice = raw_input(_('Choice: '))
    if users_choice.lower().startswith('e'):
        env.exit_globby()

    while True:
        try:
            users_choice = int(users_choice)
            if users_choice != 0:
                opts[param] = directory_list[users_choice - 1]
                print _('You choose "%s"') % opts[param]
                break
        except (ValueError, IndexError):
            #the user entered a string instead of a integer
            if users_choice in directory_list:
                opts[param] = users_choice
                print _('You choose "%s"') % opts[param]
                break

        # this only happens if we **dont** break before, so the user entered
        # something wrong....
        print _('\nSorry, this %s does not exist!') % _(output_str)
        print(
            _('fill in "%(end)s" to exit Globby \n'
              'or fill in the correct %(out_str)s\n') % {
                  'end': colors.bold(_('END')),
                  'out_str': _(output_str)
              })
        users_choice = raw_input(_('new choice: '))
Exemple #2
0
def ask_user(env, param, opts, directory_list=None, output_str=None):
    """ask the user for `param` to fill ``opts[param]``"""

    if output_str:
        # for better controling about the CLI-Output
        output_str = output_str
    else:
        output_str = param

    assert directory_list is not None # needed ;)

    print _('\nThe following %s, found by Globby:\n') % _(output_str)
    i = 0
    for sub_directory in directory_list:
        i += 1
        print '(%d) -- %s' % (i, sub_directory)
    print _('\nNow fill in the number of the %s') % _(output_str)
    print colors.bold(_('To exit Globby fill in "END"!'))
    users_choice = raw_input(_('Choice: '))
    if users_choice.lower().startswith('e'):
        env.exit_globby()

    while True:
        try:
            users_choice = int(users_choice)
            if users_choice != 0:
                opts[param] = directory_list[users_choice-1]
                print _('You choose "%s"') % opts[param]
                break
        except (ValueError, IndexError):
            #the user entered a string instead of a integer
            if users_choice in directory_list:
                opts[param] = users_choice
                print _('You choose "%s"') % opts[param]
                break

        # this only happens if we **dont** break before, so the user entered
        # something wrong....
        print _('\nSorry, this %s does not exist!') % _(output_str)
        print (_('fill in "%(end)s" to exit Globby \n'
               'or fill in the correct %(out_str)s\n') % {
                   'end': colors.bold(_('END')), 'out_str': _(output_str)})
        users_choice = raw_input(_('new choice: '))
Exemple #3
0
    def format_option(self, option):
        result = []

        opts = self.option_strings[option]
        # the help-string, where all available options
        # will be printed (long and short options)
        opts = colors.bold('\n%s\n' % (opts))

        result.append(opts)

        if option.help:
            help_lines = self.expand_default(option)
            for help_line in help_lines:
                result.append(colors.blue('%*s%s\n' % (4, ' ', _(help_line))))
        return ''.join(result)
Exemple #4
0
    def format_option(self, option):
        result = []

        opts = self.option_strings[option]
        # the help-string, where all available options
        # will be printed (long and short options)
        opts = colors.bold('\n%s\n' % (opts))

        result.append(opts)

        if option.help:
            help_lines = self.expand_default(option)
            for help_line in help_lines:
                result.append(colors.blue('%*s%s\n' % (4, ' ', _(help_line))))
        return ''.join(result)
Exemple #5
0
 def clean_logs(self):
     """
     Count existing log files.
     If more then 50 log files exist Globby will delete them all
     """
     log_re = re.compile(r"\d{4}-\d{1,2}-\d{1,2}_\[(?:\d{1,2}-){2}\d{1,2}\].log")
     log_counter = 0
     for log in os.listdir(self.logs_path):
         if log_re.match(log):
             log_counter += 1
     if log_counter > 50:
         self.info_msg(bold(_("The maximum of log files is arrived." " I'll delete all logs!")))
         for log_file in os.listdir(self.logs_path):
             if os.path.isfile(join(self.logs_path, log_file)):
                 os.remove(join(self.logs_path, log_file))
Exemple #6
0
 def clean_logs(self):
     """
     Count existing log files.
     If more then 50 log files exist Globby will delete them all
     """
     log_re = re.compile(
         r'\d{4}-\d{1,2}-\d{1,2}_\[(?:\d{1,2}-){2}\d{1,2}\].log')
     log_counter = 0
     for log in os.listdir(self.logs_path):
         if log_re.match(log):
             log_counter += 1
     if log_counter > 50:
         self.info_msg(
             bold(
                 _('The maximum of log files is arrived.'
                   ' I\'ll delete all logs!')))
         for log_file in os.listdir(self.logs_path):
             if os.path.isfile(join(self.logs_path, log_file)):
                 os.remove(join(self.logs_path, log_file))
Exemple #7
0
 def format_heading(self, heading):
     return colors.bold('%*s%s:\n' % (self.current_indent, '', heading))
Exemple #8
0
 def format_heading(self, heading):
     return colors.bold('%*s%s:\n' % (self.current_indent, '', heading))