Commits

Santiago Payà Miralta  committed 0d5c0cd

Long str definitions pythonized.

  • Participants
  • Parent commits 5c4e69d

Comments (0)

Files changed (6)

File control/genet_browser.py

     @param level from which the node types are
     @returns list the node types
     """
-    if level == None:
+    if level is None:
         st = "SELECT description, id FROM gn____node_types;"
     else:
-        st = "SELECT description, id FROM gn____node_types " \
-            "WHERE level = " + str(level) + ";"
+        st = ("SELECT description, id FROM gn____node_types " 
+            "WHERE level = " + str(level) + ";")
     return db.query(st).getresult()
 
 def listEdgeTypes(level=None):
     @param level from which the edge types are
     @returns list the node types
     """
-    if level == None:
+    if level is None:
         st = "SELECT description, id FROM gn____edge_types;"
     else:
-        st = "SELECT description, id FROM gn____edge_types " \
-            "WHERE level = " + str(level) + ";"
+        st = ("SELECT description, id FROM gn____edge_types " 
+            "WHERE level = " + str(level) + ";")
     return db.query(st).getresult()
 
 def listNodes(level=None):
     """
     list_nodes = []
 
-    if level == None:
+    if level is None:
         st = "SELECT id FROM gn____levels;"
         list_levels = db.query(st).getresult()
         for i in list_levels:

File control/genet_creator.py

     @param description of the level.
     @returns queries statements and results.
     """
-    st = "INSERT INTO gn____levels(description) " \
-        "VALUES ('" + description + "') " \
-        "RETURNING id;"
+    st = ("INSERT INTO gn____levels(description) " 
+        "VALUES ('" + description + "') " 
+        "RETURNING id;")
     level = db.query(st).getresult()[0][0]
     tag_level = genet_global.tagName(level)
     
     
     # Drop all type tables in the level.
     # Edges.
-    st = "SELECT id " \
-        "FROM gn____edge_types " \
-        "WHERE level = " + level + ";"
+    st = ("SELECT id " 
+        "FROM gn____edge_types " 
+        "WHERE level = " + level + ";")
     ids = db.query(st).getresult()
     if len(ids):
         for i in ids:
             dropEdgeType(i[0])        
 
     # Nodes.
-    st = "SELECT id " \
-        "FROM gn____node_types " \
-        "WHERE level = " + level + ";"
+    st = ("SELECT id " 
+        "FROM gn____node_types " 
+        "WHERE level = " + level + ";")
     ids = db.query(st).getresult()
     if len(ids):
         for i in ids:
             dropNodeType(i[0])        
 
     # Delete entry into the levels table.
-    st = "DELETE FROM gn____levels " \
-        "WHERE id = " + level + ";"
+    st = ("DELETE FROM gn____levels " 
+        "WHERE id = " + level + ";")
     ret = ret, db.query(st)
     return ret
 
     @param level in which the new type is added.
     @param description of the type.
     """
-    st = "INSERT INTO gn____edge_types(level, description) " \
-        "VALUES (" + level + ", '" + description + "') " \
-        "RETURNING ID;"
+    st = ("INSERT INTO gn____edge_types(level, description) " 
+        "VALUES (" + level + ", '" + description + "') " 
+        "RETURNING ID;")
     id = db.query(st).getresult()[0][0]
     ret = st, id
 
     tag_id = genet_global.tagName(id)
     tablename = "gn_" + tag_level + "_edges_type_" + tag_id
 
-    st = "UPDATE gn____edge_types " \
-        "SET tablename = '" + tablename + "' " \
-        "WHERE id = " + str(id) + ";"
+    st = ("UPDATE gn____edge_types " 
+        "SET tablename = '" + tablename + "' " 
+        "WHERE id = " + str(id) + ";")
     ret = ret, st, db.query(st)
 
     # Create the table.
     """
     @param id the type id into the table.
     """
-    st = "SELECT tablename " \
-        "FROM gn____edge_types " \
-        "WHERE id = " + str(id) + ";"
+    st = ("SELECT tablename " 
+        "FROM gn____edge_types " 
+        "WHERE id = " + str(id) + ";")
     tablename = db.query(st).getresult()[0][0]
 
     # Drop the table.
     ret = db.query(st)
 
     # Delete entry into the types table.
-    st = "DELETE FROM gn____edge_types " \
-        "WHERE id = " + str(id) + ";"
+    st = ("DELETE FROM gn____edge_types " 
+        "WHERE id = " + str(id) + ";")
     ret = ret, db.query(st)
 
     return ret
     @param level in which the new type is added.
     @param description of the type.
     """
