예제 #1
0
 def add(self, item):
     destination = "Data/Images/"
     ID = util.generateID()
     util.copyIMG(item[5], destination, ID)
     newPath = "Data/Images/{}".format(ID)
     myTool = Tool(ID, self.__owner, item[0], item[1], item[2], item[3], item[4], newPath, "yes")
     wf.add_tool(myTool)
     print("Tool has been added")
예제 #2
0
def convertFromListToObj(list):
    """
    Convert tool list to Tool object
    :param list:
    :return: obj(Tool)
    """

    return Tool(list[0], list[1], list[2], list[3], list[4], list[5], list[6], list[7], list[8])
예제 #3
0
def convertToObj(index):
    """
    Converts dict(tool) to obj(tool)

    :param index (in db)
    :return obj(tool)
    """

    with open("Data/tools.csv", 'r') as f:
        l = list(csv.reader(f))
        dict = {i[0]: [x for x in i[1:]] for i in zip(*l)}
        tool = Tool(dict["ID"][index], dict["owner"][index], dict["title"][index],
                    dict["description"][index], dict["condition"][index],
                    dict["priceFullDay"][index], dict["priceHalfDay"][index],
                    dict["imgPath"][index], dict["availability"][index])
    return tool
예제 #4
0
    def add(self, tool, editOrAdd):
        """
        :param tool: list(item specifications)
        :param editOrAdd: boolean value where True = add Tool and False = edit Tool
        :return: boolean
        """

        availability = "yes"
        isCorrect = self.__verifyTool(tool)
        if isCorrect:
            if editOrAdd:
                ID = uuid.uuid4()
                util.copyIMG(tool[6], strings.filePath_images, ID)
            else:
                ID = tool[7]
                copy2(tool[6], "{}{}_temp.png".format(strings.filePath_images,
                                                      ID))
                shutil.move(
                    os.path.join(strings.filePath_images,
                                 "{}_temp.png".format(ID)),
                    os.path.join(strings.filePath_images, ID + ".png"))
                availability = tool[8]

            newPath = "{}{}".format(strings.filePath_images, ID)
            myTool = Tool(ID, self.__login, tool[0], tool[1], tool[2], tool[3],
                          tool[4], tool[5], newPath, availability)
            if editOrAdd:
                wf.write(myTool, strings.filePath_tool,
                         strings.fieldNames_tool)
            else:
                wf.editTool(myTool)
                print("edit")
            print("Tool has been added")

            return True
        else:
            return False
def load_tools():
    """
    Gathers all data, which is required. Takes command line args into account.
    :return:
    """

    logging.info(f"Detecting tools...")
    sleep(1)
    for file in os.listdir(Config.DATA_RAW_DIRECTORY):
        file_path = os.fsdecode(file)
        try:
            if file_path.endswith(".csv") or file_path.endswith(".tsv"):
                file_name: str = File_Management.get_file_name(file_path)
                # Remove the files version number if present, then remove the file extension to get a clean name

                if any(char.isdigit() for char in file_name):
                    tool_name: str = os.path.splitext(
                        str(file_name.rsplit('_', 1)[0]))[0]
                else:
                    tool_name = Path(file_path).stem

                tool = Tool(tool_name)

                tool_found: bool = False
                for stored_tool in Runtime_Datasets.DETECTED_TOOLS:
                    if not tool_found:
                        if stored_tool.__eq__(tool):
                            stored_tool.add_file(file_path)
                            tool_found = True
                            break

                if tool_found:
                    continue
                else:
                    logging.info(f"Detected tool {tool.name}")
                    tool.add_file(file_path)
                    Runtime_Datasets.DETECTED_TOOLS.append(tool)
        except OSError as ex:
            logging.warning(ex)
        except BaseException as ex:
            logging.warning(ex)

    # Verify all tools
    for tool in Runtime_Datasets.DETECTED_TOOLS:
        tool.verify()
        if Config.DEBUG_MODE:
            if tool.verified:
                logging.debug(f"Tool {tool.name} is verified.")
            else:
                logging.debug(f"Tool {tool.name} is not verified.")

    Runtime_Datasets.VERIFIED_TOOLS = [
        tool for tool in Runtime_Datasets.DETECTED_TOOLS if tool.verified
    ]
    Runtime_Datasets.EXCLUDED_TOOLS = [
        tool for tool in Runtime_Datasets.DETECTED_TOOLS if not tool.verified
    ]
    print()
    logging.info(
        f"Tool detector detected {len(Runtime_Datasets.VERIFIED_TOOLS)} valid tools and excluded"
        f" {len(Runtime_Datasets.EXCLUDED_TOOLS)} tools.")

    print()
    sleep(2)