Esempio n. 1
0
import zope.interface
import zope.component

from pmr2.app.factory import named_factory
from pmr2.app.annotation.interfaces import *
from pmr2.app.annotation.annotator import ExposureFileAnnotatorBase

from pmr2.annotation.shjs.interfaces import ISourceTextNote


class SourceTextAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator, 
                              IExposureFileEditAnnotator)
    title = u'Source Viewer'
    label = u'Source View'
    for_interface = ISourceTextNote

    def generate(self):
        return ()

SourceTextAnnotatorFactory = named_factory(SourceTextAnnotator)
Esempio n. 2
0
from pmr2.app.exposure.interfaces import IExposureSourceAdapter

from pmr2.virtuoso.interfaces import IVirtuosoNote
from pmr2.virtuoso.interfaces import IExposureFileAnnotatorRDFIndexer


class VirtuosoAnnotator(ExposureFileAnnotatorBase):
    """
    Mark this file as one containing RDF that is to be exported to
    Virtuoso.
    """

    zope.interface.implements(IExposureFileAnnotator,
                              IExposureFilePostEditAnnotator)
    title = u'Export Semantic Metadata to Virtuoso'
    label = u'Semantic Metadata'
    description = u''
    for_interface = IVirtuosoNote
    edited_names = ('exclude_nav',)

    def generate(self):
        idx = zope.component.getAdapter(self, IExposureFileAnnotatorRDFIndexer)
        idx()
        if not self.data:
            return {}
        d = dict(self.data)
        self.context.setExcludeFromNav(d.get('exclude_nav'))
        return self.data

VirtuosoAnnotatorFactory = named_factory(VirtuosoAnnotator)
Esempio n. 3
0
from pmr2.app.factory import named_factory
from pmr2.app.annotation import note_factory
from pmr2.app.annotation.interfaces import *
from pmr2.app.annotation.annotator import ExposureFileAnnotatorBase

from cellml.pmr2.note import CellMLCodegenNote


class DummyCodegenAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    title = u'Dummy Code'
    description = u'A dummy code generator'
    
    def generate(self):
        return (
            ('code', {
                'C': 'printf("this is a test\\n");',
                'Python': 'print "this is a test"',
            }),
        )

DummyCodegenAnnotatorFactory = named_factory(DummyCodegenAnnotator)
DummyCodegenNoteFactory = note_factory(CellMLCodegenNote, 'dummy_code')
Esempio n. 4
0
class HTMLDocViewGen(PortalTransformDocViewGenBase):
    zope.interface.implements(IDocViewGen)
    transform = 'safe_html'
    title = u'HTML annotator'
    description = u'This converts raw HTML files into a format suitable for ' \
                   'a Plone site.'

    def generateTitle(self):
        try:
            tree = HTMLTreeBuilder.parse(StringIO(self.input), encoding='utf8')
            result = tree.findtext("head/title")
        except Exception:
            result = None
        return result or self.context.Title()

HTMLDocViewGenFactory = named_factory(HTMLDocViewGen)


class RSTDocViewGen(PortalTransformDocViewGenBase):
    zope.interface.implements(IDocViewGen)
    transform = 'rest_to_html'
    title = u'reStructuredText annotator'
    description = u'This converts raw RST files into a format suitable for ' \
                   'a Plone site.'

RSTDocViewGenFactory = named_factory(RSTDocViewGen)


# Supporting adapters

class ExposureFileNoteSourceAdapter(ExposureSourceAdapter):
Esempio n. 5
0
        model = doc.getModel()

        pt = getToolByName(self.context, 'portal_transforms', None)
        if pt:
            stream = datastream('license_description')
            pt.convert('safe_html', model.getNotesString(), stream)
            text = stream.getData().decode('utf8', 'ignore')
        else:
            # XXX should warn unsafe
            text = model.getNotesString()

        return (
            ('text', text,),
        )

SBMLNoteAnnotatorFactory = named_factory(SBMLNoteAnnotator)


class SBMLSpeciesAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    title = u'SBML Species'
    label = u'Species'
    description = u''
    for_interface = ISBMLSpeciesNote

    def generate(self):
        reader = libsbml.SBMLReader()
        doc = reader.readSBMLFromString(self.input)
        model = doc.getModel()
        result = [
            (
Esempio n. 6
0
    """

    zope.interface.implements(IExposureFileAnnotator, 
                              IExposureFileEditAnnotator)

    title = u'Basic Model Curation'
    label = u'Model Curation'
    description = u'Basic curation flags assigned to this item.'
    for_interface = IBasicCurationSet

    def _annotate(self, data):
        # XXX wholesale reimplementation of core method.  Once a proper
        # filter is implemented by parent class we can avoid doing this.
        note = self.note
        try:
            for a, v in data:
                # XXX figure out how to gracefully handle schema errors
                # (such as missing values).
                if a == 'flags':
                    v = scrub_json_unicode_to_string(v)
                setattr(note, a, v)
        except TypeError:
            raise TypeError('%s.generate failed to return a list of ' \
                            'tuple(key, value)' % self.__class__)
        except ValueError:
            raise ValueError('%s.generate returned invalid values (not ' \
                             'list of tuple(key, value)' % self.__class__)


BasicCurationAnnotatorFactory = named_factory(BasicCurationAnnotator)
Esempio n. 7
0
        if isinstance(issued, basestring) and re_date.search(issued):
            # Got everything.
            return u'%s, %s' % (authors, issued[:4])
        else:
            # We could pull from workspace, but users can fix this on
            # their own.  Proper citation metadata spec, etc.
            return u'%s, ' % (authors,)

    def generateTitle(self):
        # the fallbacks assume context is an atct type.
        if IExposureFile.providedBy(self.context):
            # since this is an exposure file, we will need to derive the
            # model/citation file as this should be the actual file that
            # contain the documentation.
            return self.findModelTitle() or self.context.Title()

        # otherwise, we just use the list of authors if citation is
        # found, for there are expectations for the listing to be the
        # same as how PMR1 did it.
        return self.findCitationAuthors() or self.context.Title()

    def generateDescription(self):
        # the fallbacks assume context is an atct type.
        # Since ExposureFiles don't usually show this field, the special
        # rule here applies to Exposures.  In the name of following the
        # footsteps of PMR1, the description will be the title of the
        # citation.
        return self.findCitationTitle() or self.context.Description()

CellMLTmpDocViewGenFactory = named_factory(CellMLTmpDocViewGen)
Esempio n. 8
0
from fieldml.pmr2.interfaces import *
from fieldml.pmr2.rdf import RdfExposureNoteHelper


class ZincViewerAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    for_interface = IZincViewerNote
    title = u'Zinc Viewer (Original)'
    label = u'Zinc Viewer'

    def generate(self):
        helper = RdfExposureNoteHelper()
        helper.parse(self.input)
        return helper.queryEFNote(self.__name__)

ZincViewerAnnotatorFactory = named_factory(ZincViewerAnnotator)


class JsonZincViewerAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    for_interface = IJsonZincViewerNote
    title = u'Zinc Viewer (JSON)'
    label = u'Zinc Viewer'

    def generate(self):
        helper = RdfExposureNoteHelper()
        helper.parse(self.input)
        return helper.queryEFNote(self.__name__)

JsonZincViewerAnnotatorFactory = named_factory(JsonZincViewerAnnotator)
Esempio n. 9
0
    description = u''
    for_interface = IDocGenNote
    edited_names = ('source', 'generator',)

    def generate(self):
        # XXX Should probably define the constraints better to make this
        # look less hackish.  Also tests?
        if not self.data:
            return {}

        d = dict(self.data)
        # XXX Fix the implementation of this to an adapter?
        dvgu = zope.component.queryUtility(IDocViewGen, name=d['generator'])
        if dvgu is None:
            return self.data

        exp, workspace, p = zope.component.getAdapter(self.context, 
            IExposureSourceAdapter).source()
        storage = zope.component.queryAdapter(workspace, IStorage)
        # should really use the adapter for this to avoid mistakes of
        # forgetting this.
        storage.checkout(exp.commit_id)
        # XXX so we do all of this in one single step.
        docviewgen = dvgu(self.context, storage.file(d['source']))
        docviewgen()

        # We don't need to change the data that got passed in.
        return self.data

DocGenAnnotatorFactory = named_factory(DocGenAnnotator)
Esempio n. 10
0
import zope.interface
import zope.component

from pmr2.app.factory import named_factory
from pmr2.app.annotation.interfaces import IExposureFileEditAnnotator
from pmr2.app.annotation.annotator import ExposureFileAnnotatorBase
from pmr2.app.annotation.annotator import PortalTransformAnnotatorBase

from pmr2.omex.interfaces import IOmexNote


@zope.interface.implementer(IExposureFileEditAnnotator)
class OmexAnnotator(ExposureFileAnnotatorBase):
    title = u'COMBINE Archive Path'
    label = u'COMBINE Archive'
    description = u''
    for_interface = IOmexNote

OmexAnnotatorFactory = named_factory(OmexAnnotator)
Esempio n. 11
0
        results = cu.extractMaths(model)
        return results

    def generate(self):
        def mathc2p(s):
            r = StringIO()
            t = etree.parse(StringIO(s))
            t.xslt(mathmlc2p_xslt).write(r)
            return r.getvalue()
        maths = self.maths()
        maths = [(k, [mathc2p(m) for m in v]) for k, v in maths]
        return (
            ('maths', maths),
        )

CellMLMathAnnotatorFactory = named_factory(CellMLMathAnnotator)


class CellMLCodegenAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    title = u'CellML Code Generation'
    label = u'Generated Code'
    description = u''
    for_interface = ICellMLCodegenNote

    def codegen(self):
        cu = zope.component.getUtility(ICellMLAPIUtility)
        sa = zope.component.queryAdapter(
            self.context, IExposureSourceAdapter)
        exposure, workspace, path = sa.source()
        modelfile = '%s/@@%s/%s/%s' % (workspace.absolute_url(),
Esempio n. 12
0
import zope.interface
import zope.component

from pmr2.app.factory import named_factory
from pmr2.app.annotation.interfaces import *
from pmr2.app.annotation.annotator import ExposureFileAnnotatorBase

from pmr2.annotation.mathjax.interfaces import IMathJaxNote


class MathJaxAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)

    title = u'MathML Viewer'
    label = u'MathML View'
    for_interface = IMathJaxNote

    def generate(self):
        return ()

MathJaxAnnotatorFactory = named_factory(MathJaxAnnotator)
Esempio n. 13
0
        if 'error' in result:
            raise KeyError("Flatmap server responded with an error: %s" %
                           result['error'])
        if 'map' not in result:
            raise KeyError(
                "No `map_id` found in response provided by flatmap server")
        # TODO deal with/wipe API key
        return (
            ('flatmap_host', data['flatmap_host']),
            ('flatmap_host_root', flatmap_host_root),
            ('initial_response', r.text),
            ('map_id', result['map']),
        )


FlatmapViewerAnnotatorFactory = named_factory(FlatmapViewerAnnotator)


class SDSAnnotator(ExposureFileAnnotatorBase):
    zope.interface.implements(IExposureFileAnnotator)
    for_interface = ISDSNote
    title = u'Flatmap SDS'
    label = u'Flatmap SDS Exporter'

    def generate(self):
        settings = zope.component.queryUtility(IPMR2GlobalSettings)
        root = settings.dirOf(self.context)
        view_root = join(root, self.__name__)
        if not isdir(root):
            makedirs(root)
        if exists(view_root):
Esempio n. 14
0
    edited_names = set(ILicenseCitationNote.names())

    def generate(self):
        note = self.note
        results = []

        if note.format:
            # a format is defined, we query for the selected utility to
            # generate the values below.
            u = zope.component.queryUtility(ICitationFormat, name=note.format)
            if u is None:
                # Something is wrong, either bad data or utility 
                # disappeared on us.  Fallback to the next step.
                pass
            else:
                # this may also provide the license_path if it has been
                # correctly added to the site.
                license_path, dcterms_license = u(self.context)()
                results.append(('license_path', license_path,))
                results.append(('dcterms_license', dcterms_license,))
                return results

        if note.license_path:
            license = getLicenses(self.context, path=note.license_path)
            if license:
                results.append(('dcterms_license', 
                                license[0].pmr2_license_uri,))
        return results

LicenseCitationAnnotatorFactory = named_factory(LicenseCitationAnnotator)