Commits

Yuriy Netesov committed f9c7e67

[tagjumper::tagsystem] moved to elixir from pure sqlalchemy

Comments (0)

Files changed (7)

-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()
+    dbUri = "mysql://root:QAZxsw123@localhost/tags"
+    def __init__(self) : pass
 #
 
 import sys
-sys.path.append('..')
-import string
-from tagsystem import TagSystem
 
-tagSys = TagSystem()
+from config import config
+from tagsystem.tagsystem import TagSystem
+
+tagSys = TagSystem(config.dbUri)
 
 def jump_command(args):
     print 'jumping over tag'
 
 def tag_command(args):
     print 'tagging place'
-    pass
+
 
 def untag_command(args):
     print 'untagging place'
-    pass
+
 
 def rename_tag_command(args):
-    print ''
-    pass
+    print 'rename tag command'
 
 def call_command(args):
     commands = {'jmp' : jump_command,

tagsystem/dbconnection.py

-from tagjumper.config import globalConfig
-import sqlalchemy
+from elixir import metadata
 
-_connection = None
+class DbConnection:
+    @staticmethod
+    def bind(url):
+        metadata.bind = url
 
-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()
-    
-    
+    def __init__(self):
+        pass

tagsystem/payload.py

-class PayloadModel:
-    pass
+import elixir
 
-class Payload:
-    def __init__(self, model, tagSystem):
-        self._model = model
-        self._tags = tags
+class Payload(elixir.Entity):
+    data = elixir.Field(elixir.Unicode(1024))
+    tags = elixir.OneToMany('Tag')
 
-    def tag(self, tagName):
-        self._tags.touch(tagName)
-        self._model
+    def tag(self, tag):
+        self.tags.append(tag)
+
         
-import sqlalchemy
+import elixir
 
-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
-
-    def get_name(self):
-        return self._model.name
-
-    def rename(self, newName):
-        self._model.name = newName
-        self._model.save()
+class Tag(elixir.Entity):
+    name = elixir.Field(elixir.Unicode(256))
+    payloads = elixir.ManyToOne('Payload')

tagsystem/tags.py

-from tagsystem.tag import Tag, TagModel
-from tagsystem.dbconnection import get_db_connection
-import sqlalchemy
+from tag import Tag 
 
 class Tags:
-    def __init__(self, tagsystem):
-        self._tagsystem = tagsystem
-        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 __init__(self):
+        pass
 
     def touch(self, tagName):
-        tagModel = TagModel(tagName)
-        tagModel.save()
+#        if Tag.query.
+        pass
 
     def get(self, tagName):
-        session = sqlalchemy.create_session()
-        tagModel = session.query(TagModel).selectfirst(self._tagsTable.c.name==tagName)
-        return Tag(tagModel)
-        
+        touch(tagName)
+        return Tag.get_by(name=tagName)
 
-#    def get_similar(self, tagName):
-#        pass

tagsystem/tagsystem.py

+import elixir
 from tags import Tags
 from payloads import Payloads
+from dbconnection import DbConnection 
 
-def TagSystem:
-    def __init__(self):
-        self._tags = Tags(self)
-        self._payloads = Payloads(self)
+class TagSystem:
+    def __init__(self, dburl):
+        DbConnection.bind(dburl)
+        self._tags = Tags()
+        self._payloads = Payloads()
+        elixir.setup_all()
+        elixir.create_all()
+
+    def _tag_payload(self, payloadData, tagsNames):
+        payload = self._payloads.touch_payload(payloadData)
+        for tagName in tagsNames:
+            payload.tag(self._tags.get(tagName))
+
+    def tag_payloads(self, tags, payloads):
+        
+        """ tags multiply payloads with multiply tags """
+        #TODO : implement me
+        pass
+
+    def untag_payloads(self, tags, palyloads):
+        """ toggle tags off on specified payloads """
+        #TODO : implement me
+        pass
+
+    def rename_tag(self, tag, newName):
+        """ renames specified tag with newName """
+        #TODO : implement me
+        pass
+
+    def jump_tags(self, tags):
+        """ return list of payloads relevant to tags """
+        #TODO : implement me
+        pass