From: tierno Date: Wed, 25 Apr 2018 14:59:53 +0000 (+0200) Subject: fixing imports to get ready for module distribution. X-Git-Tag: v4.0.0~18 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fcommon.git;a=commitdiff_plain;h=3054f783ac759b221233fd0a82424aa105e4ea2e fixing imports to get ready for module distribution. fixing errors detected with flake8 Change-Id: Ib99df43fd5f86ccbb3e35111972a2075e7a956dd Signed-off-by: tierno --- diff --git a/osm_common/__init__.py b/osm_common/__init__.py index df7b893..30a016f 100644 --- a/osm_common/__init__.py +++ b/osm_common/__init__.py @@ -1,2 +1,2 @@ version = '0.1.3' -date_version = '2018-04-19' \ No newline at end of file +date_version = '2018-04-25' diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index cdb0482..c27f846 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -1,5 +1,5 @@ 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 @@ -114,7 +114,7 @@ class DbMemory(DbBase): 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}) diff --git a/osm_common/dbmongo.py b/osm_common/dbmongo.py index 582773a..9e34920 100644 --- a/osm_common/dbmongo.py +++ b/osm_common/dbmongo.py @@ -1,7 +1,7 @@ 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 @@ -167,12 +167,12 @@ class DbMongo(DbBase): 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)) @@ -186,6 +186,6 @@ class DbMongo(DbBase): 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)) diff --git a/osm_common/fsbase.py b/osm_common/fsbase.py index 7b6cd0c..60c0c0f 100644 --- a/osm_common/fsbase.py +++ b/osm_common/fsbase.py @@ -40,4 +40,3 @@ class FsBase(object): def file_delete(self, storage, ignore_non_exist=False): pass - diff --git a/osm_common/fslocal.py b/osm_common/fslocal.py index b7dd839..202872d 100644 --- a/osm_common/fslocal.py +++ b/osm_common/fslocal.py @@ -1,9 +1,9 @@ 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 " diff --git a/osm_common/msgbase.py b/osm_common/msgbase.py index 25e8c80..a9d44d7 100644 --- a/osm_common/msgbase.py +++ b/osm_common/msgbase.py @@ -1,5 +1,5 @@ -import asyncio +# import asyncio from http import HTTPStatus __author__ = "Alfonso Tierno " diff --git a/osm_common/msgkafka.py b/osm_common/msgkafka.py index c819c81..71e4948 100644 --- a/osm_common/msgkafka.py +++ b/osm_common/msgkafka.py @@ -4,11 +4,13 @@ import yaml 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 , " \ "Guillermo Calvino " + + class MsgKafka(MsgBase): def __init__(self, logger_name='msg'): self.logger = logging.getLogger(logger_name) @@ -67,9 +69,9 @@ class MsgKafka(MsgBase): 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() @@ -104,4 +106,3 @@ class MsgKafka(MsgBase): raise MsgException(str(e)) finally: await self.consumer.stop() - diff --git a/osm_common/msglocal.py b/osm_common/msglocal.py index c774f85..bfa30b7 100644 --- a/osm_common/msglocal.py +++ b/osm_common/msglocal.py @@ -2,18 +2,19 @@ import logging 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 " """ 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'): @@ -41,7 +42,7 @@ class MsgLocal(MsgBase): 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): @@ -108,4 +109,3 @@ class MsgLocal(MsgBase): raise except Exception as e: # TODO refine raise MsgException(str(e)) - diff --git a/setup.py b/setup.py index 4a0749f..7dbb828 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup 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(