示例#1
0
    def manageService(servicename, servicedir, servicedata):
        if not os.path.exists(servicedir + "services/" + servicename +
                              "/__init__.py"):
            return

        if config.get('services.' + servicename + '.activate',
                      "").lower() == "false":
            return
        if servicename + '.basecontext' in config.getsubset("services").keys():
            basecontext = config.getsubset("services")[servicename +
                                                       '.basecontext']
        else:
            basecontext = config.get("services.contextprefix",
                                     "services") + '/' + servicename
        basecontext = ('/' + basecontext).replace('//', '/').replace('//', '/')
        context = athana.addContext(basecontext, ".")
        file = context.addFile(servicedir + "services/" + servicename)

        if hasattr(file.m, "request_handler"):
            file.addHandler("request_handler").addPattern("/.*")

            if not os.path.exists(servicedata):
                try:
                    os.makedirs(servicedata)
                    os.makedirs(os.path.join(servicedata, "cache"))
                except OSError:
                    return
示例#2
0
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        if os.path.basename(root) not in ("test", "__pycache__"):
            for name in [
                    f for f in files
                    if f.endswith(".py") and f != "__init__.py"
            ]:
                m = __import__("web.admin.modules." + name[:-3])
                m = eval("m.admin.modules." + name[:-3])
                mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".adminmodules"]

            for root, dirs, files in os.walk(
                    os.path.join(config.basedir, v + "/adminmodules")):
                for name in [
                        f for f in files
                        if f.endswith(".py") and f != "__init__.py"
                ]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
        except ImportError:
            pass  # no admin modules in plugin
    return mods
示例#3
0
def getEditModuleNames():
    ret = []
    path = os.walk(os.path.join(config.basedir, 'web/edit/modules'))
    for root, dirs, files in path:
        for name in [
                f for f in files if f.endswith(".py") and f != "__init__.py"
        ]:
            ret.append(name[:-3])

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".editmodules"]

            for root, dirs, files in os.walk(
                    os.path.join(config.basedir, v + "/editmodules")):
                for name in [
                        f for f in files
                        if f.endswith(".py") and f != "__init__.py"
                ]:
                    ret.append(name[:-3])
        except ImportError:
            pass  # no edit modules in plugin
    return ret
示例#4
0
def checkMetaDataFormat(format):
    d = config.getsubset('oai')
    try:
        return format.lower() in [
            x.strip().lower() for x in d['formats'].split(',') if x.strip()
        ]
    except:
        return False
示例#5
0
def loadServices():
    datapath = config.get("services.datapath", "")
    if not os.path.exists(os.path.join(datapath, "common")):
        try:
            os.makedirs(os.path.join(datapath, "common"))
        except OSError:
            pass

    def manageService(servicename, servicedir, servicedata):
        if not os.path.exists(servicedir + "services/" + servicename +
                              "/__init__.py"):
            return

        if config.get('services.' + servicename + '.activate',
                      "").lower() == "false":
            return
        if servicename + '.basecontext' in config.getsubset("services").keys():
            basecontext = config.getsubset("services")[servicename +
                                                       '.basecontext']
        else:
            basecontext = config.get("services.contextprefix",
                                     "services") + '/' + servicename
        basecontext = ('/' + basecontext).replace('//', '/').replace('//', '/')
        context = athana.addContext(basecontext, ".")
        file = context.addFile(servicedir + "services/" + servicename)

        if hasattr(file.m, "request_handler"):
            file.addHandler("request_handler").addPattern("/.*")

            if not os.path.exists(servicedata):
                try:
                    os.makedirs(servicedata)
                    os.makedirs(os.path.join(servicedata, "cache"))
                except OSError:
                    return

    if config.get("services.activate", "").lower() == "true":
        # try loading services from mediatum web/services/ folder
        p = config.basedir + "/web/services/"
        for servicedir in [
                f for f in os.listdir(p) if os.path.isdir(os.path.join(p, f))
        ]:
            manageService(servicedir, "web/",
                          os.path.join(datapath, servicedir))

        # try loading services from all plugins services/ folder
        for k, v in config.getsubset("plugins").items():
            p = os.path.join(config.basedir, v, 'services')
            if os.path.exists(p):
                for servicedir in [
                        f for f in os.listdir(p)
                        if os.path.isdir(os.path.join(p, f))
                ]:
                    manageService(servicedir, v,
                                  os.path.join(datapath, k, servicedir))

    else:
        print "web services not activated"
