From 361cd41a8bd03e133ce01963bcfdf6ce0319f3da Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Mon, 22 Aug 2011 13:37:04 +0300 Subject: [PATCH] ppf: Add SwarmWriter class. --- ppf/new/storage.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ppf/new/storage.py b/ppf/new/storage.py index f771f00..cb47b5f 100644 --- a/ppf/new/storage.py +++ b/ppf/new/storage.py @@ -579,3 +579,42 @@ class MySQLDatabaseAccess(DatabaseAccess): def add_verbose_message(self, msg): pass + +class SwarmWriter(object): + """ + Wrapper class for swarm storage write actions. Multiple *Access + objects may be added to the clas resulting in multiple storage types. + For example, adding a swarm could result in + * adding a table entry in a MySQL database (MySQLDatabaseAccess) + * adding a table entry in an SQLite database (SQLiteDatabaseAccess) + * adding a new folder in a tree structure (TreeTextFileAccess) + """ + + def __init__(self): + handlers = [] + + def add_access_handle(self, handle): + handlers.append(handle) + + def remove_access_handle(self, handle): + handlers.remove(handle) + + def add_swarm(self, swarm): + for h in handlers: + h.add_swarm(swarm) + + def add_client_session(self, session): + for h in handlers: + h.add_client_session(swarm) + + def add_peer_status_message(self, msg): + for h in handlers: + h.add_peer_status_message(swarm) + + def add_status_message(self, msg): + for h in handlers: + h.add_status_message(swarm) + + def add_verbose_message(self, msg): + for h in handlers: + h.add_verbose_message(swarm) -- 2.20.1