Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajustes para landscape.io (parte 2) #43

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions opac_proc/datastore/mongodb_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ def get_opac_logs_db_name():

def get_db_connection():
if config.MONGODB_USER and config.MONGODB_PASS:
logger.debug(u'Iniciando conexão - com credenciais do banco: mongo://{username}:{password}@{host}:{port}/{db}'.format(**config.MONGODB_SETTINGS))
msg = u'Iniciando conexão - com credenciais do banco: mongo://{username}:{password}@{host}:{port}/{db}'.format(**config.MONGODB_SETTINGS)
logger.debug(msg)
else:
logger.debug(u'Iniciando conexão - sem credenciais do banco: mongo://{host}:{port}/{db}'.format(**config.MONGODB_SETTINGS))
msg = u'Iniciando conexão - sem credenciais do banco: mongo://{host}:{port}/{db}'.format(**config.MONGODB_SETTINGS)
logger.debug(msg)
try:
db = connect(**config.MONGODB_SETTINGS)
except Exception, e: # melhorar captura da Exceção
logger.error(u"Não é possível conectar com banco de dados mongo. %s", str(e))
msg = u"Não é possível conectar com banco de dados mongo. %s", str(e)
logger.error(msg)
else:
db_name = get_opac_proc_db_name()
logger.info(u"Conexão establecida com banco: %s!" % db_name)
msg = u"Conexão establecida com banco: %s!" % db_name
logger.info(msg)
return db


Expand Down
8 changes: 4 additions & 4 deletions opac_proc/datastore/redis_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
class Singleton(object):
_instances = {}

def __new__(class_, *args, **kwargs):
if class_ not in class_._instances:
class_._instances[class_] = super(Singleton, class_).__new__(class_, *args, **kwargs)
return class_._instances[class_]
def __new__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls._instances[cls]


class RQueues(Singleton):
Expand Down
4 changes: 2 additions & 2 deletions opac_proc/extractors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def save(self):
self.extract_model_instance.modify(**self._raw_data)
else:
logger.debug(u"extract_model_instance NÃO encontrado. Criando novo!")
self.extract_model_class(**self._raw_data).save()
self.extract_model_instance = self.get_extract_model_instance()
self.extract_model_instance = self.extract_model_class(**self._raw_data)
self.extract_model_instance.save()
except Exception, e:
msg = u"Não foi possível salvar %s. Exeção: %s" % (
self.extract_model_name, e)
Expand Down
6 changes: 3 additions & 3 deletions opac_proc/loaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def __init__(self, transform_model_uuid):
self._uuid = transform_model_uuid
self._uuid_str = str(transform_model_uuid).replace("-", "")

self.get_transform_model_instance(query={'uuid': self._uuid})
self.get_transform_model_instance(query_dict={'uuid': self._uuid})

# buscamos uma instância na base opac com o mesmo UUID
self.get_opac_model_instance(query={'_id': self._uuid_str})
self.get_opac_model_instance(query_dict={'_id': self._uuid_str})

# Load model instance: to track process times by uuid
self.get_load_model_instance(query={'uuid': self._uuid})
self.get_load_model_instance(query_dict={'uuid': self._uuid})

self.metadata['uuid'] = self._uuid

Expand Down
14 changes: 4 additions & 10 deletions opac_proc/loaders/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,10 @@ def process_collection(self, collection_acronym=None, collection_uuid=None):

uuid = str(collection.uuid)

if self.async:
self.r_queues.enqueue(
self.stage, 'collection',
jobs.task_load_collection,
uuid)
else:
# invocamos a task como funcão normal (sem fila)
collection = jobs.task_load_collection(uuid)
collection.reload()
return collection
self.r_queues.enqueue(
self.stage, 'collection',
jobs.task_load_collection,
uuid)

def process_journal(self, collection_acronym=None, issn=None, uuid=None):
if not collection_acronym:
Expand Down
2 changes: 1 addition & 1 deletion opac_proc/transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def trydate(str_date):


def split_list(li, col):
return [li[i:i+col] for i in range(0, len(li), col)]
return [li[i:i + col] for i in range(0, len(li), col)]
18 changes: 9 additions & 9 deletions opac_proc/web/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def home():
register_connections()
OPAC_WEBAPP_DB_NAME = get_opac_webapp_db_name()
opac_webapp_db_name = get_opac_webapp_db_name()
# extract counts
extract_collection_count = models.ExtractCollection.objects.all().count()
extract_journal_count = models.ExtractJournal.objects.all().count()
Expand All @@ -34,28 +34,28 @@ def home():
load_issue_count = models.LoadIssue.objects.all().count()
load_article_count = models.LoadArticle.objects.all().count()
# OPAC counts
with switch_db(OpacCollection, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacCollection, opac_webapp_db_name):
opac_collection_count = OpacCollection.objects.all().count()

with switch_db(OpacJournal, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacJournal, opac_webapp_db_name):
opac_journal_count = OpacJournal.objects.all().count()

with switch_db(OpacIssue, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacIssue, opac_webapp_db_name):
opac_issue_count = OpacIssue.objects.all().count()

with switch_db(OpacArticle, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacArticle, opac_webapp_db_name):
opac_article_count = OpacArticle.objects.all().count()

with switch_db(OpacPressRelease, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacPressRelease, opac_webapp_db_name):
opac_pressrelease_count = OpacPressRelease.objects.all().count()

with switch_db(OpacSponsor, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacSponsor, opac_webapp_db_name):
opac_sponsor_count = OpacSponsor.objects.all().count()

with switch_db(OpacPages, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacPages, opac_webapp_db_name):
opac_page_count = OpacPages.objects.all().count()

with switch_db(OpacNews, OPAC_WEBAPP_DB_NAME):
with switch_db(OpacNews, opac_webapp_db_name):
opac_news_count = OpacNews.objects.all().count()

context = {
Expand Down
2 changes: 1 addition & 1 deletion thrift_clients/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


articlemeta_thrift = thriftpy.load(
os.path.join(os.path.dirname(__file__))+'/articlemeta.thrift')
os.path.join(os.path.dirname(__file__)) + '/articlemeta.thrift')


class ServerError(Exception):
Expand Down