示例#6
0
def getContentStyles(type, name="", contenttype=""):
    name = name.split(";")[0]
    global contentstyles

    if len(contentstyles) == 0:
        styles = {}
        # load standard themes
        for root, dirs, files in os.walk(
                os.path.join(config.basedir, 'web/frontend/styles')):
            for n in [f for f in files if f.endswith(".cfg")]:
                c = readStyleConfig(root + "/" + n)
                styles[c.getID()] = c

        # test for external styles by plugin (default for user types) and theme styles of plugin styles
        for k, v in config.getsubset("plugins").items():
            path, module = splitpath(v)

            if os.path.exists(os.path.join(config.basedir, v)):
                for root, dirs, files in os.walk(
                        os.path.join(config.basedir, v)):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c
                    break

            if os.path.exists(
                    os.path.join(config.basedir,
                                 v + "themes/" + theme.getName() + "/styles")):
                for root, dirs, files in os.walk(
                        os.path.join(
                            config.basedir,
                            v + "themes/" + theme.getName() + "/styles")):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c

        contentstyles = styles

    if contenttype != "":
        ret = filter(lambda x: x.getContentType() == contenttype,
                     contentstyles.values())
        if len(ret) > 0:
            if name != "":
                return filter(lambda x: x.getName() == name, ret)
            else:
                return ret
        else:
            return []

    if name != "":
        if name in contentstyles.keys():
            return contentstyles[name]
        else:
            return contentstyles.values()[0]
    return filter(lambda x: x.getType() == type, contentstyles.values())
示例#7
0
    def manageService(servicename, servicedir, servicedata):
        if not os.path.exists(servicedir + "services/" + servicename + "/__init__.py"):
            return

        if config.get('services.' + servicename + '.activate', "").lower() == "false":
            return
        if servicename + '.basecontext' in config.getsubset("services").keys():
            basecontext = config.getsubset("services")[servicename + '.basecontext']
        else:
            basecontext = config.get("services.contextprefix", "services") + '/' + servicename
        basecontext = ('/' + basecontext).replace('//', '/').replace('//', '/')
        context = athana.addContext(basecontext, ".")
        file = context.addFile(servicedir + "services/" + servicename)

        if hasattr(file.m, "request_handler"):
            file.addHandler("request_handler").addPattern("/.*")

            if not os.path.exists(servicedata):
                try:
                    os.makedirs(servicedata)
                    os.makedirs(os.path.join(servicedata, "cache"))
                except OSError:
                    return
示例#8
0
def init_plugins():
    logg.info("looking for plugins, sys path is %s", pformat(sys.path))
    for name, location in config.getsubset("plugins").items():
        logg.info("Initializing plugin named '%s' from '%s'", name, location)
        m = import_plugin_module(name, location.strip(os.sep))
        if m is None:
            logg.warn("couldn't load plugin %s!", name)

        else:
            plugins[name] = m

        if hasattr(m, 'pofiles'):  # add po file paths
            if len(m.pofiles) > 0:
                print "  load translation files"
                for fp in m.pofiles:
                    translation.addPoFilepath([fp])
