Пример #1
0
def Verify_Data_Integrity(newData):
    if not os.path.exists(CHIPS_JSON):
        return newData
    oldData = JSON.loadObjects(CHIPS_JSON)  # Serialized Data in form of dict
    oldDataUn = [
    ]  # Unserialized Data in form of <class 'dataChip.Chip'> objects
    oLen = len(oldData)
    nLen = len(newData)
    eLen = oLen  # Storing only for printing purposes
    i, j = (0, 0)

    for chipDict in oldData:  # Need to unserialize it for compatibility
        oldDataUn.append(Chip.unserialize(chipDict))

    while (i < oLen):
        j = 0
        while (j < nLen):
            if (newData[j].url == oldDataUn[i].url):
                del newData[j]
                del oldDataUn[i]
                oLen -= 1
                nLen -= 1
                j -= 1
                i -= 1
                break
            j += 1
        i += 1

    if (
            len(oldDataUn) > 0
    ):  # Avoid showing the Menu if there aren't any objects with deletion requests pending
        delete, dataToBeRemoved = get_menuCLI(newData, oldDataUn, eLen)
    else:
        delete = False

    CHIPSDict = JSON.loadObjects(CHIPS_JSON)  # Serialized Data in form of dict
    CHIPS = []  # Unserialized Data in form of <class 'dataChip.Chip'> objects
    for chipDict in CHIPSDict:  # Need to unserialize it for compatibility
        CHIPS.append(Chip.unserialize(chipDict))

    if (delete):
        for chip in dataToBeRemoved:
            for i, C in enumerate(CHIPS):
                if (chip.url == C.url):
                    del CHIPS[i]
                    break

    for chip in newData:
        CHIPS.append(chip)
    return CHIPS
Пример #2
0
def digJSONTree(sublist, foldersStack):
    """
        Recursive generator that fetches the bookmarks from a JSON storage
        scheme, preserving the hierarchical folder structure data.

        # Parameters
        `sublist` : List of child entries in the given folder ->  _(list)_
        `foldersStack` : Stack denoting Parent folders  ->  _(str)_

        # Returns
        `Chip` : Object of dataChip.Chip class containing bookmark name, url and
                 folder structure data
    """
    for item in sublist:
        if item["type"] == "folder":
            foldersStack.append(item["name"])
            createTreeNode(foldersStack)

            for object in digJSONTree(item["children"], foldersStack):
                yield object
            foldersStack.pop()

        elif item["type"] == "url":
            p_bm = Primitive_Bookmark()
            p_bm.name = item["name"]
            p_bm.url = item["url"]
            p_bm.date_added = timestamp_from_webkit(int(item["date_added"]))
            p_bm.foldersStack = foldersStack
            chip = Chip(p_bm)

            node = tree.get_node('->'.join(foldersStack))
            if node.data is None:
                node.data = []
            node.data.append(chip.ID)
            yield chip
Пример #3
0
def generateChipImports():
    """
        Generator for iterating through imports from browsers and medium files

        Yields:
        `dataChip.Chip`
    """
    import parser_Browser as BP  # import needs to be removed otherwise
    # if parser_Browser.py is to be run alone

    sys.stdout.write(
        "\n> Auto-Importing bookmarks: "
    )  # TODO: Add the config setup check before this for paths
    with Spinner():
        if (__IMPORT_GC):
            try:
                for chips in BP.import_from_Browser("Google Chrome",
                                                    __GC_DB,
                                                    BP.jsonMiner,
                                                    mute=True):
                    yield chips
            except FileNotFoundError as e:
                print("Issue Encountered: ", e, " > ", __GC_DB)

        if (__IMPORT_CR):
            try:
                for chips in BP.import_from_Browser("Chromium",
                                                    __CR_DB,
                                                    BP.jsonMiner,
                                                    mute=True):
                    yield chips
            except FileNotFoundError as e:
                print("Issue Encountered: ", e, " > ", __CR_DB)

        if (__IMPORT_MEDIUM):
            try:
                mediumB, _ = GET_MediumExports()
                for p_bm in mediumB:
                    yield Chip(p_bm)
            except FileNotFoundError as e:
                print("Issue Encountered: ", e, " > ", MEDIUM_DIR)
Пример #4
0
def generateChipsfromImport():
    for p_bm in importer.generateImportsfromExports():
        yield Chip(p_bm)
Пример #5
0
def generateChips(limit):
    for pbm in generatePrimitiveBookmarks(limit):
        yield Chip(pbm)