Exemple #1
0
 def complete_delRel(self, text, line, begidx, endidx):
     """Provides tab completion data for delRel"""
     bline = core_parse(line[7:])
     btext = bline[-1]
     possibleMatches = []
     
     if len(bline) < 2:
         allClasses = Class.query.all()
         for Klass in allClasses:
             possibleMatches.append(Klass.name)
     else:
         allRels = Relationship.query.filter(bline[0] == Relationship.from_name).all()
         for Rel in allRels:
             possibleMatches.append(Rel.to_name)
     
     Matches = []
     for PM in possibleMatches:
         if PM.startswith(btext):
             tokens = btext.split(" ")
             PMTokens = PM.split(" ")
             
             while tokens[0] == PMTokens[0]:
                 tokens.pop(0)
                 PMTokens.pop(0)
                 
             
             Matches.append(" ".join(PMTokens))
             
     return Matches
Exemple #2
0
 def complete_addRel(self, text, line, begidx, endidx):
     """Provides tab completion data for addRel"""
     btext = core_parse(line[7:])[-1]
     allClasses = Class.query.all()
     allClassNames = []
     
     for Klass in allClasses:
         allClassNames.append(Klass.name)
         
     allClassNames.append("agg")
     allClassNames.append("comp")
     allClassNames.append("gen")
     allClassNames.append("none")
     
     ClassNames = []
     for Klass in allClassNames:
         if Klass.startswith(btext):
             tokens = btext.split(" ")
             classTokens = Klass.split(" ")
             
             while tokens[0] == classTokens[0]:
                 tokens.pop(0)
                 classTokens.pop(0)
                 
             
             ClassNames.append(" ".join(classTokens))
             
     return ClassNames
Exemple #3
0
 def complete_editAttr(self, text, line, begidx, endidx):
     """Provides tab completion data for editAttr"""
     bline = core_parse(line[8:])
     btext = bline[-1]
     possibleMatches = []
     
     if len(bline) < 2:
         allClasses = Class.query.all()
         for Klass in allClasses:
             possibleMatches.append(Klass.name)
     elif len(bline) == 2:
         allAttrs = Attribute.query.filter(bline[0] == Attribute.class_name).all()
         for Attr in allAttrs:
             possibleMatches.append(Attr.attribute)
     
     Matches = []
     for PM in possibleMatches:
         if PM.startswith(btext):
             tokens = btext.split(" ")
             PMTokens = PM.split(" ")
             
             while tokens[0] == PMTokens[0]:
                 tokens.pop(0)
                 PMTokens.pop(0)
                 
             
             Matches.append(" ".join(PMTokens))
             
     return Matches
Exemple #4
0
def index():
    """Deals with requests to the base index.

    On POST request, adds requested class and redirects
      to itself to re-render with updated data
    On GET request, renders the base index with current data
    """

    if request.method == 'POST':
        # form tag 'content'
        class_name = request.form['class_name']

        if class_name == '':
            return redirect('/')

        classList = core_parse(class_name)
        for class_ in classList:
            addCmd = add_class(class_)
            if cmd_stack.execute(addCmd):
                flash('ERROR: Unable to add class ' + class_, 'error')
        return redirect('/')

    else:
        # grab all entries in order
        classes = Class.query.order_by(Class.date_created).all()
        attributes = Attribute.query.order_by(Attribute.date_created).all()
        theme = Settings.query.get({"name":"theme"})
        if theme is None:
            theme = "Dark-Green"
        else:
            theme = theme.value

        athemes = populateThemes();
        return render_template('index.html', classes=classes, attributes=attributes, cmd_stack=cmd_stack, theme=theme, availThemes=athemes)
Exemple #5
0
def addAttributes(name, attrString, attrType):
    """Helper to add attributes to class."""
    attrList = core_parse(attrString)
    for attr in attrList:
        addAttrCmd = add_attr(name, attr, attrType)
        if cmd_stack.execute(addAttrCmd):
            flash('ERROR: Unable to add attribute ' + attr + " to " + name, 'error')
Exemple #6
0
 def do_delete(self, args):
     """Accepts a single class name OR a list separated by commas and removes them from the database.
 Usage: delete <class_name1>, <class_name2>, ... , <class_nameN>
 """
     argList = core_parse(args)
     if argList:
         for name in argList:
             deleteCmd = delete_class(name)
             if cmd_stack.execute(deleteCmd):
                 print('ERROR: Unable to delete class \'' + name + '\'')
             else:
                 print('Successfully deleted class \'' + name + '\'')
     else:
         print("Usage: delete <class_name1>, <class_name2>, ... , <class_nameN>")
Exemple #7
0
 def do_add(self, args):
     """Accepts a single class name OR a list separated by commas and adds them to the database.
 Usage: add <class_name1>, <class_name2>, ... , <class_nameN>
 """
     argList = core_parse(args)
     if argList:
         for name in argList:
             addCmd = add_class(name)
             if cmd_stack.execute(addCmd):
                 print('ERROR: Unable to add class \'' + name + '\'')
             else:
                 print('Successfully added class \'' + name + '\'')
     else:
         print("Usage: add <class_name1>, <class_name2>, ... , <class_nameN>")
