コード例 #1
0
ファイル: embed_xmp.py プロジェクト: ncorona/notredam
 def __init__(self, deferred, workspace, item_id, variant_name):
     self.deferred = deferred
     self.workspace = workspace
     self.proxy = Proxy('XMPEmbedder')
     self.item = Item.objects.get(pk=item_id)
     self.item, self.component = get_source_rendition(
         item_id, variant_name, workspace)
コード例 #2
0
ファイル: adapter.py プロジェクト: ncorona/notredam
        self.item.update_time = time.time()
        self.item.save()

        self.deferred.callback(self.out_file)

    def handle_error(self, result):
        self.deferred.errback(Failure(Exception(result.getErrorMessage())))

    def execute(self, output_variant_name, output_type, **params):
        # get basic data (avoid creating stuff in DB)
        try:
            self.get_cmdline(output_variant_name, output_type, **params)
            output_variant = Variant.objects.get(name=output_variant_name)
            self.out_comp = self.item.create_variant(output_variant,
                                                     self.workspace,
                                                     self.out_type)
            self.out_comp.source = self.source
            args = splitstring(self.cmdline)
        except Exception, e:
            log.error('Error in %s: %s %s' %
                      (self.__class__.__name__, type(e), str(e)))
            self.deferred.errback(e)
        else:
            if self.fake:
                log.debug('######### Command line:\n%s' % str(args))
            else:
                proxy = Proxy(self.md_server)
                d = proxy.call(self.remote_exe, args, self.env)
                d.addCallbacks(self.handle_result, self.handle_error)
        return self.deferred  # if executed stand alone
コード例 #3
0
ファイル: pinger.py プロジェクト: ncorona/notredam
def run(workspace, target):
    deferred = defer.Deferred()
    ping_method = Proxy('Adapter').ping
    pinger = Pinger(deferred, ping_method)
    reactor.callLater(0, pinger.execute)
    return deferred
コード例 #4
0
ファイル: analyzer.py プロジェクト: mlclemente/notredam
    def handle_result(self, result, *args):
        #log.debug('= handle_result %s' % str(result)[:128])
        try:
            return_value = self.parse_stdout(result['data'], *args)
            self.deferred.callback(return_value)
        except Exception, e:
            log.error('Error in %s: %s %s' % (self.__class__.__name__, type(e), str(e)))
            self.deferred.errback(e)
        
    def handle_error(self, result):
        self.deferred.errback(Failure(Exception(result.getErrorMessage())))

    def execute(self, **params):     
        # get basic data (avoid creating stuff in DB)
        try:
            self.get_cmdline(**params)
            args = splitstring(self.cmdline)
        except Exception, e:
            log.error('Error in %s: %s %s' % (self.__class__.__name__, type(e), str(e)))
            self.deferred.errback(e)
        else:
            if self.fake:
                log.debug('######### Command line:\n%s' % str(args))
            else:
                proxy = Proxy(self.md_server)
                d = proxy.call(self.remote_exe, args, self.env)
                d.addCallbacks(self.handle_result, self.handle_error, callbackArgs=self.cb_args)
        return self.deferred    # if executed stand alone

コード例 #5
0
ファイル: embed_xmp.py プロジェクト: mlclemente/notredam
 def __init__(self, deferred, workspace, item_id, variant_name):
     self.deferred = deferred
     self.workspace = workspace
     self.proxy = Proxy('XMPEmbedder') 
     self.item = Item.objects.get(pk = item_id)
     self.item, self.component = get_source_rendition(item_id, variant_name, workspace)
