示例#1
0
文件: Handler.py 项目: acintr/GODA
    def create_object(self, obj_name, obj_attributes):
        """
        Creates a new object
        :param obj_name: str - object name
        :param obj_attributes: dictionary of object attributes
        :return: None
        """
        if obj_name in self.objects:
            return ObjectExistsError(obj_name)

        obj = ObjectType(obj_name, obj_attributes)
        self.objects[obj_name] = obj
示例#2
0
文件: Handler.py 项目: acintr/GODA
    def imp_col(self, file_path, library_name):
        try:
            lib = self.libraries[library_name]
        except Exception:
            return LibraryNotOpenedError(library_name)

        try:
            filereader = open(file_path, 'r')
        except Exception:
            return FileNotFoundError(file_path)

        file = filereader.read().split("\n")
        # Path of file with data
        col_path = file[0]
        # Name of collection
        col_name = file[1]
        # Name of object
        obj_name = file[2]
        # Object attributes
        obj_attr = file[3]

        # Convert the object attributes to a string
        att = obj_attr.split(",")
        att_dict = {}
        for a in att:
            split = a.split(":")
            att_dict[split[0]] = split[1]

        obj = ObjectType(obj_name, att_dict)
        data_types = obj.get_obj_data_types()
        try:
            col = InputManager.import_collection(col_path,
                                                 Collection(col_name, obj),
                                                 data_types)
        except Exception:
            return FileNotFoundError(col_path)

        lib.add_collection(col)
        OutputManager2.create_collection(self.dir_path, library_name, col)
示例#3
0
文件: Library.py 项目: acintr/GODA
 def create_collection(self, col_name, obj_type, obj_attributes):
     """
     CREATE A NEW COLLECTION IN LIBRARY
     :param col_name: STRING - NAME OF NEW COLLECTION
     :param obj_type: STRING - OBJECT TYPE
     :param obj_attributes: DICTIONARY - OBJECT DEFINITION
     :return: VOID
     """
     for c in self.__col_list:
         if c.get_name() == col_name:
             print("A Collection with that name already exists")
             return
     obj_def = ObjectType(obj_type, obj_attributes)
     new_col = Collection(col_name, obj_def)
     self.__col_list.append(new_col)
     objdef_exist = False
     for o in self.__obj_list:
         if o.get_obj_type() == obj_def.get_obj_type() \
                 and o.get_obj_att_dict() == obj_def.get_obj_att_dict():
             objdef_exist = True
     if not objdef_exist:
         self.__obj_list.append(obj_def)
     return
示例#4
0
文件: test5.py 项目: acintr/GODA
c1.add_obj([None, None, None, None])
c1.add_obj(["802-10-6088", 4.00, "Changoma", "BIOL"])
c1.add_obj(["802-80-2802", 10.0, "help", "ICOM"])
c1.add_obj(["802-04-0420", 4.20, "Willy", "MAFU"])

# Adding Professors to Faculty
c3 = lib0.get_collection("Faculty")
c3.add_obj(["Wilson", "ICOM", 2])
c3.add_obj(["Bienvenido", "CIIC", 3])
c3.add_obj(["Pedro", "ICOM", 2])
c3.add_obj(["Amir", "CIIC", 1])

# Adding a collection (Not creating!)
ot1 = "Car"
at1 = {"model": "str", "year": "int", "color": "str"}
o1 = ObjectType(ot1, at1)
cn1 = "Garage"
c1 = Collection(cn1, o1)
c1.add_obj(["Tacoma", 2010, "gray"])
c1.add_obj(["Sienna", 2015, "black"])
c1.add_obj(["Yaris", 2020, "red"])
c1.add_obj(["Smart Car", 2018, "blue"])

lib0.add_collection(c1)

# Exporting Library to Desktop (replace my directory with your to test for yourself)
print(
    '\n**********************************\nExporting Library to Desktop (replace my directory with your own to test)\n'
)
export_library(lib0, r'TestingRes\Libraries')
示例#5
0
文件: test0.py 项目: acintr/GODA
from ADT.ObjectType import ObjectType
from ADT.Collection import Collection

print("===================\n\nTESTING INSTANCES\n\n===================")

ot1 = "Car"
at1 = {"model": "str", "year": "int", "color": "str"}
o1 = ObjectType(ot1, at1)
cn1 = "Garage"
c1 = Collection(cn1, o1)
c1.add_obj(["Tacoma", 2010, "gray"])
c1.add_obj(["Sienna", 2015, "black"])
c1.add_obj(["Yaris", 2020, "red"])
c1.add_obj(["Smart Car", 2018, "blue"])

ot2 = "Person"
at2 = {"name": "str", "age": "int"}
o2 = ObjectType(ot2, at2)
cn2 = "People"
c2 = Collection(cn2, o2)
c2.add_obj(["Willy Wonka", 55])
c2.add_obj(["Pedro", 62])
c2.add_obj(["Bienve", 47])

ot3 = "Something with bool"
at3 = {"name": "str", "dead": "bool"}
o3 = ObjectType(ot3, at3)
cn3 = "Stuff with list"
c3 = Collection(cn3, o3)
c3.add_obj(["Willy Wonka", False])
c3.add_obj(["Pedro", False])
示例#6
0
from ADT.ObjectType import ObjectType
from ADT.Collection import Collection
from Handler import Handler

# Creating collection with an object that has boolean attributes
ot3 = "Something with bool"
at3 = {"name": "str", "dead": "bool"}
o3 = ObjectType(ot3, at3)
cn3 = "Stuff with list"

handler = Handler()

handler.create_library('Testing something with bool')
handler.create_object(ot3, at3)
handler.create_collection('Testing something with bool', cn3, ot3)
handler.add_object('Testing something with bool', cn3, ["Willy Wonka", False])
handler.add_object('Testing something with bool', cn3, ["Hawking", True])
handler.add_object('Testing something with bool', cn3, ["Pedro", False])
handler.add_object('Testing something with bool', cn3, ["Bienve", None])
handler.add_object('Testing something with bool', cn3, ["Changoma", True])

handler.show_collection('Testing something with bool', cn3)

handler.sort('Testing something with bool', "Stuff with list", 'dead')

handler.show_all_libraries()

handler.remove_library('Testing something with bool')