コード例 #1
0
    def __init__(self):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """

        self.authz = authz
        #self.users = _USERS
        self.NAMESPACES = NAMESPACES
        self.PREFIXES = PREFIXES

        if config.has_key("granary.uri_root"):
            self.root = config['granary.uri_root']

        if config.has_key("granary.store"):
            self.granary = Granary(config['granary.store'])

        if config.has_key("redis.host"):
            self.redishost = config['redis.host']
            try:
                self.r = Redis(self.redishost)
            except:
                self.r = None
            if self.r and config.has_key("broadcast.to") and config[
                    'broadcast.to'] == "redis" and config.has_key(
                        "broadcast.queue"):
                self.b = BroadcastToRedis(config['redis.host'],
                                          config['broadcast.queue'])
        else:
            self.r = None
            self.redishost = None
            self.b = None

        if config.has_key("solr.host"):
            from solr import SolrConnection
            self.solrhost = config['solr.host']
            try:
                self.solr = SolrConnection(self.solrhost)
            except:
                self.solr = None
        else:
            self.solrhost = None
            self.solr = None

        if config.has_key("naming_rule"):
            self.naming_rule = config['naming_rule']

        if config.has_key("naming_rule_humanized"):
            self.naming_rule_humanized = config['naming_rule_humanized']
        elif config.has_key("naming_rule"):
            self.naming_rule_humanized = config['naming_rule']

        if config.has_key("metadata.embargoed"):
            self.metadata_embargoed = config['metadata.embargoed']
            if isinstance(self.metadata_embargoed, basestring):
                if self.metadata_embargoed.lower().strip() == 'true':
                    self.metadata_embargoed = True
                else:
                    self.metadata_embargoed = False
            elif not type(self.metadata_embargoed).__name__ == 'bool':
                self.metadata_embargoed = False
        else:
            self.metadata_embargoed = False

        if config.has_key("auth.file"):
            pwdfile = config['auth.file']
            self.passwdfile = HtpasswdFile(pwdfile)
            self.passwdfile.load()

        if config.has_key("auth.info"):
            self.userfile = config['auth.info']

        if config.has_key("doi.count"):
            self.doi_count_file = config['doi.count']

        if config.has_key("formats_served"):
            self.formats_served = config['formats_served']
        else:
            self.formats_served = [
                "text/html", "text/xhtml", "text/plain", "application/json",
                "application/rdf+xml", "text/xml"
            ]

        if config.has_key("publisher"):
            self.publisher = config['publisher']
        else:
            self.publisher = "Bodleian Libraries, University of Oxford"

        if config.has_key("rights"):
            self.rights = config['rights']

        if config.has_key("license"):
            self.license = config['license']

        if config.has_key("api.version"):
            self.api_version = config['api.version']

        try:
            sync_members(self.granary)
        except:
            pass
コード例 #2
0
# -*- coding: utf-8 -*-
"""
Copyright (c) 2012 University of Oxford

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, --INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

from recordsilo import Granary

from frontend.settings import GRANARY_STORE

granary = Granary(GRANARY_STORE)
コード例 #3
0
# -*- coding: utf-8 -*-
"""
Copyright (c) 2012 University of Oxford

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, --INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

from recordsilo import Granary

import frontend.settings

granary = Granary(settings.GRANARY_STORE)
コード例 #4
0
ファイル: solr_worker.py プロジェクト: cbeer/RDFDatabank
    hours_before_commit = 1
    if len(sys.argv) == 3:
        if "redis_%s" % sys.argv[2] in c.sections():
            redis_section = "redis_%s" % sys.argv[2]

    rq = RedisQueue(c.get(worker_section, "listento"), "solr_%s" % worker_number,
                  db=c.get(redis_section, "db"), 
                  host=c.get(redis_section, "host"), 
                  port=c.get(redis_section, "port"),
                  errorqueue=c.get(worker_section, "errorq")
                 )
    DB_ROOT = c.get(worker_section, "dbroot")
    rdfdb_config = Config("%s/production.ini" % DB_ROOT)
    granary_root = rdfdb_config.get("app:main", "granary.store", 0, {'here':DB_ROOT})
  
    g = Granary(granary_root)

    solr = SolrConnection(c.get(worker_section, "solrurl"))

    idletime = 0.1
    commit_time = datetime.now() + timedelta(hours=hours_before_commit)
    toCommit = False
    while(True):
        sleep(idletime)

        if datetime.now() > commit_time and toCommit:
            solr.commit()
            commit_time = datetime.now() + timedelta(hours=hours_before_commit)
            toCommit = False

        line = rq.pop()
コード例 #5
0
    
#======================================================================

# To add items to SOLR once in redis (for testing). Stop supervisor workers
from redis import Redis
from recordsilo import Granary
from solr import SolrConnection
from solr_worker import gather_document
import simplejson

r = Redis()
r.llen('silochanges')
for i in range(r.llen('silochanges')):
    r.lindex('silochanges', i)

g = Granary("/opt/RDFDatabank/silos")
solr = SolrConnection("http://localhost:8080/solr")

line = r.rpop("silochanges")
msg = simplejson.loads(line)
silo_name = msg['silo']
s = g.get_rdf_silo(silo_name)
itemid = msg.get('id')
if itemid and s.exists(itemid):
    item = s.get_item(itemid)
    solr_doc = gather_document(silo_name, item)
    solr.add(_commit=True, **solr_doc)

#r.rpush("silochanges", line)

#======================================================================
コード例 #6
0
  redis_section = "redis"
  worker_section = "worker_solr"
  worker_number = sys.argv[1]
  if len(sys.argv) == 3:
    if "redis_%s" % sys.argv[2] in c.sections():
      redis_section = "redis_%s" % sys.argv[2]

  rq = RedisQueue(c.get(worker_section, "listento"), "solr_%s" % worker_number,
                  db=c.get(redis_section, "db"), 
                  host=c.get(redis_section, "host"), 
                  port=c.get(redis_section, "port")
                  )
  rdfdb_config = Config("%s/production.ini" % DB_ROOT)
  granary_root = rdfdb_config.get("app:main", "granary.store", 0, {'here':DB_ROOT})
  
  g = Granary(granary_root)

  solr = SolrConnection(c.get(worker_section, "solrurl"))

  idletime = 2

  while(True):
    line = rq.pop()
    if line:
      try:
        msg = simplejson.loads(line)
        # solr switch
        silo_name = msg['silo']
        if silo_name not in g.silos:
          g._register_silos()
          if silo_name not in g.silos: