Rfaulk has submitted this change and it was merged.

Change subject: add. FileBroker definition.
......................................................................


add. FileBroker definition.

Change-Id: I2aa2ef18d590f357baf8285f6a0340b538912254
---
M user_metrics/api/broker.py
1 file changed, 43 insertions(+), 0 deletions(-)

Approvals:
  Rfaulk: Verified; Looks good to me, approved



diff --git a/user_metrics/api/broker.py b/user_metrics/api/broker.py
index 72e97a1..35243d8 100644
--- a/user_metrics/api/broker.py
+++ b/user_metrics/api/broker.py
@@ -10,6 +10,10 @@
 __license__ = "GPL (version 2 or later)"
 
 
+import json
+import os
+
+
 class Broker(object):
     """
     Base class for broker
@@ -22,10 +26,49 @@
         raise NotImplementedError()
 
     def add(self, target, key, value):
+        """
+        Add a key/value pair to the broker
+        """
         raise NotImplementedError()
 
     def remove(self, target, key):
+        """
+        Remove a key/value pair to the broker
+        """
         raise NotImplementedError()
 
     def get(self, target, key):
+        """
+        Retrieve a key/value pair to the broker
+        """
         raise NotImplementedError()
+
+
+class FileBroker(Broker):
+    """
+    Implements a broker that uses a flat file as a broker
+    """
+
+    def __init__(self, **kwargs):
+        super(FileBroker, self).__init__(**kwargs)
+
+    def compose(self):
+        pass
+
+    def add(self, target, key, value):
+        """
+        Adds key/value pair
+        """
+        if os.path.isfile(target):
+            mode = 'a'
+        else:
+            mode = 'w'
+
+        with open(target, mode) as f:
+            f.write(json.dumps({key: value}) + '\n')
+
+    def remove(self, target, key):
+        pass
+
+    def get(self, target, key):
+        pass

-- 
To view, visit https://gerrit.wikimedia.org/r/72689
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2aa2ef18d590f357baf8285f6a0340b538912254
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: repair_runtime
Gerrit-Owner: Rfaulk <[email protected]>
Gerrit-Reviewer: Rfaulk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to