示例#9
0
def loadServices():
    datapath = config.get("services.datapath", "")
    if not os.path.exists(os.path.join(datapath, "common")):
        try:
            os.makedirs(os.path.join(datapath, "common"))
        except OSError:
            pass

    def manageService(servicename, servicedir, servicedata):
        if not os.path.exists(servicedir + "services/" + servicename + "/__init__.py"):
            return

        if config.get('services.' + servicename + '.activate', "").lower() == "false":
            return
        if servicename + '.basecontext' in config.getsubset("services").keys():
            basecontext = config.getsubset("services")[servicename + '.basecontext']
        else:
            basecontext = config.get("services.contextprefix", "services") + '/' + servicename
        basecontext = ('/' + basecontext).replace('//', '/').replace('//', '/')
        context = athana.addContext(basecontext, ".")
        file = context.addFile(servicedir + "services/" + servicename)

        if hasattr(file.m, "request_handler"):
            file.addHandler("request_handler").addPattern("/.*")

            if not os.path.exists(servicedata):
                try:
                    os.makedirs(servicedata)
                    os.makedirs(os.path.join(servicedata, "cache"))
                except OSError:
                    return

    if config.get("services.activate", "").lower() == "true":
        # try loading services from mediatum web/services/ folder
        p = config.basedir + "/web/services/"
        for servicedir in [f for f in os.listdir(p) if os.path.isdir(os.path.join(p, f))]:
            manageService(servicedir, "web/", os.path.join(datapath, servicedir))

        # try loading services from all plugins services/ folder
        for k, v in config.getsubset("plugins").items():
            p = os.path.join(config.basedir, v, 'services')
            if os.path.exists(p):
                for servicedir in [f for f in os.listdir(p) if os.path.isdir(os.path.join(p, f))]:
                    manageService(servicedir, v, os.path.join(datapath, k, servicedir))

    else:
        print "web services not activated"
示例#10
0
def getContentStyles(type, name="", contenttype=""):
    name = name.split(";")[0]
    global contentstyles

    if len(contentstyles) == 0:
        styles = {}
        # load standard themes
        for root, dirs, files in os.walk(os.path.join(config.basedir, 'web/frontend/styles')):
            for n in [f for f in files if f.endswith(".cfg")]:
                c = readStyleConfig(root + "/" + n)
                styles[c.getID()] = c

        # test for external styles by plugin (default for user types) and theme styles of plugin styles
        for k, v in config.getsubset("plugins").items():
            path, module = splitpath(v)

            if os.path.exists(os.path.join(config.basedir, v)):
                for root, dirs, files in os.walk(os.path.join(config.basedir, v)):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c
                    break

            if os.path.exists(os.path.join(config.basedir, v + "themes/" + theme.getName() + "/styles")):
                for root, dirs, files in os.walk(os.path.join(config.basedir, v + "themes/" + theme.getName() + "/styles")):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c

        contentstyles = styles

    if contenttype != "":
        ret = filter(lambda x: x.getContentType() == contenttype, contentstyles.values())
        if len(ret) > 0:
            if name != "":
                return filter(lambda x: x.getName() == name, ret)
            else:
                return ret
        else:
            return []

    if name != "":
        if name in contentstyles.keys():
            return contentstyles[name]
        else:
            return contentstyles.values()[0]
    return filter(lambda x: x.getType() == type, contentstyles.values())
