Beispiel #1
0
 def tag(self, task):
     update = Ontology(self.env, 'ns.medium.resource.meta.tag')
     meta = self.meta.project('ns.medium.resource.meta.tag')
     knowledge = Ontology(self.env, 'ns.medium.resource.meta.tag', self.knowledge['body'])
     genealogy = Ontology(self.env, 'ns.service.genealogy', self.knowledge['head']['genealogy'])
     knowledge.merge_all(genealogy)
     
     # Everything that is in meta but doesn't fit knowledge
     # should be replaced with the value in knowledge 
     for i in meta.keys():
         if meta[i] != knowledge[i]:
             update[i] = knowledge[i]
             
     # Everything that is in knowledge but not in meta
     # should be set to the value in knowledge 
     for i in knowledge.keys():
         if i not in meta:
             update[i] = knowledge[i]
             
     modify = []
     for k,v in update.iteritems():
         prototype = update.namespace.find(k)
         if prototype and prototype.node['subler']:
             modify.append(u'{{{}:{}}}'.format(prototype.node['subler'],v))
             
     print unicode(modify).encode('utf-8')
Beispiel #2
0
 def decode_resource_path(self, path):
     result = None
     if path:
         decoded = Ontology(self.env, 'ns.medium.resource.url.decode')
         decoded['directory'], decoded['file name'] = os.path.split(path)
         if 'file name' in decoded and 'directory' in decoded:
             
             # Normalize the directory
             # This will replace path framents with canonic values
             decoded['directory'] = self.normalize(decoded['directory'])
             
             # Check if the directory resides in a volume
             for volume in self.volume.element.values():
                 if os.path.commonprefix((volume.node['real'], decoded['directory'])) == volume.node['real']:
                     decoded['volume'] = volume.key
                     
             # If a UMID was encoded in the name, infer the home id and media kind
             # This will also trigger rule.medium.resource.filename.parse
             if 'umid' in decoded:
                 umid = Umid.decode(decoded['umid'])
                 if umid:
                     decoded['media kind'] = umid.media_kind
                     decoded['home id'] = umid.home_id
                     
             # Make the elements of the decoded onlology kernel elements of the result
             result = decoded.project('ns.medium.resource.location')
             for k,v in decoded.iteritems(): result[k] = v
             
             # set the host and domain
             result['host'] = self.host
             result['domain'] = self.domain
     return result