コード例 #1
0
ファイル: Parser.py プロジェクト: visavis2k/accords-platform
    def __init__(self, files):
        '''
        Constructor
            @param files: list of files to parse
        '''
        self.files = files
        self.cats = Category.Categories()
        self.models = Model.Models()

        # Add the standard categories from OCCI Core
        self._built_in_model = Model.Model("core", "OCCI Core categories",
                                           "1.0,0")
        self.models.add(self._built_in_model)
        # Entity
        entity = Category.Category("entity",
                                   "http://schemas.ogf.org/occi/core#",
                                   "/entity/", None, "kind",
                                   self._built_in_model)
        entity.addattr(
            Attribute.Attribute("id", "string", "true", "true", None, "true"))
        entity.addattr(
            Attribute.Attribute("title", "string", "false", "false", None,
                                "false"))
        self.cats.add(entity)

        # Resource
        resource = Category.Category(
            "resource", "http://schemas.ogf.org/occi/core#", "/resource/",
            "http://schemas.ogf.org/occi/core#entity", "kind",
            self._built_in_model)
        resource.addattr(
            Attribute.Attribute("summary", "string", "false", "false", None,
                                "false"))
        self.cats.add(resource)

        # Link
        link = Category.Category("link", "http://schemas.ogf.org/occi/core#",
                                 "/link/",
                                 "http://schemas.ogf.org/occi/core#entity",
                                 "link", self._built_in_model)
        link.addattr(
            Attribute.Attribute("source", "string", "true", "false", None,
                                "false"))
        link.addattr(
            Attribute.Attribute("target", "string", "true", "false", None,
                                "false"))
        self.cats.add(link)
        self.parsers = ParserCollection()
コード例 #2
0
ファイル: Parser.py プロジェクト: visavis2k/accords-platform
    def _addattrs(self, category, cat):
        '''
        Parse and add all attributes to a category
            @param category: a collection of XML Elements
            @param cat: the Category to add the collections to
        '''
        # Parse attributes
        for attr in category.findall("attributes/attribute"):
            name = attr.get("name")
            if name == None:
                logging.warn("Category" + cat.term + " - invalid attribute")
                continue
            logging.info("Category " + cat.term + " attribute " + name)
            try:
                cat.addattr(
                    Attribute.Attribute(name, attr.get("type"),
                                        attr.get("required"),
                                        attr.get("immutable"),
                                        attr.get("validation"),
                                        attr.get("index"), attr.get("default"),
                                        attr.get("units"),
                                        attr.get("legacytype"),
                                        attr.get("scope"), attr.get("script")))
            except:
                logging.error("Category " + cat.term +
                              "Problem processing attribute " + id)
                logging.error(sys.exc_info())

        # Parse instances
        colls = category.findall("attributes/instance")
        self._addcoll(colls, cat)

        # Parse collections
        colls = category.findall("attributes/collection")
        self._addcoll(colls, cat)
コード例 #3
0
    def __init__(self, string, know_final_class):
        self.final_class = None
        self.attributeList = []

        #replace all of the non attribute characters in the string read in from
        #the .txt data file
        string = string.replace("\n", "")
        string = string.replace(",", "")

        #if we know the final classification (the first character on the string)
        #remove it and store in the final_class data variable
        if know_final_class:
            self.final_class = string[0]
            l = list(string)
            l[0] = ""
            string = "".join(l)
            for char in string:
                #make attribues and add them to the entities attributeList
                self.attributeList.append(Attribute(char))
        else:
            #make attributes from string and add them to the entities attributeList
            for char in string:
                self.attributeList.append(Attribute(char))
コード例 #4
0
class IVersionFolder(Interface):
    """
    Interface for version container in the repository
    """

    latest = Attribute('latest', 'The latest revision of this object.  Must implement the IVersionedObject interface')
    
    def url():
        """Return the URL to access the last version of the object"""

    def createVersion(object, submitter, submitlog):
        """Commit a new version of the object to the repository

           object      : the new object
           submitter   : the user creating the new version
           submitlog   : a string describing the changes
        """

    def getHistory():
        """Return the version history of the object as a list.  Each item in the list will implement the **** interface"""
        return None

    def toString(self):
        return '\n'.join(
            [self.attributes[a].toString() for a in self.attributes])


