Exemple #1
0
def parse_file(FOLDER, FILE, rootFolder, date="", check_override=False):
    # file = open(FILE.RootFolder+"/"+FILE.name+"."+FILE.extension)
    regex = "(.*?)[\(\[](.*)"
    regex2 = "(.*)[\s_](\d+)"
    parse_file = FILE.replace("_", " ")
    # should really only get files with the way it's done now...
    # print(date + " :: " + FILE)
    # CHECK TO SEE IF FILE IS IN DB!
    extension = os.path.splitext(FILE)[1][1:]
    # print(extension)
    ignore_ext_set = set(["txt", "com", "com.txt", "part"])
    if extension in ignore_ext_set:
        return False
    """
        Check the DB to see if we already parsed this one; don't if we already have
    """

    try:
        print("checking for db item...")
        f = ComicFile.objects.get(name=FILE, dir_path=FOLDER)
    except ComicFile.DoesNotExist:
        print("No Object exist...that's good!")
        f = ComicFile(name=FILE, dir_path=FOLDER, comic_date=date, rootFolder=rootFolder)
        # return False
    else:
        print("No exceptions, but there was a file already in there...")
        if check_override is False:
            print("...override is false, don't parse")
            return
        else:
            print("override is true, please parse")

    # IT ISN'T?! Then lets start parsing!
    file_parse = re.match(regex, parse_file)
    if file_parse:
        # DO STUFF
        # print(file_parse.group(1))
        f.comic_name = file_parse.group(1)
        # print(file_parse.group(2))
        number_parse = re.match(regex2, file_parse.group(1))
        if number_parse:
            f.comic_name = number_parse.group(1)
            f.comic_issue = number_parse.group(2)
            # print(number_parse.group(1) + " :: " + number_parse.group(2))
    f.extension = extension
    f.save()
    #    file_parse = re.match(regex2, FILE)
    #    if file_parse:
    # do more stuff
    #        print(file_parse)
    # now that the file is saved; add to image processing queue!
    thumbnail_parse_task.delay(f)
Exemple #2
0
def reparse_image(modeladmin, request, queryset):
    for q in queryset:
        thumbnail_parse_task.delay(q)