Пример #1
0
 def _cb_remove(self, node, user_data):
     "lo stato non e' ready di sicuro del nodo"
     log.info('target %s: cancelling %s on failed %s' % (self.target, node.name, user_data['failed_action']))
     if node.name in self.actions:
         del self.actions[node.name]
         if node.name != user_data['failed_action']:
             user_data['deleted'].append(node.name)
Пример #2
0
 def stop(self, seconds_offset=0):
     log.info('stopping process %s' % self.process.pk)
     when = datetime.datetime.now() + datetime.timedelta(seconds=seconds_offset)
     self.process.end_date = when
     self.process.save()
     self.gameover = True
     self.deferred.callback(None)
Пример #3
0
 def stop(self, seconds_offset=0):
     log.info('stopping process %s' % self.process.pk)
     when = datetime.datetime.now() + datetime.timedelta(
         seconds=seconds_offset)
     self.process.end_date = when
     self.process.save()
     self.gameover = True
Пример #4
0
 def run(self, seconds_offset=0):
     log.info('starting process %s' % self.process.pk)
     when = datetime.datetime.now() + datetime.timedelta(
         seconds=seconds_offset)
     self.process.start_date = when
     self.process.save()
     return defer.Deferred()  # never used
Пример #5
0
 def _cb_remove(self, node, user_data):
     "lo stato non e' ready di sicuro del nodo"
     log.info('target %s: cancelling %s on failed %s' %
              (self.target, node.name, user_data['failed_action']))
     if node.name in self.actions:
         del self.actions[node.name]
         if node.name != user_data['failed_action']:
             user_data['deleted'].append(node.name)
Пример #6
0
 def action_to_run(self):
     """Return the first action ready to run.
        If all actions are done, failed, or cancelled, returns None
        If no action is ready to run returns ''
     """
     #log.debug("action_to_run item=%s, actions=%s ready=%s" % (self.target, len(self.actions), len(self.ready))) #d
     if not self.actions:
         #log.debug('action_to_run: no actions') #d
         return None
     if not self.ready:
         #log.debug('action_to_run: nothing ready') #d
         return ''
     else:
         r = min(self.ready)
         action = self.action_list[r]
         log.info('### target %s: run %s' % (self.target, action))
         self.ready.remove(r)
         self.dag.visit(action, self._cb_set_to_wait, action)
         #self.show() #d
         return action
Пример #7
0
 def action_to_run(self):
     """Return the first action ready to run.
        If all actions are done, failed, or cancelled, returns None
        If no action is ready to run returns ''
     """
     #log.debug("action_to_run item=%s, actions=%s ready=%s" % (self.target, len(self.actions), len(self.ready))) #d 
     if not self.actions:
         #log.debug('action_to_run: no actions') #d
         return None
     if not self.ready:
         #log.debug('action_to_run: nothing ready') #d
         return ''
     else:
         r = min(self.ready)
         action = self.action_list[r]
         log.info('### target %s: run %s' % (self.target, action))
         self.ready.remove(r)
         self.dag.visit(action, self._cb_set_to_wait, action)
         #self.show() #d
         return action
Пример #8
0
 def _get_scripts(self, pipeline):
     """Load scripts from plugin directory. 
     
        Returns the dictionary
        {'script_name': (callable, params)}
        Throws an exception if not all scripts can be loaded.
     """
     plugins_module = self.cfg.get("MPROCESSOR", "plugins")
     scripts = {}
     for script_key, script_dict in pipeline.items():
         script_name = script_dict['script_name']
         full_name = plugins_module + '.' + script_name + '.run'
         p = full_name.split('.')
         log.info('<$> loading script: %s' % '.'.join(p[:-1]))
         m = __import__('.'.join(p[:-1]), fromlist = p[:-1])
         f = getattr(m, p[-1], None)
         if not f or not callable(f):
             raise BatchError('Plugin %s has no callable run method' % script_name)
         else:
             scripts[script_key] = (f, script_dict.get('params', {}))
     return scripts