if __name__ == "__main__":
    import Attribute

    a1 = ["att", "n", "this is a test"]
    a2 = ["avd", "n", "this was a test"]
    a3 = ["avs", "c", "this will be a test"]
    a4 = ["kmn", "c", "this could be a test"]

    d1 = Attribute.Attribute(a1)
    d2 = Attribute.Attribute(a2)
    d3 = Attribute.Attribute(a3)
    d4 = Attribute.Attribute(a4)

    aa = AttributeSet()

    aa.add(d1)
    aa.add(d2)
    aa.add(d3)
    aa.add(d4)

    print aa.get(0).getValues()

    for a in aa:
        print a
コード例 #6
0
    def readSchemeFile(self, schemeFile):

        #Variable to hold each read line from the file
        fileLine = ""

        try:

            #The number of attributes read from the scheme file
            numSchemeAttributes = 0

            #Variables to hold information associated with each attribute
            attributeName = ""
            attributeNumValues = ""
            attributeValues = ""

            #Read the entire scheme file
            with open(schemeFile, "r") as fp:

                #Read the initial line as the number of attributes in the scheme file
                fileLine = fp.readline()
                numSchemeAttributes = int(fileLine)
                fileLine = fp.readline()

                #Read in all of the non-function value attributes
                for i in range(numSchemeAttributes - 1):
                    attributeName = fp.readline()
                    attributeName = attributeName.strip()
                    attributeNumValues = fp.readline()
                    attributeNumValues = attributeNumValues.strip()
                    attributeValues = fp.readline()
                    attributeValues = attributeValues.strip()
                    fp.readline()

                    #Attempt to create a new attribute
                    readAttribute = Attribute(attributeName,
                                              int(attributeNumValues),
                                              attributeValues)

                    #If the attribute was invalid, inform the user and exit the system
                    if (readAttribute.getValues() == None):
                        print(
                            "One or more of the attributes in the SchemeFile was invalid.\nPlease ensure all of the attributes specified are present."
                        )
                        fp.close()
                        sys.exit(1)

                    #Add the attribute to the list of read attributes
                    self.attributes.append(readAttribute)

                #Read in the function value information
                attributeName = fp.readline()
                attributeName = attributeName.strip()
                attributeNumValues = fp.readline()
                attributeNumValues = attributeNumValues.strip()
                attributeValues = fp.readline()
                attributeValues = attributeValues.strip()

                #Create the function value attribute and add it to the list of attributes
                functionAttribute = Attribute(attributeName,
                                              int(attributeNumValues),
                                              attributeValues)
                self.functionValue = functionAttribute

                fp.close()

        #Inform the user if the file couldn't be found
        except FileNotFoundError:
            print("The scheme file \'" + schemeFile + "\' could not be found.")
            sys.exit(1)

        #Inform the user if an error occurred while reading the file
        except IOError:
            print("An error occurred while reading the scheme file \'" +
                  schemeFile + "\'")
            sys.exit(1)

        #Inform the user if an error occurred while reading the file
        except ValueError:
            print("An error occurred while reading the scheme file \'" +
                  schemeFile + "\'")
            sys.exit(1)
コード例 #7
0
    # d1.addTable(t2)

    # statement = "t1, t2 on t1.a1 = t2.a3"
    # p = parseJoins([statement])
    # print(d1)
    # print(d1.join(p))
    # join_table = d1.join(p)
    # select_table = join_table.select("*", [[['a1',condition('inside', (1, 2))]]])
    # print(select_table)

    # d1.addForeignKey("t1", "a1", "t2", "a3")
    # d1.addForeignKey("t2", "a3", "t1", "a2")
    # print(d1.showForeignKeys())

    # ===============================test join time===================================
    a1 = Attribute(name="a1", type=AttrTypes.INT, key=[AttrKeys.NOT_NULL])
    for i in range(1, 1001):
        a1.addValue(i)
    a2 = Attribute(name="a2", type=AttrTypes.INT, key=[AttrKeys.NOT_NULL])
    for i in range(1, 1001):
        a2.addValue(1)
    a3 = Attribute(name="a3", type=AttrTypes.INT, key=[AttrKeys.PRIMARY])
    for i in range(1, 10001):
        a3.addValue(i)
    a4 = Attribute(name="a4", type=AttrTypes.INT, key=[AttrKeys.NOT_NULL])
    for i in range(1, 10001):
        a4.addValue(1)

    t1 = Table('t1', [a1, a2])
    t2 = Table('t2', [a3, a4])
コード例 #8
0
    def __setitem__(self, name, value):
        """
        """

        self.attr[name] = Attribute(name, value)