Ejemplo n.º 1
0
    def outputFunction(self, obj):
        """
        Check if the output function is valid.

        @param obj   : Population protocol or graph obj
        @return      : True if the attribute is valid otherwise False
        """
        try:
            inputFunction = getattr(obj, "outputFunction")
            for function in inputFunction:
                firstElem, secondElem = self.findXYQBetween(function)
                states = getattr(obj, "states")
                output = getattr(obj, "output")
                if firstElem not in states:
                    raise ProtocolItemError(function, "outputFunction")
                if secondElem not in output:
                    raise ProtocolItemError(function, "outputFunction")
        except AttributeError as error:
            printRed(error)
            return False
        except ProtocolItemError as error:
            printRed(error)
            return False
        return True
Ejemplo n.º 2
0
def setUp():
    """
    Create necessary window-python files and folders tree for application

    @return: None
    """
    global errorCounter
    printYellow("=" * 40)
    for uiFile in listUiFiles:
        printYellow("-I- Create {}UI.py file".format(uiFile))

        if uiFile == listUiFiles[-1]:
            command = "pyuic5 -x dialogs/{0}.ui -o dialogs/{0}UI.py".format(
                uiFile)
        else:
            command = "pyuic5 -x {0}.ui -o {0}UI.py".format(uiFile)

        if processCommand(command, currentFilePath):
            printYellow("-I- File {}UI.py was created\n".format(uiFile))
        else:
            printRed("-E- File {}UI.py was not created\n".format(uiFile))
            errorCounter += 1

    printYellow("=" * 40)

    for folder in listFolders:
        printYellow("-I- Create {} folder".format(folder))

        if os.path.isdir("\\".join([currentFilePath, folder])):
            printYellow("-I- Folder {} already exists\n".format(folder))
            continue

        command = "mkdir {}".format(folder)

        if processCommand(command, currentFilePath):
            printYellow("-I- Folder {} was created\n".format(folder))
        else:
            printRed("-E- Folder {} was not created\n".format(folder))
            errorCounter += 1

    if (errorCounter == NO_ERROR):
        printYellow("\n-I- Script finished successfully")
    else:
        printRed("\n-E- Script finished with failure")

    createSettings(configFile)
    input(getBrightGreenString("Press Enter to continue..."))
Ejemplo n.º 3
0
    def numberNodes(self, obj):
        """
        Check if the number nodes is valid.

        @param obj  : Population protocol or graph obj
        @return     : True if the attribute is valid otherwise False
        """
        try:
            numberNodes = getattr(obj, "numberNodes")
            if isinstance(numberNodes, int):
                if numberNodes > 1:
                    return True
                else:
                    printRed("Number of nodes must be higher than 1.")
                    return False
            else:
                printRed("Attribute numberNodes is not integer instance.")
                return False
        except AttributeError as error:
            printRed(error)
            return False
        except ValueError as error:
            printRed(error)
            return False
Ejemplo n.º 4
0
    def states(self, obj):
        """
        Check if the states is valid.

        @param obj   : Population protocol or graph obj
        @return      : True if the attribute is valid otherwise False
        """
        try:
            states = getattr(obj, "states")
            if isinstance(states, list):
                if not len(states) > 0:
                    printRed("List of states does not contain single state.")
            else:
                printRed("States does not contain list of states")
                return False
        except AttributeError as error:
            printRed(error)
            return False
        return True
Ejemplo n.º 5
0
    def input(self, obj):
        """
        Check if the input is valid.

        @param obj   : Population protocol or graph obj
        @return      : True if the attribute is valid otherwise False
        """
        try:
            input = getattr(obj, "input")
            if isinstance(input, list):
                if not len(input) > 0:
                    printRed("List of inputs does not contain single input.")
            else:
                printRed("Input does not contain list of inputs")
                return False
        except AttributeError as error:
            printRed(error)
            return False
        return True
Ejemplo n.º 6
0
    def protocolType(self, obj):
        """
        Check if the protocolType is valid.

        @param obj   : Population protocol or graph obj
        @return      : True if the attribute is valid otherwise False
        """
        try:
            protocolType = getattr(obj, "protocolType")
            strippedProtocolType = protocolType.strip()
            if strippedProtocolType == "Leader Election":
                return True
            elif strippedProtocolType == "Leader Election":
                return True
            elif strippedProtocolType == "":
                printRed("Missing protocolType's key.")
                return False
            else:
                printRed("Unsupported protocol Type.")
                return False
        except AttributeError as error:
            printRed(error)
            return False
Ejemplo n.º 7
0
import sys

try:
    import settings as st
    from util_lib.utilityPrint import printRed
    from util_lib.utilityDict import ObjectDict
except ImportError as error:
    printRed(error)
    sys.exit(st.ErrorCode.ERROR_IMPORT)


class Protocol(ObjectDict):
    pass