summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-04-16 10:42:24 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-04-16 10:42:24 +0200
commit9e4e6b7727df521bd187ca209e2a0ebc10f4a382 (patch)
tree6598f7c232391db821456e55b12ef4b71c0e3a68
parent188d0883ef4eda09da91cfa6e4cffd583dd999ac (diff)
downloadtodolist-9e4e6b7727df521bd187ca209e2a0ebc10f4a382.tar.gz
todolist-9e4e6b7727df521bd187ca209e2a0ebc10f4a382.tar.xz
todolist-9e4e6b7727df521bd187ca209e2a0ebc10f4a382.zip
first trys
-rw-r--r--.gitignore1
-rw-r--r--item.py29
-rw-r--r--itemList.py28
-rw-r--r--storage/__init__.py0
-rw-r--r--storage/factory.py5
-rw-r--r--storage/sqlite.py17
-rw-r--r--storage/storageBase.py11
-rwxr-xr-xtodolist.py27
8 files changed, 118 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/item.py b/item.py
new file mode 100644
index 0000000..c2accaa
--- /dev/null
+++ b/item.py
@@ -0,0 +1,29 @@
+class item:
+ readOnly = ['id']
+
+ def __init__(self, title, created, priority):
+ self.id = -1
+ self.title = title
+ self.created = created
+ self.priority = priority
+
+ def setId(self, id):
+ if self.id == -1:
+ self.id = id
+
+ def getTitle(self):
+ return self.title
+
+ def getCreatedAt(self):
+ return self.created
+
+ def getPriority(self):
+ return self.priority
+
+ def __setattr__(self, name, value):
+ if name not in item.readOnly:
+ if name not in self.__dict__ or self.__dict__[name] != value:
+ self.__dict__[name] = value
+
+ if 'observer' in self.__dict__:
+ self.observer.notifyChange(self)
diff --git a/itemList.py b/itemList.py
new file mode 100644
index 0000000..527c837
--- /dev/null
+++ b/itemList.py
@@ -0,0 +1,28 @@
+class itemList:
+ def __init__(self, observer):
+ self.data = []
+ self.observer = observer
+
+ def __len__(self):
+ return len(self.data)
+
+ def __getitem__(self, idx):
+ return self.data[idx]
+
+ def __setitem__(self, idx, item):
+ self.data[idx] = item
+
+ def append(self, item):
+ item.observer = self
+ self.data.append(item)
+ self.observer.notifyChange(item)
+
+ def notifyChange(self, sender):
+ self.observer.notifyChange(sender)
+
+ def __add__(self, item):
+ self.append(item)
+ return self
+
+ def __iter__(self):
+ return self.data.__iter__()
diff --git a/storage/__init__.py b/storage/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/storage/__init__.py
diff --git a/storage/factory.py b/storage/factory.py
new file mode 100644
index 0000000..c1fa049
--- /dev/null
+++ b/storage/factory.py
@@ -0,0 +1,5 @@
+from sqlite import *
+
+def getStorage():
+ x = sqlite()
+ return x
diff --git a/storage/sqlite.py b/storage/sqlite.py
new file mode 100644
index 0000000..8a24858
--- /dev/null
+++ b/storage/sqlite.py
@@ -0,0 +1,17 @@
+from storageBase import storageBase
+from itemList import itemList
+from pysqlite2 import dbapi2 as sqliteBackend
+
+class sqlite(storageBase):
+ def __init__(self):
+ self.con = sqliteBackend.connect(self.getConfigDir() + '/data.sqlite')
+
+ def __del__(self):
+ self.con.close()
+
+ def load(self):
+ return itemList(self)
+
+ def notifyChange(self, sender):
+ print '%s %s' % ('Save changes:', sender.getCreatedAt())
+ return
diff --git a/storage/storageBase.py b/storage/storageBase.py
new file mode 100644
index 0000000..24abd2c
--- /dev/null
+++ b/storage/storageBase.py
@@ -0,0 +1,11 @@
+import os
+
+class storageBase:
+ def notifyChange(self, sender): abstract
+
+ def getConfigDir(self):
+ dir = os.path.expanduser('~/.todolist/blub')
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+
+ return dir
diff --git a/todolist.py b/todolist.py
new file mode 100755
index 0000000..141f5d1
--- /dev/null
+++ b/todolist.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import storage.factory
+import item
+
+from time import time
+
+def main():
+ store = storage.factory.getStorage()
+ items = store.load()
+ items += item.item("Test1", time(), 0)
+ items += item.item("Test1", time(), 0)
+ items += item.item("Test1", time(), 0)
+
+ for i in items:
+ print i.getTitle()
+ print i.getCreatedAt()
+ print i.getPriority()
+ print '========================================'
+
+ items[len(items)-1].id = 'new Title'
+ items[len(items)-1].id = 'new Title'
+
+ return
+
+if __name__ == '__main__':
+ main()