Esempio n. 1
0
File: grid.py Progetto: Solvi/pyhrf
    def next(self):
        rule = self._rule_stack[-1]
        val = self._tasks[rule]
        if isinstance(val, TaskHierarchical): val = [], []
        deps, tasks = val

        if self._deps_stack[-1] == 0 and deps != []:
            if not self._find_leaf(): return self._pop_subhie()
            deps, tasks = self._tasks[rule]

        # if at the end of deps :
        if self._deps_stack[-1] >= len(deps):
            # no task or task done -> go up
            if tasks == [] or self._deps_stack[-1] > len(deps):
                self._go_up_for_next_leaf()
                if self._rule_stack == []: return None
                rule = self._rule_stack[-1]
                deps, tasks = self._tasks[rule]
                if self._deps_stack[-1] < len(deps):
                    if not self._find_leaf():
                        return self._pop_subhie()

                elif tasks != []:
                    msg.write_list(['  ' * \
                        len(self._rule_stack), '<- ',
                        ('%s' % rule, 'blue'), '\n'])
                rule = self._rule_stack[-1]
                deps, tasks = self._tasks[rule]
        self._deps_stack[-1] += 1
        return TaskList(list(tasks))
Esempio n. 2
0
    def next(self):
        rule = self._rule_stack[-1]
        val = self._tasks[rule]
        if isinstance(val, TaskHierarchical): val = [], []
        deps, tasks = val

        if self._deps_stack[-1] == 0 and deps != []:
            if not self._find_leaf(): return self._pop_subhie()
            deps, tasks = self._tasks[rule]

        # if at the end of deps :
        if self._deps_stack[-1] >= len(deps):
            # no task or task done -> go up
            if tasks == [] or self._deps_stack[-1] > len(deps):
                self._go_up_for_next_leaf()
                if self._rule_stack == []: return None
                rule = self._rule_stack[-1]
                deps, tasks = self._tasks[rule]
                if self._deps_stack[-1] < len(deps):
                    if not self._find_leaf():
                        return self._pop_subhie()

                elif tasks != []:
                    msg.write_list(['  ' * \
                        len(self._rule_stack), '<- ',
                        ('%s' % rule, 'blue'), '\n'])
                rule = self._rule_stack[-1]
                deps, tasks = self._tasks[rule]
        self._deps_stack[-1] += 1
        return TaskList(list(tasks))
Esempio n. 3
0
File: grid.py Progetto: Solvi/pyhrf
 def _find_leaf(self):
     if len(self._rule_stack) == 0: return True
     rule = self._rule_stack[-1]
     deps, tasks = self._tasks[rule]
     if deps:
         subrule = deps[self._deps_stack[-1]]
         val = self._tasks[subrule]
         self._rule_stack.append(subrule)
         self._deps_stack.append(0)
         if isinstance(val, TaskHierarchical):
             return False
         else: subdeps, subtasks = val
         msg.write_list(['  ' * len(self._rule_stack), '- ',
             ('%s' % subrule, 'blue'),
             ' : %s\n' % ', '.join(subdeps)])
         return self._find_leaf()
     else:    return True
Esempio n. 4
0
def parse_options(parser):
    morehelpmap = {
        'hosts': hosts_help,
        'tasks': tasks_help,
        'mode': mode_help,
        'broken': broken_help,
        'log': log_help,
        'timeslot': timeslot_help
    }
    (options, args) = parser.parse_args(sys.argv)
    error = False
    error_msg = []

    if options.morehelp != None:
        try:
            morehelpmap[options.morehelp](sys.argv[0])
            sys.exit(1)
        except KeyError:
            msg.error("No help for '%s'.\n" % options.morehelp)
            msg.write_list(
                [' ', ('*', 'green'), ' List of available full helps :\n   '])
            for k in morehelpmap.keys():
                msg.write('%s, ' % k)
            msg.write('\n')
            sys.exit(1)
    mandatory_options = {'hosts': options.hosts}
    timeslot = read_timeslot(options.timeslot)
    if None in mandatory_options.values():
        opt = [n for n, o in mandatory_options.items() if o == None]
        error_msg.append('missing options : %s' % opt)
        error = True
    if not options.mode in ["dispatch", "repeat", "hie", "hierarchical"]:
        error_msg.append("'%s' : unknown task manager mode." % \
                            options.mode)
        error = True
    if error:
        parser.print_help()
        for m in error_msg:
            msg.error(m)
        sys.exit(1)
    hosts_list = read_hosts(options.hosts)
    if options.tasks:
        tasks_list = read_tasks(options.tasks, options.mode)
    else:
        tasks_list = None
    return options, timeslot, hosts_list, tasks_list
Esempio n. 5
0
File: grid.py Progetto: Solvi/pyhrf
 def update_all_hosts(self):
     self._init_lists()
     self._hosts_probed_number = 0
     for h in self._list:
         ph = ProbeHost(self, h)
         ph.start()
     while 1:
         if self._hosts_probed_number == len(self._list): break
         time.sleep(0.01)
     hosts_lists = {
         'available hosts' :     self._available_list,
         'unavailable hosts' : self._not_available_list,
         'unknown hosts' :       self._unknown_list,
         'unknown status' :      self._unknown_status_list}
     for name, list in hosts_lists.items():
         if len(list) == 0: continue
         msg.write_list([(' * ', 'bold_yellow'), '%s : %s' % \
                         (name, ' ' * (20 - len(name))),
                         ('%d' % len(list), 'cyan'), " ",
                         str(list), '\n'])
