コード例 #1
0
    def do_show_rules_with_status(self):
        default = Status.text_to_status('problem')
        self.cmpl.set_choices_completion(['A'] + Status.STATUSES + ['Q'],
                                         default)
        while True:
            statuses_text = Status.get_statuses_prompt(", ")
            status = raw_input("status type A(all), " + statuses_text +
                               ", Q(quit)) [%s]: " % default)
            status = status.strip()
            if status == "":
                status = default

            if status == 'q' or status == 'Q':
                return None
            elif status[0].upper() not in ['A'] + Status.STATUSES:
                print "Unknown status type"
                continue

            readline.set_completer(None)
            prefix = raw_input("starting with prefix? [/]: ")
            prefix = prefix.strip()
            if prefix == "":
                prefix = "/"
            if status == 'a' or status == 'A':
                clouseau.retention.utils.ruleutils.show_rules(self.cdb,
                                                              self.cenv.host,
                                                              prefix=prefix)
                return True
            elif status[0].upper() in Status.STATUSES:
                clouseau.retention.utils.ruleutils.show_rules(
                    self.cdb, self.cenv.host, status[0].upper(), prefix=prefix)
                return True
コード例 #2
0
ファイル: cli.py プロジェクト: wikimedia/operations-software
    def do_show_rules_with_status(self):
        default = Status.text_to_status('problem')
        self.cmpl.set_choices_completion(['A'] + Status.STATUSES + ['Q'], default)
        while True:
            statuses_text = Status.get_statuses_prompt(", ")
            status = raw_input("status type A(all), " + statuses_text +
                               ", Q(quit)) [%s]: " % default)
            status = status.strip()
            if status == "":
                status = default

            if status == 'q' or status == 'Q':
                return None
            elif status[0].upper() not in ['A'] + Status.STATUSES:
                print "Unknown status type"
                continue

            readline.set_completer(None)
            prefix = raw_input("starting with prefix? [/]: ")
            prefix = prefix.strip()
            if prefix == "":
                prefix = "/"
            if status == 'a' or status == 'A':
                clouseau.retention.utils.ruleutils.show_rules(
                    self.cdb, self.cenv.host, prefix=prefix)
                return True
            elif status[0].upper() in Status.STATUSES:
                clouseau.retention.utils.ruleutils.show_rules(
                    self.cdb, self.cenv.host, status[0].upper(), prefix=prefix)
                return True
コード例 #3
0
ファイル: cli.py プロジェクト: wikimedia/operations-software
 def show_menu(self, level):
     if level == 'top':
         text = ("S(set status)/E(examine directory)/"
                 "Filter directory listings/"
                 "I(ignore)/R(manage rules)/Q(quit menu)")
         command = self.get_menu_entry(['S', 'E', 'I', 'F', 'R', 'Q'], 'S', text)
     elif level == 'status':
         text = Status.get_statuses_prompt(", ") + ", Q(quit status menu)"
         command = self.get_menu_entry(Status.STATUSES + ['Q'], text,
                                       Status.text_to_status('good'))
         if command == 'Q' or command == 'q':
             level = 'top'
     elif level == 'examine':
         text = ("D(down a level)/U(up a level)/E(show entries)/"
                 "C(show contents of file)/R(show rules)/"
                 "F(filter directory listings/"
                 "M(mark file(s))/Q(quit examine menu)")
         command = self.get_menu_entry(['D', 'U', 'E', 'F', 'C', 'R', 'M', 'Q'], 'E', text)
         if command == 'Q' or command == 'q':
             level = 'top'
     elif level == 'rule':
         text = ("S(show all rules of type)/D(show rules covering dir)/"
                 "C(show rules covering dir contents)/"
                 "A(add rule to rules store)/"
                 "R(remove rule from rules store/"
                 "E(export rules from store to file)/"
                 "I(import rules from file to store)/Q(quit rule menu)")
         command = self.get_menu_entry(['S', 'C', 'A', 'R', 'E', 'I', 'Q'], 'D', text)
         if command == 'Q' or command == 'q':
             level = 'top'
     else:
         command = None
     return command
コード例 #4
0
    def do_add_rule(self):
        # fixme need different completer here I think, that
        # completes relative to self.cwdir
        readline.set_completer(None)
        path = raw_input("path or wildcard expr in rule (empty to quit): ")
        path = path.strip()
        if path == '':
            return True
        default = Status.text_to_status('good')
        self.cmpl.set_choices_completion(Status.STATUSES + ['Q'], default)
        while True:
            statuses_text = Status.get_statuses_prompt(", ")
            status = raw_input(statuses_text + " Q(quit)) [%s]: " % default)
            status = status.strip()
            if status == "":
                status = default
            if status[0].upper() in Status.STATUSES:
                status = status[0].upper()
                break
            elif status == 'q' or status == 'Q':
                return None
            else:
                print "Unknown status type"
                continue

        # fixme should check that any wildcard is only one and only
        # in the last component... someday

        if path[0] != os.path.sep:
            path = os.path.join(self.cenv.cwdir, path)
        if path[-1] == os.path.sep:
            path = path[:-1]
            filetype = clouseau.retention.utils.ruleutils.text_to_entrytype(
                'dir')
        else:
            filetype = clouseau.retention.utils.ruleutils.text_to_entrytype(
                'file')

        clouseau.retention.utils.ruleutils.do_add_rule(self.cdb, path,
                                                       filetype, status,
                                                       self.cenv.host)
        # update the ignores list since we have a new rule
        results = clouseau.retention.utils.ignores.get_ignored_from_rulestore(
            self.cdb, [self.cenv.host])
        if self.cenv.host in results:
            self.ignored_from_rulestore[self.cenv.host] = results[
                self.cenv.host]
        return True
コード例 #5
0
ファイル: cli.py プロジェクト: wikimedia/operations-software
    def do_add_rule(self):
        # fixme need different completer here I think, that
        # completes relative to self.cwdir
        readline.set_completer(None)
        path = raw_input("path or wildcard expr in rule (empty to quit): ")
        path = path.strip()
        if path == '':
            return True
        default = Status.text_to_status('good')
        self.cmpl.set_choices_completion(Status.STATUSES + ['Q'], default)
        while True:
            statuses_text = Status.get_statuses_prompt(", ")
            status = raw_input(statuses_text + " Q(quit)) [%s]: " %
                               default)
            status = status.strip()
            if status == "":
                status = default
            if status[0].upper() in Status.STATUSES:
                status = status[0].upper()
                break
            elif status == 'q' or status == 'Q':
                return None
            else:
                print "Unknown status type"
                continue

        # fixme should check that any wildcard is only one and only
        # in the last component... someday

        if path[0] != os.path.sep:
            path = os.path.join(self.cenv.cwdir, path)
        if path[-1] == os.path.sep:
            path = path[:-1]
            filetype = clouseau.retention.utils.ruleutils.text_to_entrytype('dir')
        else:
            filetype = clouseau.retention.utils.ruleutils.text_to_entrytype('file')

        clouseau.retention.utils.ruleutils.do_add_rule(
            self.cdb, path, filetype, status, self.cenv.host)
        # update the ignores list since we have a new rule
        results = clouseau.retention.utils.ignores.get_ignored_from_rulestore(
            self.cdb, [self.cenv.host])
        if self.cenv.host in results:
            self.ignored_from_rulestore[self.cenv.host] = results[self.cenv.host]
        return True
コード例 #6
0
 def show_menu(self, level):
     if level == 'top':
         text = ("S(set status)/E(examine directory)/"
                 "Filter directory listings/"
                 "I(ignore)/R(manage rules)/Q(quit menu)")
         command = self.get_menu_entry(['S', 'E', 'I', 'F', 'R', 'Q'], 'S',
                                       text)
     elif level == 'status':
         text = Status.get_statuses_prompt(", ") + ", Q(quit status menu)"
         command = self.get_menu_entry(Status.STATUSES + ['Q'], text,
                                       Status.text_to_status('good'))
         if command == 'Q' or command == 'q':
             level = 'top'
     elif level == 'examine':
         text = ("D(down a level)/U(up a level)/E(show entries)/"
                 "C(show contents of file)/R(show rules)/"
                 "F(filter directory listings/"
                 "M(mark file(s))/Q(quit examine menu)")
         command = self.get_menu_entry(
             ['D', 'U', 'E', 'F', 'C', 'R', 'M', 'Q'], 'E', text)
         if command == 'Q' or command == 'q':
             level = 'top'
     elif level == 'rule':
         text = ("S(show all rules of type)/D(show rules covering dir)/"
                 "C(show rules covering dir contents)/"
                 "A(add rule to rules store)/"
                 "R(remove rule from rules store/"
                 "E(export rules from store to file)/"
                 "I(import rules from file to store)/Q(quit rule menu)")
         command = self.get_menu_entry(['S', 'C', 'A', 'R', 'E', 'I', 'Q'],
                                       'D', text)
         if command == 'Q' or command == 'q':
             level = 'top'
     else:
         command = None
     return command