Пример #9
0
    def execute(self,
                workspace,       # workspace object
                item_id,         # item pk
                source_variant,  # name of the variant
                output_variant,  # name of the variat
                output_preset,   # a mime type or a Mediadart PRESET
                **preset_params  # additional parameters (see adapter server for explanation)
                ):

        log.info('%s.execute' % self)
        log.info('output_preset %s'%output_preset)
        log.info('self.presets %s'%self.presets)
        if output_preset not in self.presets:
            raise  Exception('%s: unsupported output_preset' % (self, output_preset))

        try:
            output_type = Type.objects.get_or_create_by_mime(self.presets[output_preset])
            item, source = get_source_rendition(item_id, source_variant, workspace)
            output_variant_obj = Variant.objects.get(name = output_variant)
            output_component = item.create_variant(output_variant_obj, workspace, output_type)
            output_component.source = source
            output_file = get_storage_file_name(item.ID, workspace.pk, output_variant_obj.name, output_type.ext)
        except Exception, e:
            self.deferred.errback(Failure(e))
            return
Пример #10
0
    def execute(
        self,
        workspace,  # workspace object
        item_id,  # item pk
        source_variant,  # name of the variant
        output_variant,  # name of the variat
        output_preset,  # a mime type or a Mediadart PRESET
        **preset_params  # additional parameters (see adapter server for explanation)
    ):

        log.info("%s.execute" % self)
        log.info("output_preset %s" % output_preset)
        log.info("self.presets %s" % self.presets)
        if output_preset not in self.presets:
            raise Exception("%s: unsupported output_preset" % (self, output_preset))

        try:
            output_type = Type.objects.get_or_create_by_mime(self.presets[output_preset])
            item, source = get_source_rendition(item_id, source_variant, workspace)
            output_variant_obj = Variant.objects.get(name=output_variant)
            output_component = item.create_variant(output_variant_obj, workspace, output_type)
            output_component.source = source
            output_file = get_storage_file_name(item.ID, workspace.pk, output_variant_obj.name, output_type.ext)
        except Exception, e:
            self.deferred.errback(Failure(e))
            return
Пример #11
0
 def _get_scripts(self, pipeline):
     """Load scripts from plugin directory. 
     
        Returns the dictionary
        {'script_name': (callable, params)}
        Throws an exception if not all scripts can be loaded.
     """
     plugins_module = self.cfg.get("MPROCESSOR", "plugins")
     scripts = {}
     for script_key, script_dict in pipeline.items():
         script_name = script_dict['script_name']
         full_name = plugins_module + '.' + script_name + '.run'
         p = full_name.split('.')
         log.info('<$> loading script: %s' % '.'.join(p[:-1]))
         m = __import__('.'.join(p[:-1]), fromlist=p[:-1])
         f = getattr(m, p[-1], None)
         if not f or not callable(f):
             raise BatchError('Plugin %s has no callable run method' %
                              script_name)
         else:
             scripts[script_key] = (f, script_dict.get('params', {}))
     return scripts
Пример #12
0
 def wake_process(self, restarting):
     running_processes = Process.objects.filter(Q(end_date=None) & ~Q(start_date=None))
     log.info("Running processes: %d" % len(running_processes))
     if running_processes:
         if restarting:
             log.info("Restarting process %s" % (running_processes[0].pk))
             return running_processes[0]    # rerun a running process, some actions
                                            # will be repeated
         else:
             log.info("Process %s already running, doing nothing" % (running_processes[0].pk))
             return None                    # a process is already running, do nothing
     else:
         waiting_processes = Process.objects.filter(start_date=None)
         log.info("Number of waiting processes: %d" % len(waiting_processes))
         if waiting_processes:
             log.info("running the waiting process %s" % (waiting_processes[0].pk))
             return waiting_processes[0]
         else:
             log.info("No waiting process: doing nothing")
             return None
Пример #13
0
 def run(self, seconds_offset = 0):
     log.info('starting process %s' % self.process.pk)
     when = datetime.datetime.now() + datetime.timedelta(seconds=seconds_offset)
     self.process.start_date = when
     self.process.save()
     return defer.Deferred()   # never used
Пример #14
0
 def wake_process(self, restarting):
     running_processes = Process.objects.filter(
         Q(end_date=None) & ~Q(start_date=None))
     log.info("Running processes: %d" % len(running_processes))
     if running_processes:
         if restarting:
             log.info("Restarting process %s" % (running_processes[0].pk))
             return running_processes[
                 0]  # rerun a running process, some actions
             # will be repeated
         else:
             log.info("Process %s already running, doing nothing" %
                      (running_processes[0].pk))
             return None  # a process is already running, do nothing
     else:
         waiting_processes = Process.objects.filter(start_date=None)
         log.info("Number of waiting processes: %d" %
                  len(waiting_processes))
         if waiting_processes:
             log.info("running the waiting process %s" %
                      (waiting_processes[0].pk))
             return waiting_processes[0]
         else:
             log.info("No waiting process: doing nothing")
             return None