diff --git a/opac_proc/datastore/mongodb_connector.py b/opac_proc/datastore/mongodb_connector.py index 9d53498b..4f37d588 100644 --- a/opac_proc/datastore/mongodb_connector.py +++ b/opac_proc/datastore/mongodb_connector.py @@ -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 diff --git a/opac_proc/datastore/redis_queues.py b/opac_proc/datastore/redis_queues.py index f5a6ad0b..d1305291 100644 --- a/opac_proc/datastore/redis_queues.py +++ b/opac_proc/datastore/redis_queues.py @@ -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): diff --git a/opac_proc/extractors/base.py b/opac_proc/extractors/base.py index 9a13b40f..f0416aba 100644 --- a/opac_proc/extractors/base.py +++ b/opac_proc/extractors/base.py @@ -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) diff --git a/opac_proc/loaders/base.py b/opac_proc/loaders/base.py index ba3c8332..e64eb6e8 100644 --- a/opac_proc/loaders/base.py +++ b/opac_proc/loaders/base.py @@ -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 diff --git a/opac_proc/loaders/process.py b/opac_proc/loaders/process.py index 4ad23156..bc3e8aa3 100644 --- a/opac_proc/loaders/process.py +++ b/opac_proc/loaders/process.py @@ -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: diff --git a/opac_proc/transformers/utils.py b/opac_proc/transformers/utils.py index 0cff2682..27b32734 100644 --- a/opac_proc/transformers/utils.py +++ b/opac_proc/transformers/utils.py @@ -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)] diff --git a/opac_proc/web/views/home.py b/opac_proc/web/views/home.py index 50351528..cb3861dd 100644 --- a/opac_proc/web/views/home.py +++ b/opac_proc/web/views/home.py @@ -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() @@ -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 = { diff --git a/thrift_clients/clients.py b/thrift_clients/clients.py index 163eb73f..ad3a5eb2 100644 --- a/thrift_clients/clients.py +++ b/thrift_clients/clients.py @@ -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):