-    st = "INSERT INTO gn____node_types(level, description) " \
-        "VALUES (" + level + ", '" + description + "') " \
-        "RETURNING ID;"
+    st = ("INSERT INTO gn____node_types(level, description) " 
+        "VALUES (" + level + ", '" + description + "') " 
+        "RETURNING ID;")
     id = db.query(st).getresult()[0][0]
     ret = st, id
 
     tag_id = genet_global.tagName(id)
     tablename = "gn_" + tag_level + "_nodes_type_" + tag_id
 
-    st = "UPDATE gn____node_types " \
-        "SET tablename = '" + tablename + "' " \
-        "WHERE id = " + str(id) + ";"
+    st = ("UPDATE gn____node_types " 
+        "SET tablename = '" + tablename + "' " 
+        "WHERE id = " + str(id) + ";")
     ret = ret, st, db.query(st)
 
     # Create the table.
     """
     @param id the type id into the table.
     """
-    st = "SELECT tablename " \
-        "FROM gn____node_types " \
-        "WHERE id = " + str(id) + ";"
+    st = ("SELECT tablename " 
+        "FROM gn____node_types " 
+        "WHERE id = " + str(id) + ";")
     tablename = db.query(st).getresult()[0][0]
 
     # Drop the table.
     ret = db.query(st)
 
     # Delete entry into the types table.
-    st = "DELETE FROM gn____node_types " \
-        "WHERE id = " + str(id) + ";"
+    st = ("DELETE FROM gn____node_types " 
+        "WHERE id = " + str(id) + ";")
     ret = ret, db.query(st)
 
     return ret

File control/genet_global.py

     *** DANGER *** *** DANGER *** *** DANGER *** *** DANGER *** *** DANGER *** 
 
     """
-    st = "DROP SCHEMA public CASCADE;" \
-        "CREATE SCHEMA public AUTHORIZATION genet;"
+    st = ("DROP SCHEMA public CASCADE;" 
+        "CREATE SCHEMA public AUTHORIZATION genet;")
     ret = st, db.query(st)
     ret = ret, db_schema.fillSchema()
     return ret

File model/class_edge.py

         if self.id:
 
             # Update the edges table.
-            st1 = "UPDATE gn_" + tag_level + "_edges SET " \
-                "idnA = " + str(self.idnA) + ", " \
-                "idnB" + str(self.idnB) + ", " \
-                "idtype = " + str(self.idtype) + " " \
-                "WHERE id = " + str(self.id) + ";"
+            st1 = ("UPDATE gn_" + tag_level + "_edges SET " 
+                "idnA = " + str(self.idnA) + ", " 
+                "idnB" + str(self.idnB) + ", " 
+                "idtype = " + str(self.idtype) + " " 
+                "WHERE id = " + str(self.id) + ";")
             db.query(st1)
 
             # Update the tree table.
-            st2 = "UPDATE gn____tree SET " \
-                "idparent = " + str(self.idparent) + ", " \
-                "parentlevel = " + str(self.parentlevel) + ", " \
-                "childlevel = " + str(self.level) + " " \
-                "WHERE idchild = " + str(self.id) + ";"
+            st2 = ("UPDATE gn____tree SET " 
+                "idparent = " + str(self.idparent) + ", " 
+                "parentlevel = " + str(self.parentlevel) + ", " 
+                "childlevel = " + str(self.level) + " " 
+                "WHERE idchild = " + str(self.id) + ";")
             db.query(st2)
 
             return st1, st2, self.id
         else:
 
             # Insert the edge into the table.
-            st1 = "INSERT INTO gn_" + tag_level + "_edges(idna, idnb, idtype) " \
-                "VALUES(" \
-                + str(self.idnA) + ", " \
-                + str(self.idnB) + ", " \
-                + str(self.idtype) + ") " \
-                "RETURNING id;"
+            st1 = ("INSERT INTO gn_" + tag_level + "_edges(idna, idnb, idtype) " 
+                "VALUES(" 
+                + str(self.idnA) + ", " 
+                + str(self.idnB) + ", " 
+                + str(self.idtype) + ") " 
+                "RETURNING id;")
             self.id = db.query(st1).getresult()[0][0]
 
             # Insert the node into the tree.
-            st2 = "INSERT INTO gn____tree(idparent, idchild, parentlevel, childlevel) " \
-                "VALUES(" \
-                + str(self.idparent) + ", " \
-                + str(self.id) + ", " \
-                + str(self.parentlevel) + ", " \
-                + str(self.level) + ");" 
+            st2 = ("INSERT INTO gn____tree(idparent, idchild, "
+                   "parentlevel, childlevel) " 
+                "VALUES(" 
+                + str(self.idparent) + ", " 
+                + str(self.id) + ", " 
+                + str(self.parentlevel) + ", " 
+                + str(self.level) + ");")
             db.query(st2)
 
             return st1, st2, self.id

File model/class_node.py

         if self.id:
 
             # Update the nodes table.            
-            st1 = "UPDATE gn_" + tag_level + "_nodes SET " \
-                "idtype = " + str(self.idtype) + " " \
-                "WHERE id = " + str(self.id) + ";"
+            st1 = ("UPDATE gn_" + tag_level + "_nodes SET " 
+                "idtype = " + str(self.idtype) + " " 
+                "WHERE id = " + str(self.id) + ";")
             db.query(st1)
 
             # Update the tree table.
-            st2 = "UPDATE gn____tree SET " \
-                "idparent = " + str(self.idparent) + ", " \
-                "parentlevel = " + str(self.parentlevel) + ", " \
-                "childlevel = " + str(self.level) + " " \
-                "WHERE idchild = " + str(self.id) + ";"
+            st2 = ("UPDATE gn____tree SET " 
+                "idparent = " + str(self.idparent) + ", " 
+                "parentlevel = " + str(self.parentlevel) + ", " 
+                "childlevel = " + str(self.level) + " " 
+                "WHERE idchild = " + str(self.id) + ";")
             db.query(st2)
 
             return st1, st2, self.id
         else:
             
             # Insert the node into the table.
-            st1 = "INSERT INTO gn_" + tag_level + "_nodes(idtype) " \
-                "VALUES(" \
-                + str(self.idtype) + ") " \
-                "RETURNING id;"
+            st1 = ("INSERT INTO gn_" + tag_level + "_nodes(idtype) " 
+                "VALUES(" 
+                + str(self.idtype) + ") " 
+                "RETURNING id;")
             self.id = db.query(st1).getresult()[0][0]
 
             # Insert the node into the tree.
-            st2 = "INSERT INTO gn____tree(idparent, idchild, parentlevel, childlevel) " \
-                "VALUES (" \
-                + str(self.idparent) + ", " \
-                + str(self.id) + ", " \
-                + str(self.parentlevel) + ", " \
-                + str(self.level) + ");" 
+            st2 = ("INSERT INTO gn____tree(idparent, idchild, "
+                   "parentlevel, childlevel) " 
+                "VALUES (" 
+                + str(self.idparent) + ", " 
+                + str(self.id) + ", " 
+                + str(self.parentlevel) + ", " 
+                + str(self.level) + ");")
             db.query(st2)
 
             return st1, st2, self.id

File view/genet_window.py

 
 """
 
