def broadcast_links(src_dir):
    links_list = []
    os.path.walk(src_dir,get_objs_in_dir,links_list)
    b = BroadcastToRedis(config['redis.host'], config['broadcast.queue'])
    
    for silo, item in links_list:
        b.creation(silo, item)
    return
def broadcast_links(src_file):
    csvfo = file(fname, 'r')
    b = BroadcastToRedis('localhost', 'silochanges')
    ur = UnicodeReader(csvfo)
    data = ur.next()
    while data:
        b.change('digital.bodleian', data[0])
        try:
            data = ur.next()
        except:
            data = None
    return
    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
def get_objs_in_dir(items_list, dirname, fnames):
    for fname in fnames:
        a = os.path.join(dirname,fname)
        if fname == 'obj':
            item = a.split('pairtree_root')[1].strip('/').split('obj')[0].replace('/', '')
            silo = a.split('pairtree_root')[0].strip('/').split('/')[-1]
            if not (silo, item) in items_list:
                items_list.append((silo, item))
    return
    
def broadcast_links(src_dir):
    links_list = []
    os.path.walk(src_dir,get_objs_in_dir,links_list)
    b = BroadcastToRedis(config['redis.host'], config['broadcast.queue'])
    
    for silo, item in links_list:
        b.creation(silo, item)
    return
            
src_dirs = [
'/silos',
]

for src_dir in src_dirs:
    print "starting", src_dir
    links_list = []
    os.path.walk(src_dir,get_objs_in_dir,links_list)
    b = BroadcastToRedis(config['redis.host'], config['broadcast.queue'])
    for silo, item in links_list:
        b.creation(silo, item)
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)

#======================================================================

# To add items to redis
from rdfdatabank.lib.broadcast import BroadcastToRedis
b = BroadcastToRedis("localhost", 'silochanges')

b.creation("demo", "Apocalypse-auctm315", ident="admin")
b.creation("demo", "Apocalypse-douce249", ident="admin")
b.creation("demo", "BibliaPauperum-archgc14", ident="admin")
b.creation("demo", "CanticumCanticorum-auctm312", ident="admin")
b.creation("demo", "MCSimulation-WW4jet", ident="admin")
b.creation("demo", "MCSimulation-WW4jet-CR", ident="admin")
b.creation("demo", "MonteCarloSimulations", ident="admin")
b.creation("demo", "blockbooks", ident="admin")
b.creation("test", "TestSubmission_2", ident="sandbox_user")
b.creation("dataflow", "GabrielTest", ident="admin")
b.creation("dataflow", "anusha-test", ident="admin")
b.creation("dataflow", "anusha-test-testrdf3", ident="admin")
b.creation("dataflow", "anusha:test", ident="admin")
b.creation("dataflow", "joe-test-2011-09-16-1", ident="admin")