示例#11
0
def ListMetadataFormats(req):
    if "set" in req.params:
        return writeError(req, "badArgument")

    # supported oai metadata formats are configured in section
    # oai.formats in the mediatum.cfg file
    d = config.getsubset('oai')
    formats = [x.strip() for x in d['formats'].split(',') if x.strip()]

    if "identifier" in req.params:
        # list only formats available for the given identifier
        try:
            nid = identifier2id(req.params.get("identifier"))
            if nid is None:
                return writeError(req, "idDoesNotExist")
            node = q(Node).get(nid)
        except (TypeError, KeyError):
            return writeError(req, "badArgument")
        if node is None:
            return writeError(req, "badArgument")

        if not node.has_read_access(user=get_guest_user()):
            return writeError(req, "noPermission")

        formats = [x for x in formats if nodeHasOAIExportMask(node, x.lower())]
        formats = [x for x in formats if filterFormat(node, x.lower())]

    # write xml for metadata formats list
    req.write('\n      <ListMetadataFormats>\n')
    for mdf in formats:
        try:
            req.write("""
             <metadataFormat>
               <metadataPrefix>%s</metadataPrefix>
               <schema>%s</schema>
               <metadataNamespace>%s</metadataNamespace>
             </metadataFormat>
             """ % (mdf, d["schema.%s" % mdf], d["namespace.%s" % mdf]))
        except:
            logg.exception(
                "%s: OAI error reading oai metadata format %s from config file",
                __file__, mdf)
    req.write('\n</ListMetadataFormats>')
    if DEBUG:
        timetable_update(req, "leaving ListMetadataFormats")
示例#12
0
def loadThemes():

    def manageThemes(themepath, type):
        name = config.get("config.theme", "")
        if os.path.exists(config.basedir + "/" + themepath + "themes/" + name + "/"):
            athana.addFileStore("/theme/", themepath + "themes/" + name + "/")
            athana.addFileStorePath("/css/", themepath + "themes/" + name + "/css/")
            athana.addFileStorePath("/img/", themepath + "themes/" + name + "/img/")
            athana.addFileStorePath("/js/", themepath + "themes/" + name + "/js/")
            theme.update(name, themepath + "themes/" + name + "/", type)
            print "Loading theme '%s' (%s)" % (name, type)

    if config.get("config.theme", "") != "":
        manageThemes("web/", "intern")  # internal theme

        for k, v in config.getsubset("plugins").items():  # themes from plugins
            manageThemes(v, "extern")
    else:
        print "Loading default theme"
示例#13
0
def getEditModuleNames():
    ret = []
    path = os.walk(os.path.join(config.basedir, 'web/edit/modules'))
    for root, dirs, files in path:
        for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
            ret.append(name[:-3])

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".editmodules"]

            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/editmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    ret.append(name[:-3])
        except ImportError:
            pass  # no edit modules in plugin
    return ret
示例#14
0
def init_plugins():
    for name, location in config.getsubset("plugins").items():
        m = import_plugin_module(name, location)
        if m is None:
            logg.warn("couldn't load plugin %s!", name)
        else:
            logg.info("Initializing plugin '%s' from '%s'", name, location or "pythonpath")
            plugins[name] = m

        # plugins can define an init() method in their package __init__
        if hasattr(m, "init") and callable(m.init):
            m.init()

        # add po file paths
        if hasattr(m, "pofiles"):  
            if len(m.pofiles) > 0:
                logg.debug("loading translation files for plugin %s", name)
                for fp in m.pofiles:
                    translation.addPoFilepath([fp])
示例#15
0
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        if os.path.basename(root) not in ("test", "__pycache__"):
            for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                m = __import__("web.admin.modules." + name[:-3])
                m = eval("m.admin.modules." + name[:-3])
                mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        with suppress(ImportError,warn=False): # no admin modules in plugin
            sys.path += [path + ".adminmodules"]
            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/adminmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
    return mods
示例#16
0
def ListMetadataFormats(req):
    if "set" in req.params:
        return writeError(req, "badArgument")

    # supported oai metadata formats are configured in section
    # oai.formats in the mediatum.cfg file
    d = config.getsubset('oai')
    formats = [x.strip() for x in d['formats'].split(',') if x.strip()]

    if "identifier" in req.params:
        # list only formats available for the given identifier
        try:
            node = tree.getNode(identifier2id(req.params.get("identifier")))
        except (TypeError, KeyError, tree.NoSuchNodeError):
            return writeError(req, "badArgument")

        access = acl.AccessData(req)
        if not access.hasReadAccess(node):
            return writeError(req, "noPermission")

        formats = [x for x in formats if nodeHasOAIExportMask(node, x.lower())]
        formats = [x for x in formats if filterFormat(node, x.lower())]

    # write xml for metadata formats list
    req.write('\n      <ListMetadataFormats>\n')
    for mdf in formats:
        try:
            req.write("""
             <metadataFormat>
               <metadataPrefix>%s</metadataPrefix>
               <schema>%s</schema>
               <metadataNamespace>%s</metadataNamespace>
             </metadataFormat>
             """ % (mdf, d["schema.%s" % mdf], d["namespace.%s" % mdf]))
        except:
            OUT(
                "%s: OAI error reading oai metadata format %s from config file"
                % (__file__, mdf), 'error')
    req.write('\n</ListMetadataFormats>')
    if DEBUG:
        timetable_update(req, "leaving ListMetadataFormats")
示例#17
0
文件: oai.py 项目: agromsl/mediatum
def ListMetadataFormats(req):
    if "set" in req.params:
        return writeError(req, "badArgument")

    # supported oai metadata formats are configured in section
    # oai.formats in the mediatum.cfg file
    d = config.getsubset('oai')
    formats = [x.strip() for x in d['formats'].split(',') if x.strip()]

    if "identifier" in req.params:
        # list only formats available for the given identifier
        try:
            node = tree.getNode(identifier2id(req.params.get("identifier")))
        except (TypeError, KeyError, tree.NoSuchNodeError):
            return writeError(req, "badArgument")

        access = acl.AccessData(req)
        if not access.hasReadAccess(node):
            return writeError(req, "noPermission")

        formats = [x for x in formats if nodeHasOAIExportMask(node, x.lower())]
        formats = [x for x in formats if filterFormat(node, x.lower())]

    # write xml for metadata formats list
    req.write('\n      <ListMetadataFormats>\n')
    for mdf in formats:
        try:
            req.write("""
             <metadataFormat>
               <metadataPrefix>%s</metadataPrefix>
               <schema>%s</schema>
               <metadataNamespace>%s</metadataNamespace>
             </metadataFormat>
             """ % (mdf, d["schema.%s" % mdf], d["namespace.%s" % mdf]))
        except:
            OUT("%s: OAI error reading oai metadata format %s from config file" % (__file__, mdf), 'error')
    req.write('\n</ListMetadataFormats>')
    if DEBUG:
        timetable_update(req, "leaving ListMetadataFormats")
示例#18
0
def loadThemes():
    def manageThemes(themepath, type):
        name = config.get("config.theme", "")
        if os.path.exists(config.basedir + "/" + themepath + "themes/" + name +
                          "/"):
            athana.addFileStore("/theme/", themepath + "themes/" + name + "/")
            athana.addFileStorePath("/css/",
                                    themepath + "themes/" + name + "/css/")
            athana.addFileStorePath("/img/",
                                    themepath + "themes/" + name + "/img/")
            athana.addFileStorePath("/js/",
                                    themepath + "themes/" + name + "/js/")
            theme.update(name, themepath + "themes/" + name + "/", type)
            print "Loading theme '%s' (%s)" % (name, type)

    if config.get("config.theme", "") != "":
        manageThemes("web/", "intern")  # internal theme

        for k, v in config.getsubset("plugins").items():  # themes from plugins
            manageThemes(v, "extern")
    else:
        print "Loading default theme"
示例#19
0
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
            m = __import__("web.admin.modules." + name[:-3])
            m = eval("m.admin.modules." + name[:-3])
            mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".adminmodules"]

            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/adminmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
        except ImportError:
            pass  # no admin modules in plugin
    return mods
示例#20
0
文件: oai.py 项目: agromsl/mediatum
def checkMetaDataFormat(format):
    d = config.getsubset('oai')
    try:
        return format.lower() in [x.strip().lower() for x in d['formats'].split(',') if x.strip()]
    except:
        return False