Example #1
0
 def transform(self, template):
     # apply overrides on the pivot location from the template
     if 'override' in template:
         for k,v in template['override'].iteritems():
             self.location[k] = v
             
     # apply track rules from the template
     if 'track' in template:
         for rule in template['track']:
             for branch in rule['branch']:
                 taken = False
                 for stream in self.resource.stream:
                     if stream.match(branch):
                         taken = True
                         s = Ontology.clone(stream)
                         s['resource path digest'] = self.resource.location['path digest']
                         if 'override' in rule:
                             for k,v in rule['override'].iteritems(): s[k] = v
                         self.stream.append(s)
                         
                         if rule['mode'] == 'choose':
                             break
                             
                 if taken and rule['mode'] == 'choose':
                     break
                     
     return self.taken
Example #2
0
 def _transcode_ac3(self, task):
     product = task.produce(task.ontology)
     if product:
         taken = False
         
         for pivot in task.transform.pivot.values():
             for stream in pivot.stream:
                 if not taken and stream['stream kind'] == 'audio':
                     taken = True
                     
                     # Clone the hint ontology
                     product.hint = Ontology.clone(self.hint)
                     
                     command = self.env.initialize_command('ffmpeg', self.log)
                     if command:
                         # make ffmpeg not check for overwrite, we already do this check
                         command.append(u'-y')
                         
                         # set the number of processing threads
                         command.append(u'-threads')
                         command.append(unicode(self.env.system['threads']))
                         
                         # set the input file
                         command.append(u'-i')
                         command.append(self.path)
                         
                         for k,v in stream['ffmpeg parameters'].iteritems():
                             command.append(k)
                             if v is not None: command.append(unicode(v))
                             
             if taken: break
         if taken and self.env.check_path_available(product.path, task.ontology['overwrite']):
             command.append(product.path)
             message = u'Transcode {} --> {}'.format(self.path, product.path)
             self.env.execute(command, message, task.ontology['debug'], pipeout=True, pipeerr=False, log=self.log)
Example #3
0
 def produce(self, override=None):
     # copy the location ontology
     p = Ontology.clone(self.location)
     
     # allow the location to recalculate those concepts 
     del p['volume path']
     del p['file name']
     del p['directory']
     
     # explicitly set the volume and host from the task
     p['host'] = self.env.host
     p['volume'] = self.ontology['volume']
     
     # for copy and move we try to set a profile from the source
     if self.ontology['action'] in set(('copy', 'move', 'pack')):
         if self.resource.meta['profile']:
             p['profile'] = self.resource.meta['profile']
             
     # for transcode we try to set the profile from the transform
     elif self.ontology['action'] == 'transcode':
         for pivot in self.transform.pivot.values():
             if 'profile' in pivot.location:
                 p['profile'] = pivot.location['profile']
                 
     # whatever happened, if a profile has been explicitly provided by the task
     # it will override anything we set implicitly
     if self.ontology['profile']:
         p['profile'] = self.ontology['profile']
         
     # if an override was given set some concepts from it 
     if override:
         for i in set((
             'kind', 
             'language',
             'stream order',
             'resource path digest',
             'routing type'
         )):
             if i in override: p[i] = override[i]
             
     # try to produce a product
     product = self.resource.asset.locate_resource(p)
     if product:
         self.product.append(product)
     else:
         self.log.error(u'Could not determine destination path from:\n%s', self.env.encode_json(p))
         
     return product
Example #4
0
 def __init__(self, resource):
     self.resource = resource
     self.location = Ontology.clone(resource.location)
     self.stream = []