예제 #1
0
    def build_proto(self):
        """Builds the prototype library, by building or injesting any bundles that don't
        exist in it yet. """

        from ambry.orm.exc import NotFoundError

        l = Library(self._proto_config())


        try:
            b = l.bundle('ingest.example.com-headerstypes')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/headerstypes')
            b.log('Build to: {}'.format(b.build_fs))
            b.ingest()
            b.close()

        try:
            b = l.bundle('ingest.example.com-stages')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/stages')
            b.ingest()
            b.close()

        try:
            b = l.bundle('ingest.example.com-basic')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/basic')
            b.ingest()
            b.close()

        try:
            b = l.bundle('build.example.com-coverage')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/coverage')
            b.ingest()
            b.source_schema()
            b.schema()
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-generators')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/generators')
            b.run()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-plot')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/plot')
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-casters')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/casters')
            b.ingest()
            b.source_schema()
            b.schema()
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-sql')

        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/sql')
            b.build(sources=['integers', 'integers2', 'integers3'])
예제 #2
0
class AmbryAppContext(object):
    """Ambry specific objects for the application context"""

    def __init__(self):
        from ambry.library import Library
        from ambry.run import get_runconfig

        rc = get_runconfig()
        self.library = Library(rc, read_only=True, echo=False)

    def render(self, template, *args, **kwargs):
        from flask import render_template

        context = self.cc

        context.update(kwargs)

        context['l'] = self.library

        return render_template(template, *args, **context)

    @property
    def cc(self):
        """Return common context values. These are primarily helper functions
        that can be used from the context. """
        from ambry._meta import __version__ as ambry_version
        from __meta__ import __version__ as ui_version
        from flask import request

        def scale_font(x):
            """Scales the font for the partition title. Completely ad-hoc."""

            size = 100

            if len(x) > 130:
                size = 90

            return 'font-size: {}%;'.format(size)

        return {
            'scale_font': scale_font,
            'ambry_version': ambry_version,
            'ui_version': ui_version,
            'url_for': url_for,
            'from_root': lambda x: x,
            'getattr': getattr,
            'title': app.config.get('website_title'),
            'next_page': request.path,  # Actually last page, for login redirect
            'session': session,
            'autologin_user': app.config['LOGGED_IN_USER']

        }

    def bundle(self, ref):
        from flask import abort
        from ambry.orm.exc import NotFoundError

        try:
            return self.library.bundle(ref)
        except NotFoundError:
            abort(404)

    def json(self, **kwargs):
        return Response(dumps(kwargs, cls=JSONEncoder), mimetype='application/json')

    def close(self):
        self.library.close()
예제 #3
0
class AmbryAppContext(object):
    """Ambry specific objects for the application context"""
    def __init__(self):
        from ambry.library import Library
        from ambry.run import get_runconfig

        rc = get_runconfig()
        self.library = Library(rc, read_only=True, echo=False)

    def render(self, template, *args, **kwargs):
        from flask import render_template

        context = self.cc

        context.update(kwargs)

        context['l'] = self.library

        return render_template(template, *args, **context)

    @property
    def cc(self):
        """Return common context values. These are primarily helper functions
        that can be used from the context. """
        from ambry._meta import __version__ as ambry_version
        from __meta__ import __version__ as ui_version
        from flask import request

        def scale_font(x):
            """Scales the font for the partition title. Completely ad-hoc."""

            size = 100

            if len(x) > 130:
                size = 90

            return 'font-size: {}%;'.format(size)

        return {
            'scale_font': scale_font,
            'ambry_version': ambry_version,
            'ui_version': ui_version,
            'url_for': url_for,
            'from_root': lambda x: x,
            'getattr': getattr,
            'title': app.config.get('website_title'),
            'next_page':
            request.path,  # Actually last page, for login redirect
            'session': session,
            'autologin_user': app.config['LOGGED_IN_USER']
        }

    def bundle(self, ref):
        from flask import abort
        from ambry.orm.exc import NotFoundError

        try:
            return self.library.bundle(ref)
        except NotFoundError:
            abort(404)

    def json(self, **kwargs):
        return Response(dumps(kwargs, cls=JSONEncoder),
                        mimetype='application/json')

    def close(self):
        self.library.close()
예제 #4
0
    def build_proto(self):
        """Builds the prototype library, by building or injesting any bundles that don't
        exist in it yet. """

        from ambry.orm.exc import NotFoundError

        l = Library(self._proto_config())

        try:
            b = l.bundle('ingest.example.com-headerstypes')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/headerstypes')
            b.log('Build to: {}'.format(b.build_fs))
            b.ingest()
            b.close()

        try:
            b = l.bundle('ingest.example.com-stages')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/stages')
            b.ingest()
            b.close()

        try:
            b = l.bundle('ingest.example.com-basic')
        except NotFoundError:
            b = self.import_bundle(l, 'ingest.example.com/basic')
            b.ingest()
            b.close()

        try:
            b = l.bundle('build.example.com-coverage')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/coverage')
            b.ingest()
            b.source_schema()
            b.schema()
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-generators')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/generators')
            b.run()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-plot')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/plot')
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-casters')
        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/casters')
            b.ingest()
            b.source_schema()
            b.schema()
            b.build()
            b.finalize()
            b.close()

        try:
            b = l.bundle('build.example.com-sql')

        except NotFoundError:
            b = self.import_bundle(l, 'build.example.com/sql')
            b.build(sources=['integers', 'integers2', 'integers3'])