Esempio n. 6
0
File: grid.py Progetto: Solvi/pyhrf
 def start(self):
     self._tasks.init()
     while 1:
         tasks = self._tasks.next()
         if tasks is None: break
         if isinstance(tasks, TaskHierarchical):
             rule = tasks.rule
             msg.write_list(['--> ', ('file', 'green'),
                 (" : '%s'\n" % rule)])
             htm = HierarchicalTasksManager(self._timeslot,
                 self._user, tasks, self._hosts_manager,
                 self._log, self._brokenfd)
             htm.start()
             msg.write_list(['<-- ', ('file', 'green'),
                 (" : '%s'\n" % rule)])
         else:
             dtm = DispatchedTasksManager(self._timeslot,
                 self._user, tasks, self._hosts_manager,
                 self._log, self._brokenfd)
             dtm.start()
Esempio n. 7
0
 def _find_leaf(self):
     if len(self._rule_stack) == 0: return True
     rule = self._rule_stack[-1]
     deps, tasks = self._tasks[rule]
     if deps:
         subrule = deps[self._deps_stack[-1]]
         val = self._tasks[subrule]
         self._rule_stack.append(subrule)
         self._deps_stack.append(0)
         if isinstance(val, TaskHierarchical):
             return False
         else:
             subdeps, subtasks = val
         msg.write_list([
             '  ' * len(self._rule_stack), '- ', ('%s' % subrule, 'blue'),
             ' : %s\n' % ', '.join(subdeps)
         ])
         return self._find_leaf()
     else:
         return True
Esempio n. 8
0
 def start(self):
     self._tasks.init()
     while 1:
         tasks = self._tasks.next()
         if tasks is None: break
         if isinstance(tasks, TaskHierarchical):
             rule = tasks.rule
             msg.write_list(
                 ['--> ', ('file', 'green'), (" : '%s'\n" % rule)])
             htm = HierarchicalTasksManager(self._timeslot, self._user,
                                            tasks, self._hosts_manager,
                                            self._log, self._brokenfd)
             htm.start()
             msg.write_list(
                 ['<-- ', ('file', 'green'), (" : '%s'\n" % rule)])
         else:
             dtm = DispatchedTasksManager(self._timeslot, self._user, tasks,
                                          self._hosts_manager, self._log,
                                          self._brokenfd)
             dtm.start()
Esempio n. 9
0
 def update_all_hosts(self):
     self._init_lists()
     self._hosts_probed_number = 0
     for h in self._list:
         ph = ProbeHost(self, h)
         ph.start()
     while 1:
         if self._hosts_probed_number == len(self._list): break
         time.sleep(0.01)
     hosts_lists = {
         'available hosts': self._available_list,
         'unavailable hosts': self._not_available_list,
         'unknown hosts': self._unknown_list,
         'unknown status': self._unknown_status_list
     }
     for name, list in hosts_lists.items():
         if len(list) == 0: continue
         msg.write_list([(' * ', 'bold_yellow'), '%s : %s' % \
                         (name, ' ' * (20 - len(name))),
                         ('%d' % len(list), 'cyan'), " ",
                         str(list), '\n'])
Esempio n. 10
0
File: grid.py Progetto: Solvi/pyhrf
def parse_options(parser):
    morehelpmap = {'hosts' : hosts_help, 'tasks' : tasks_help,
        'mode' : mode_help, 'broken' : broken_help, 'log' : log_help,
        'timeslot' : timeslot_help}
    (options, args) = parser.parse_args(sys.argv)
    error = False
    error_msg = []

    if options.morehelp != None:
        try:
            morehelpmap[options.morehelp](sys.argv[0])
            sys.exit(1)
        except KeyError:
            msg.error("No help for '%s'.\n" % options.morehelp)
            msg.write_list([' ', ('*', 'green'),
                ' List of available full helps :\n   '])
            for k in morehelpmap.keys(): msg.write('%s, ' % k)
            msg.write('\n')
            sys.exit(1)
    mandatory_options = {'hosts' : options.hosts}
    timeslot = read_timeslot(options.timeslot)
    if None in mandatory_options.values():
        opt = [n for n, o in mandatory_options.items() if o == None]
        error_msg.append('missing options : %s' % opt)
        error = True
    if not options.mode in ["dispatch", "repeat", "hie", "hierarchical"]:
        error_msg.append("'%s' : unknown task manager mode." % \
                            options.mode)
        error = True
    if error:
        parser.print_help()
        for m in error_msg: msg.error(m)
        sys.exit(1)
    hosts_list = read_hosts(options.hosts)
    if options.tasks:
        tasks_list = read_tasks(options.tasks, options.mode)
    else:    tasks_list = None
    return options, timeslot, hosts_list, tasks_list
Esempio n. 11
0
File: grid.py Progetto: Solvi/pyhrf
 def print_status(self, n, size):
     msg.write_list(['\r ', ('%d' % n, 'red'),
             '/', ('%d' % size, 'red')])
     if n == size: msg.write('\n')
     sys.stdout.flush()
Esempio n. 12
0
File: grid.py Progetto: Solvi/pyhrf
 def init(self):
     self._deps_stack = [0]
     self._rule_stack = ['all']
     msg.write_list(['- ', ('all', 'blue'), ' : %s\n' % \
             ', '.join(self._tasks['all'][0])])
Esempio n. 13
0
 def init(self):
     self._deps_stack = [0]
     self._rule_stack = ['all']
     msg.write_list(['- ', ('all', 'blue'), ' : %s\n' % \
             ', '.join(self._tasks['all'][0])])
Esempio n. 14
0
 def print_status(self, n, size):
     msg.write_list(['\r ', ('%d' % n, 'red'), '/', ('%d' % size, 'red')])
     if n == size: msg.write('\n')
     sys.stdout.flush()