Commits

Yuriy Netesov committed ecd4629

[tagjumper] scratched architercture

Comments (0)

Files changed (9)

+import os
+
+class config:
+    def __init__(self):
+        dbdir =  "%(homedir)/.tagjumper" % {'homedir' : os.getenv('HOME')}
+        os.mkdir(dbdir)
+        self.dbUri = "sqlite://%(dbdir)/tags.db" % {'dbdir' : dbdir}
+        self.isDebugEnabled = True
+
+globalConfig = config()
+#
+# tagit - edit tags for destination
+#
+
+def main():
+    pass
+
+if __name__ == '__main__':
+    main()
+#
+# tagj - tag jumper
+#
+
+def main():
+    pass
+
+if __name__ == '__main__':
+    main()

tagsystem/__init__.py

+

tagsystem/dbconnection.py

+from tagjumper.config import globalConfig
+import sqlalchemy
+
+_connection = None
+
+def _init_connection():
+    connection = sqlalchemy.create_engine(globalConfig.dbUri)
+    connection.echo = globalConfig.isDebugEnabled
+
+def get_db_connection():
+    if (_connection):
+        return _connection
+    _connection = _init_connection()
+    return get_connection()
+    
+    

tagsystem/payload.py

+class PayloadModel:
+    pass
+
+class Payload:
+    def __init__(self, model, tags):
+        self._model = model
+        self._tags = tags
+
+    def tag(self, tagName):
+        
+import sqlalchemy
+
+class TagModel:
+    def __init__(self, name):
+        self.name = name
+
+    def save(self):
+        session = sqlalchemy.create_session()
+        session.save(self)
+        session.flush()
+
+class Tag:
+    def __init__(self, model):
+        self._model = model

tagsystem/tags.py

+from tagjumper.tagsystem.tag import Tag, TagModel
+from tagjumper.tagsystem.dbconnection import get_db_connection
+import sqlalchemy
+
+class Tags:
+    def __init__(self):
+        self._touch_table()
+        metadata = sqlalchemy.BoundMetaData(get_db_connection())
+        self._tagsTable = sqlalchemy.Table('tags', metadata, autoload=True)
+        self._tags_mapper = sqlalchemy.mapper(TagModel, self._tagsTable)
+
+    def _touch_table(self):
+        metadata = sqlalchemy.BoundMetaData(get_db_connection())
+        tagsTable = sqlalchemy.Table('tags', metadata,
+                                     sqlalchemy.Column('tag_id', sqlalchemy.Integer, primary_key=True),
+                                     sqlalchemy.Column('name', sqlalchemy.String))
+        tagsTable.create()
+
+    def touch(self, tagName):
+        tagModel = TagModel(tagName)
+        tagModel.save()
+
+    def get(self, tagName):
+        session = sqlalchemy.create_session()
+        tagModel = session.query(TagModel).selectfirst(self._tagsTable.c.name==tagName)
+        return Tag(tagModel)
+        
+
+#    def get_similar(self, tagName):
+#        pass

tagsystem/tagsystem.py

+from tags import Tags
+from payloads import Payloads
+
+def TagSystem:
+