summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomek Dubrownik <t.dubrownik@gmail.com>2011-11-08 15:58:52 +0100
committerTomek Dubrownik <t.dubrownik@gmail.com>2011-11-08 15:58:52 +0100
commit44057288e77eca8dcfae9e6a906ae0428f37e228 (patch)
tree5128aac1c73d963346e900eb05f695cf1e936147
parent6abec97b0955d75f9dd253c6c71814244adbe47b (diff)
parent94a71cd3db7518884acca0f9ff4c4aa9a52f4dc5 (diff)
downloaddoorman-44057288e77eca8dcfae9e6a906ae0428f37e228.tar.gz
doorman-44057288e77eca8dcfae9e6a906ae0428f37e228.tar.bz2
doorman-44057288e77eca8dcfae9e6a906ae0428f37e228.tar.xz
doorman-44057288e77eca8dcfae9e6a906ae0428f37e228.zip
Merge branch 'minefield' of github.com:tdubrownik/doorman
-rw-r--r--README.md6
-rw-r--r--admin/lib/csvstore.py21
-rw-r--r--admin/lib/jsonstore.py11
-rw-r--r--admin/lib/storage.py14
4 files changed, 39 insertions, 13 deletions
diff --git a/README.md b/README.md
index 50081d9..7e0a445 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,8 @@
+# THIS IS A DEV BRANCH, ***DO NOT*** USE IT! #
+
**Hackerspace.pl** door management software.
* *arduino* is the Arduino hardware implementation of the current protocol.
-* *admin* the Python implementation of the management system of the current protocol. \ No newline at end of file
+* *admin* the Python implementation of the management system of the current protocol.
+
+### TWILIGHT IS BEST PONY ### \ No newline at end of file
diff --git a/admin/lib/csvstore.py b/admin/lib/csvstore.py
index c0087a9..c4c882c 100644
--- a/admin/lib/csvstore.py
+++ b/admin/lib/csvstore.py
@@ -1,19 +1,28 @@
-import csv
-
+import StringIO
from UserDict import IterableUserDict
+import csv
+
class Storage(IterableUserDict):
- def __init__(self, name):
- self.filename = name
+ def __init__(self, file):
+ self.encapsulation = encapsulation
+ self.encapsulation.begin_transaction()
try:
stored = {x[0]: [x[1], x[2]]
- for x in csv.reader(open(name))}
+ for x in csv.reader([self.encapsulation.data])}
except IOError:
stored = {}
IterableUserDict.__init__(self, stored)
def sync(self):
- csv.writer(open(self.filename, 'w')).writerows(
+ f = StringIO.StringIO()
+ csv.writer(f).writerows(
[c, u, name] for c, (u, name) in self.data.iteritems())
+
+ self.encapsulation.data = f.getvalue()
+ self.encapsulation.end_transaction()
+ f.close()
+
+ self.encapsulation.begin_transaction()
def __del__(self):
self.sync()
def __setitem__(self, k, v):
diff --git a/admin/lib/jsonstore.py b/admin/lib/jsonstore.py
index bdedf13..48dcc9e 100644
--- a/admin/lib/jsonstore.py
+++ b/admin/lib/jsonstore.py
@@ -3,10 +3,11 @@ import json
from UserDict import IterableUserDict
class Storage(IterableUserDict):
- def __init__(self, name, **kw):
- self.filename = name
+ def __init__(self, encapsulation):
+ self.encapsulation = encapsulation
+ self.encapsulation.begin_transaction()
try:
- stored = json.load(open(name))
+ stored = json.loads(self.encapsulation.data)
except IOError:
stored = {}
IterableUserDict.__init__(self, stored)
@@ -19,4 +20,6 @@ class Storage(IterableUserDict):
def __del__(self):
self.sync()
def sync(self):
- json.dump(self.data, open(self.filename, 'w'), indent=4)
+ self.encapsulation.data = json.dumps(self.data, indent=4)
+ self.encapsulation.end_transaction()
+ self.encapsulation.begin_transaction()
diff --git a/admin/lib/storage.py b/admin/lib/storage.py
index 9489e37..5627ff7 100644
--- a/admin/lib/storage.py
+++ b/admin/lib/storage.py
@@ -3,13 +3,23 @@ import shelve
import csvstore
import jsonstore
import options
+import storage_encapsulation
+
+if options.storage_encrypt == True
+ encapsulation_class = storage_encapsulation.DESFileEncapsulation
+else:
+ encapsulation_class = storage_encapsulation.RawFileEncapsulation
if options.storage == 'shelve':
+ if options.storage_encrypt == True:
+ raise NotImplementedError("Who the fuck uses Shelve anyway.")
storage = shelve.open(options.shelf)
if options.storage == 'json':
- storage = jsonstore.Storage(options.json)
+ encapsulation = encapsulation_class(options.json)
+ storage = jsonstore.Storage(encapsulation)
if options.storage == 'csv':
- storage = csvstore.Storage(options.csv)
+ encapsulation = encapsulation_class(options.csv)
+ storage = csvstore.Storage(encapsulation)
nobody = (None, '-unknown-')