version = '0.1.3'
-date_version = '2018-04-19'
\ No newline at end of file
+date_version = '2018-04-25'
import logging
-from dbbase import DbException, DbBase
+from osm_common.dbbase import DbException, DbBase
from http import HTTPStatus
from uuid import uuid4
from copy import deepcopy
if __name__ == '__main__':
# some test code
- db = dbmemory()
+ db = DbMemory()
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
-from dbbase import DbException, DbBase
+from osm_common.dbbase import DbException, DbBase
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})
- 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
- return {"deleted": rows.deleted_count}
+ return {"modified": rows.modified_count}
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
- return {"replace": rows.modified_count}
+ return {"replaced": rows.modified_count}
except Exception as e: # TODO refine
raise DbException(str(e))
def file_delete(self, storage, ignore_non_exist=False):
pass
-
import os
import logging
-import tarfile
+# import tarfile
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>"
-import asyncio
+# import asyncio
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 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>"
+
+
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()
- 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))
except Exception as e:
- 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()
raise MsgException(str(e))
finally:
await self.consumer.stop()
-
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.
-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.
"""
+
class MsgLocal(MsgBase):
def __init__(self, logger_name='msg'):
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):
raise
except Exception as e: # TODO refine
raise MsgException(str(e))
-
here = os.path.abspath(os.path.dirname(__file__))
_name = "osm_common"
-VERSION = "4.0.0rc1"
+VERSION = "4.0.0rc1"
README = open(os.path.join(here, 'README.rst')).read()
setup(