Exemple #8
0
 def do_edit(self, args):
     """Accepts a single class name followed by a replacement name, separated by commas, and changes instances of old name in database with new name.
 Usage: edit <old_name>, <new_name>
 """
     argList = core_parse(args)
     if len(argList) == 2:
         old_name = argList.pop(0)
         new_name = argList.pop(0)
         editCmd = edit_class(old_name, new_name)
         if cmd_stack.execute(editCmd):
             print('ERROR: Unable to update class \'' + old_name + '\' to \'' + new_name + '\'')
         else:
             print('Successfully updated class \'' + old_name + '\' to \'' + new_name + '\'')
     else:
         print("Usage: edit <old_name>, <new_name>")
Exemple #9
0
 def do_delRel(self, args):
     """Accepts a single 'from' class name followed by a list of 'to' class names separated by commas and removes these relationships from the database.
 Usage: delRel <class_name>, <relationship1>, <relationship2>, ... , <relationshipN>
 """
     argList = core_parse(args)
     if len(argList) > 1:
         class_name = argList.pop(0)
         for rel in argList:
             rel_to_del = Relationship.query.get({"from_name":class_name, "to_name":rel})
             if rel_to_del is None or cmd_stack.execute(del_rel(class_name, rel, rel_to_del.rel_type)):
                 print('ERROR: Unable to delete relationship from \'' + class_name + '\' to \'' + rel + '\'')
             else:
                 print('Successfully deleted relationship from \'' + class_name + '\' to \'' + rel + '\'')
     else:
         print("Usage: delRel <class_name>, <relationship1>, <relationship2>, ... , <relationshipN>")
Exemple #10
0
 def do_delAttr(self, args):
     """Accepts a single class name followed by a list of attribute names separated by commas and removes them from the class.
 Usage: delAttr <class_name>, <attribute1>, <attribute2>, ... , <attributeN>
 """
     argList = core_parse(args)
     if len(argList) > 1:
         class_name = argList.pop(0)
         for attr in argList:
             attr_to_del = Attribute.query.get({"class_name":class_name, "attribute":attr})
             if attr_to_del is None or cmd_stack.execute(del_attr(class_name, attr, attr_to_del.attr_type)):
                 print('ERROR: Unable to delete attribute \'' + attr + '\'')
             else:
                 print('Successfully deleted attribute \'' + attr + '\'')
     else:
         print("Usage: delAttr <class_name>, <attribute1>, <attribute2>, ... , <attributeN>")
Exemple #11
0
 def do_editAttr(self, args):
     """Accepts a single class name followed by an existing attribute within and a new name which will replace said attribute in the class, all separated by commas.
 Usage: editAttr <class_name>, <old_attribute>, <new_attribute>
 """
     argList = core_parse(args)
     if len(argList) == 3:
         class_name = argList.pop(0)
         old_name = argList.pop(0)
         new_name = argList.pop(0)
         editAttrCmd = edit_attr(class_name, old_name, new_name)
         if cmd_stack.execute(editAttrCmd):
             print('ERROR: Unable to update attribute \'' + old_name + '\' to \'' + new_name + '\'')
         else:
             print('Successfully updated attribute \'' + old_name + '\' to \'' + new_name + '\'')
     else:
         print("Usage: editAttr <class_name>, <old_attribute>, <new_attribute>")
Exemple #12
0
 def do_addAttr(self, args):
     """Accepts a single class name and attribute type followed by a list of attribute names separated by commas and adds them to the class.
 Usage: addAttr <class_name>, <field/method>, <attribute1>, <attribute2>, ... , <attributeN>
 """
     argList = core_parse(args)
     if len(argList) > 2:
         class_name = argList.pop(0)
         attr_type = argList.pop(0).lower()
         if not attr_type in ["field", "method"]:
             print('ERROR: Invalid attribute type: ' + attr_type + "\n\tValid attribute types: field, method")
             return
         for attr in argList:
             addAttrCmd = add_attr(class_name, attr, attr_type)
             if cmd_stack.execute(addAttrCmd):
                 print('ERROR: Unable to add ' + attr_type + ' \'' + attr + '\'')
             else:
                 print('Successfully added ' + attr_type + ' \'' + attr + '\'')
     else:
         print("Usage: addAttr <class_name>, <field/method>, <attribute1>, <attribute2>, ... , <attributeN>")
Exemple #13
0
 def do_addRel(self, args):
     """Accepts a single 'from' class name and relationship type followed by a list of 'to' class names separated by commas and adds these relationships to the database.
 Usage: addRel <class_name>, <relationship type>, <relationship1>, <relationship2>, ... , <relationshipN>
     Valid relationship types: agg, comp, gen, none
 """
     argList = core_parse(args)
     if len(argList) > 2:
         class_name = argList.pop(0)
         rel_type = argList.pop(0).lower()
         if not rel_type in ["agg", "comp", "gen", "none"]:
             print('ERROR: Invalid relationship type: ' + rel_type + "\n  Valid relationship types: agg, comp, gen, none")
             return
         for rel in argList:
             addRelCmd = add_rel(class_name, rel, rel_type)
             if cmd_stack.execute(addRelCmd):
                 print('ERROR: Unable to add relationship from \'' + class_name + '\' to \'' + rel + '\' of type \'' + rel_type + '\'')
             else:
                 print('Successfully added relationship from \'' + class_name + '\' to \'' + rel + '\' of type \'' + rel_type + '\'')
     else:
         print("Usage: addRel <class_name>, <relationship type>, <relationship1>, <relationship2>, ... , <relationshipN>\n  Valid relationship types: agg, comp, gen, none")