-## TODO My emacs needs this once
+## TODO My emacs needs this
 import sys
 sys.path.append('/home/santiago/workspace/genet')
 ##
         tree_model = tree.get_model()
         tree_model.reload()
 
-    def button_drop_item_clicked(self, widget):
-        values = self.get_admin_tree_selected_values()
-
-        values_id = values[1]
-        values_type = values[2]
-
-        # TODO raise errors
-        if values_type == "Edge":
-            genet_creator.dropEdgeType(values_id)
-        elif values_type == "Node":
-            genet_creator.dropNodeType(values_id)
-        else:
-            genet_creator.dropLevel(values_id)
-
-        # TODO Refresh tree without forget selection
-        tree = self.wTree.get_widget("treeview_admin_levels")
-        tree_model = tree.get_model()
-        tree_model.reload()
-
     def button_create_node_type_clicked(self, widget):
         # Get level
         level = self.get_admin_tree_level()
         tree_model = tree.get_model()
         tree_model.reload()
 
+    def button_drop_item_clicked(self, widget):
+        values = self.get_admin_tree_selected_values()
+
+        values_id = values[1]
+        values_type = values[2]
+
+        if values_type == "Edge":
+            genet_creator.dropEdgeType(values_id)
+        elif values_type == "Node":
+            genet_creator.dropNodeType(values_id)
+        elif values_type == "":
+            genet_creator.dropLevel(values_id)
+        else:
+            # TODO raise errors
+            pass
+
+        # TODO Refresh tree without forget selection
+        tree = self.wTree.get_widget("treeview_admin_levels")
+        tree_model = tree.get_model()
+        tree_model.reload()
+
     def button_admin_reset_clicked(self, widget):
         genet_global.restartDatabase()
         
-        # TODO Refresh the combo when touched.    
-        self.button_admin_refresh_clicked(None)
+        # TODO Refresh tree without forget selection
+        tree = self.wTree.get_widget("treeview_admin_levels")
+        tree_model = tree.get_model()
+        tree_model.reload()
 
     def get_admin_tree_level(self):
         # Get all information from the selected row in the tree
         
         # Get if selection has a parent or if it is the parent
         parent_iter = tree_selection_model.iter_parent(tree_selection_iter)
-        if parent_iter == None:
+        if parent_iter is None:
             values = tree_selection_model.get(tree_selection_iter, 0, 1, 2)
             level = values[1]
         else: