Ejemplo n.º 1
0
def asset_spec_from_abspath(abspath, package):
    """ Try to convert an absolute path to a resource in a package to
    a resource specification if possible; otherwise return the
    absolute path.  """
    if getattr(package, "__name__", None) == "__main__":
        return abspath
    pp = package_path(package) + os.path.sep
    if abspath.startswith(pp):
        relpath = abspath[len(pp) :]
        return "%s:%s" % (package_name(package), relpath.replace(os.path.sep, "/"))
    return abspath
Ejemplo n.º 2
0
def asset_spec_from_abspath(abspath, package):
    """ Try to convert an absolute path to a resource in a package to
    a resource specification if possible; otherwise return the
    absolute path.  """
    if getattr(package, '__name__', None) == '__main__':
        return abspath
    pp = package_path(package) + os.path.sep
    if abspath.startswith(pp):
        relpath = abspath[len(pp):]
        return '%s:%s' % (package_name(package),
                          relpath.replace(os.path.sep, '/'))
    return abspath
Ejemplo n.º 3
0
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)
        self.config.include("ptah")

        for pkg in self._includes:  # pragma: no cover
            self.config.include(pkg)

        pkg = package_name(sys.modules[self.__class__.__module__])
        if pkg != "ptah":
            parts = self.__class__.__module__.split(".")
            for l in range(len(parts)):
                pkg = ".".join(parts[: l + 1])
                if pkg == "ptah" or pkg.startswith("ptah.") or pkg in self._includes:
                    continue  # pragma: no cover
                try:
                    self.config.include(pkg)
                except:  # pragma: no cover
                    pass

        self.config.scan(self.__class__.__module__)

        self.config.commit()

        self.config.ptah_init_settings()

        if self._init_static:
            self.config.add_bower_components("ptah:static/bower_components")

        if self._init_sqla:
            # create engine
            self.config.ptah_init_sql()

            # create sql tables
            Base = ptah.get_base()
            Base.metadata.create_all()
            transaction.commit()

        if self._init_mail:
            self.config.init_mailer(ptah.mail.DummyMailer())

        if self._trusted_manage:

            def trusted(*args):
                return True

            ptah.manage.set_access_manager(trusted)
Ejemplo n.º 4
0
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)
        self.config.include('ptah')

        for pkg in self._includes:  # pragma: no cover
            self.config.include(pkg)

        pkg = package_name(sys.modules[self.__class__.__module__])
        if pkg != 'ptah':
            parts = self.__class__.__module__.split('.')
            for l in range(len(parts)):
                pkg = '.'.join(parts[:l + 1])
                if pkg == 'ptah' or pkg.startswith('ptah.') or \
                       pkg in self._includes:
                    continue  # pragma: no cover
                try:
                    self.config.include(pkg)
                except:  # pragma: no cover
                    pass

        self.config.scan(self.__class__.__module__)

        self.config.commit()

        self.config.ptah_init_settings()

        if self._init_static:
            self.config.add_bower_components('ptah:static/bower_components')

        if self._init_sqla:
            # create engine
            self.config.ptah_init_sql()

            # create sql tables
            Base = ptah.get_base()
            Base.metadata.create_all()
            transaction.commit()

        if self._trusted_manage:

            def trusted(*args):
                return True

            ptah.manage.set_access_manager(trusted)
Ejemplo n.º 5
0
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)
        self.config.include('ptah')

        for pkg in self._includes: # pragma: no cover
            self.config.include(pkg)

        pkg = package_name(sys.modules[self.__class__.__module__])
        if pkg != 'ptah':
            packages = []
            parts = self.__class__.__module__.split('.')
            for l in range(len(parts)):
                pkg = '.'.join(parts[:l+1])
                if pkg == 'ptah' or pkg.startswith('ptah.') or \
                       pkg in self._includes:
                    continue # pragma: no cover
                try:
                    self.config.include(pkg)
                except: # pragma: no cover
                    pass

        self.config.scan(self.__class__.__module__)

        self.config.commit()
        self.config.autocommit = self._auto_commit

        self.config.ptah_init_settings()

        ptah.reset_session()

        if self._init_sqla:
            # create engine
            self.config.ptah_init_sql()

            # create sql tables
            Base = ptah.get_base()
            Base.metadata.create_all()
            transaction.commit()

        if self._trusted_manage:
            def trusted(*args):
                return True
            ptah.manage.set_access_manager(trusted)
 def _callFUT(self, package):
     from pyramid.path import package_name
     return package_name(package)