コード例 #6
0
ファイル: embed_xmp.py プロジェクト: mlclemente/notredam
class EmbedXMP:
    def __init__(self, deferred, workspace, item_id, variant_name):
        self.deferred = deferred
        self.workspace = workspace
        self.proxy = Proxy('XMPEmbedder') 
        self.item = Item.objects.get(pk = item_id)
        self.item, self.component = get_source_rendition(item_id, variant_name, workspace)


    def _reset_modified_flag(self):
        """
        Reset flags modified in Component and in its metadata
        """
        comp_metadata = self.component.metadata.filter(modified = True)
        for m in comp_metadata:
            m.modified = False
            m.save()
        self.component.modified_metadata = False
        self.component.save()

    def _populate(self, dictionary, metadata, structures):
        for im in metadata:
            if im.schema.namespace.uri not in dictionary:
                dictionary[im.schema.namespace.uri] = {'prefix': im.schema.namespace.prefix, 'fields': {}}
            if im.schema.field_name not in dictionary[im.schema.namespace.uri]['fields']:
                if im.schema.type == 'lang':
                    dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name] = {'type':im.schema.type,'is_array':im.schema.is_array,'value':[im.value],'qualifier':[im.language], 'xpath':[]}
                elif im.schema.type in structures:
                    dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name] = {'type':im.schema.type,'is_array':im.schema.is_array,'value':[im.value],'qualifier':[],'xpath':[im.xpath]}
                else:
                    dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name] = {'type':im.schema.type,'is_array':im.schema.is_array,'value':[im.value],'qualifier':[],'xpath':[]}
            else:
                dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name]['value'].append(im.value)
                if im.schema.type == 'lang':
                    dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name]['qualifier'].append(im.language)
                elif im.schema.type in structures:
                    dictionary[im.schema.namespace.uri]['fields'][im.schema.field_name]['xpath'].append(im.xpath)
        return dictionary

    def _synchronize_metadata(self):
        changes = {}
        structures = [s.name for s in XMPStructure.objects.all()]
        metadata = self.item.metadata.filter(modified = True)
        self._populate(changes, metadata, structures)

        metadata = self.component.metadata.filter(modified = True)
        self._populate(changes, metadata, structures)
        return changes

    def _cb_embed_reset_xmp(self, result):
        if result:
            self._reset_modified_flag()
        self.deferred.callback(result)
        return result

    def _cb_error(self, failure):
        self.deferred.errback(failure)
        return failure

    def execute(self):
        metadata_dict = self._synchronize_metadata()
        d = self.proxy.metadata_synch(self.component.uri, metadata_dict)
        d.addCallbacks(self._cb_embed_reset_xmp, self._cb_error)
        return d
コード例 #7
0
ファイル: embed_xmp.py プロジェクト: ncorona/notredam
class EmbedXMP:
    def __init__(self, deferred, workspace, item_id, variant_name):
        self.deferred = deferred
        self.workspace = workspace
        self.proxy = Proxy('XMPEmbedder')
        self.item = Item.objects.get(pk=item_id)
        self.item, self.component = get_source_rendition(
            item_id, variant_name, workspace)

    def _reset_modified_flag(self):
        """
        Reset flags modified in Component and in its metadata
        """
        comp_metadata = self.component.metadata.filter(modified=True)
        for m in comp_metadata:
            m.modified = False
            m.save()
        self.component.modified_metadata = False
        self.component.save()

    def _populate(self, dictionary, metadata, structures):
        for im in metadata:
            if im.schema.namespace.uri not in dictionary:
                dictionary[im.schema.namespace.uri] = {
                    'prefix': im.schema.namespace.prefix,
                    'fields': {}
                }
            if im.schema.field_name not in dictionary[
                    im.schema.namespace.uri]['fields']:
                if im.schema.type == 'lang':
                    dictionary[im.schema.namespace.uri]['fields'][
                        im.schema.field_name] = {
                            'type': im.schema.type,
                            'is_array': im.schema.is_array,
                            'value': [im.value],
                            'qualifier': [im.language],
                            'xpath': []
                        }
                elif im.schema.type in structures:
                    dictionary[im.schema.namespace.uri]['fields'][
                        im.schema.field_name] = {
                            'type': im.schema.type,
                            'is_array': im.schema.is_array,
                            'value': [im.value],
                            'qualifier': [],
                            'xpath': [im.xpath]
                        }
                else:
                    dictionary[im.schema.namespace.uri]['fields'][
                        im.schema.field_name] = {
                            'type': im.schema.type,
                            'is_array': im.schema.is_array,
                            'value': [im.value],
                            'qualifier': [],
                            'xpath': []
                        }
            else:
                dictionary[im.schema.namespace.uri]['fields'][
                    im.schema.field_name]['value'].append(im.value)
                if im.schema.type == 'lang':
                    dictionary[im.schema.namespace.uri]['fields'][
                        im.schema.field_name]['qualifier'].append(im.language)
                elif im.schema.type in structures:
                    dictionary[im.schema.namespace.uri]['fields'][
                        im.schema.field_name]['xpath'].append(im.xpath)
        return dictionary

    def _synchronize_metadata(self):
        changes = {}
        structures = [s.name for s in XMPStructure.objects.all()]
        metadata = self.item.metadata.filter(modified=True)
        self._populate(changes, metadata, structures)

        metadata = self.component.metadata.filter(modified=True)
        self._populate(changes, metadata, structures)
        return changes

    def _cb_embed_reset_xmp(self, result):
        if result:
            self._reset_modified_flag()
        self.deferred.callback(result)
        return result

    def _cb_error(self, failure):
        self.deferred.errback(failure)
        return failure

    def execute(self):
        metadata_dict = self._synchronize_metadata()
        d = self.proxy.metadata_synch(self.component.uri, metadata_dict)
        d.addCallbacks(self._cb_embed_reset_xmp, self._cb_error)
        return d