fixing errors detected with flake8
Change-Id: Ib99df43fd5f86ccbb3e35111972a2075e7a956dd
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
-date_version = '2018-04-19'
\ No newline at end of file
+date_version = '2018-04-25'
-from dbbase import DbException, DbBase
+from osm_common.dbbase import DbException, DbBase
from http import HTTPStatus
from uuid import uuid4
from copy import deepcopy
from http import HTTPStatus
from uuid import uuid4
from copy import deepcopy
if __name__ == '__main__':
# some test code
if __name__ == '__main__':
# some test code
db.create("test", {"_id": 1, "data": 1})
db.create("test", {"_id": 2, "data": 2})
db.create("test", {"_id": 3, "data": 3})
db.create("test", {"_id": 1, "data": 1})
db.create("test", {"_id": 2, "data": 2})
db.create("test", {"_id": 3, "data": 3})
import logging
from pymongo import MongoClient, errors
import logging
from pymongo import MongoClient, errors
-from dbbase import DbException, DbBase
+from osm_common.dbbase import DbException, DbBase
from http import HTTPStatus
from time import time, sleep
from http import HTTPStatus
from time import time, sleep
try:
collection = self.db[table]
rows = collection.update_one(self._format_filter(filter), {"$set": update_dict})
try:
collection = self.db[table]
rows = collection.update_one(self._format_filter(filter), {"$set": update_dict})
- if rows.updated_count == 0:
+ if rows.matched_count == 0:
if fail_on_empty:
raise DbException("Not found any {} with filter='{}'".format(table[:-1], filter),
HTTPStatus.NOT_FOUND)
return None
if fail_on_empty:
raise DbException("Not found any {} with filter='{}'".format(table[:-1], filter),
HTTPStatus.NOT_FOUND)
return None
- return {"deleted": rows.deleted_count}
+ return {"modified": rows.modified_count}
except Exception as e: # TODO refine
raise DbException(str(e))
except Exception as e: # TODO refine
raise DbException(str(e))
raise DbException("Not found any {} with filter='{}'".format(table[:-1], _filter),
HTTPStatus.NOT_FOUND)
return None
raise DbException("Not found any {} with filter='{}'".format(table[:-1], _filter),
HTTPStatus.NOT_FOUND)
return None
- return {"replace": rows.modified_count}
+ return {"replaced": rows.modified_count}
except Exception as e: # TODO refine
raise DbException(str(e))
except Exception as e: # TODO refine
raise DbException(str(e))
def file_delete(self, storage, ignore_non_exist=False):
pass
def file_delete(self, storage, ignore_non_exist=False):
pass
from http import HTTPStatus
from shutil import rmtree
from http import HTTPStatus
from shutil import rmtree
-from fsbase import FsBase, FsException
+from osm_common.fsbase import FsBase, FsException
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
from http import HTTPStatus
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
from http import HTTPStatus
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
from aiokafka import AIOKafkaConsumer
from aiokafka import AIOKafkaProducer
from aiokafka.errors import KafkaError
from aiokafka import AIOKafkaConsumer
from aiokafka import AIOKafkaProducer
from aiokafka.errors import KafkaError
-from msgbase import MsgBase, MsgException
-#import json
+from osm_common.msgbase import MsgBase, MsgException
+# import json
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>, " \
"Guillermo Calvino <guillermo.calvinosanchez@altran.com>"
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>, " \
"Guillermo Calvino <guillermo.calvinosanchez@altran.com>"
class MsgKafka(MsgBase):
def __init__(self, logger_name='msg'):
self.logger = logging.getLogger(logger_name)
class MsgKafka(MsgBase):
def __init__(self, logger_name='msg'):
self.logger = logging.getLogger(logger_name)
self.producer = AIOKafkaProducer(loop=loop, key_serializer=str.encode, value_serializer=str.encode,
bootstrap_servers=self.broker)
await self.producer.start()
self.producer = AIOKafkaProducer(loop=loop, key_serializer=str.encode, value_serializer=str.encode,
bootstrap_servers=self.broker)
await self.producer.start()
- await self.producer.send(topic=topic, key=key, value=msg)
+ await self.producer.send(topic=topic, key=key, value=yaml.safe_dump(msg, default_flow_style=True))
- raise MsgException("Error publishing to {} topic: {}".format(topic, str(e)))
+ raise MsgException("Error publishing topic '{}', key '{}': {}".format(topic, key, e))
finally:
await self.producer.stop()
finally:
await self.producer.stop()
raise MsgException(str(e))
finally:
await self.consumer.stop()
raise MsgException(str(e))
finally:
await self.consumer.stop()
import os
import yaml
import asyncio
import os
import yaml
import asyncio
-from msgbase import MsgBase, MsgException
+from osm_common.msgbase import MsgBase, MsgException
from time import sleep
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
"""
This emulated kafka bus by just using a shared file system. Useful for testing or devops.
from time import sleep
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
"""
This emulated kafka bus by just using a shared file system. Useful for testing or devops.
-One file is used per topic. Only one producer and one consumer is allowed per topic. Both consumer and producer
+One file is used per topic. Only one producer and one consumer is allowed per topic. Both consumer and producer
access to the same file. e.g. same volume if running with docker.
One text line per message is used in yaml format.
"""
access to the same file. e.g. same volume if running with docker.
One text line per message is used in yaml format.
"""
class MsgLocal(MsgBase):
def __init__(self, logger_name='msg'):
class MsgLocal(MsgBase):
def __init__(self, logger_name='msg'):
for f in self.files.values():
try:
f.close()
for f in self.files.values():
try:
f.close()
- except Exception as e: # TODO refine
+ except Exception: # TODO refine
pass
def write(self, topic, key, msg):
pass
def write(self, topic, key, msg):
raise
except Exception as e: # TODO refine
raise MsgException(str(e))
raise
except Exception as e: # TODO refine
raise MsgException(str(e))
here = os.path.abspath(os.path.dirname(__file__))
_name = "osm_common"
here = os.path.abspath(os.path.dirname(__file__))
_name = "osm_common"
README = open(os.path.join(here, 'README.rst')).read()
setup(
README = open(os.path.join(here, 'README.rst')).read()
setup(