fixing imports to get ready for module distribution. 27/6027/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 25 Apr 2018 14:59:53 +0000 (16:59 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 25 Apr 2018 14:59:53 +0000 (16:59 +0200)
fixing errors detected with flake8

Change-Id: Ib99df43fd5f86ccbb3e35111972a2075e7a956dd
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_common/__init__.py
osm_common/dbmemory.py
osm_common/dbmongo.py
osm_common/fsbase.py
osm_common/fslocal.py
osm_common/msgbase.py
osm_common/msgkafka.py
osm_common/msglocal.py
setup.py

index df7b893..30a016f 100644 (file)
@@ -1,2 +1,2 @@
 version = '0.1.3'
 version = '0.1.3'
-date_version = '2018-04-19'
\ No newline at end of file
+date_version = '2018-04-25'
index cdb0482..c27f846 100644 (file)
@@ -1,5 +1,5 @@
 import logging
 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
 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
 
 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})
     db.create("test", {"_id": 1, "data": 1})
     db.create("test", {"_id": 2, "data": 2})
     db.create("test", {"_id": 3, "data": 3})
index 582773a..9e34920 100644 (file)
@@ -1,7 +1,7 @@
 
 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
 
@@ -167,12 +167,12 @@ class DbMongo(DbBase):
         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))
 
@@ -186,6 +186,6 @@ class DbMongo(DbBase):
                     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))
index 7b6cd0c..60c0c0f 100644 (file)
@@ -40,4 +40,3 @@ class FsBase(object):
 
     def file_delete(self, storage, ignore_non_exist=False):
         pass
 
     def file_delete(self, storage, ignore_non_exist=False):
         pass
-
index b7dd839..202872d 100644 (file)
@@ -1,9 +1,9 @@
 import os
 import logging
 import os
 import logging
-import tarfile
+import tarfile
 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>"
 
index 25e8c80..a9d44d7 100644 (file)
@@ -1,5 +1,5 @@
 
 
-import asyncio
+import asyncio
 from http import HTTPStatus
 
 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 from http import HTTPStatus
 
 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
index c819c81..71e4948 100644 (file)
@@ -4,11 +4,13 @@ import yaml
 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)
@@ -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()
             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:
         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()
 
         finally:
             await self.producer.stop()
 
@@ -104,4 +106,3 @@ class MsgKafka(MsgBase):
             raise MsgException(str(e))
         finally:
             await self.consumer.stop()
             raise MsgException(str(e))
         finally:
             await self.consumer.stop()
-
index c774f85..bfa30b7 100644 (file)
@@ -2,18 +2,19 @@ import logging
 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'):
@@ -41,7 +42,7 @@ class MsgLocal(MsgBase):
         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):
@@ -108,4 +109,3 @@ class MsgLocal(MsgBase):
             raise
         except Exception as e:  # TODO refine
             raise MsgException(str(e))
             raise
         except Exception as e:  # TODO refine
             raise MsgException(str(e))
-
index 4a0749f..7dbb828 100644 (file)
--- 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"
 
 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(
 README = open(os.path.join(here, 'README.rst')).read()
 
 setup(