示例#1
0
def SelectFolder():
    misc.SetHeader("Select the folder with the downloaded files")
    homedir = os.path.expanduser("~")
    downloadDir = os.path.join(homedir, "Downloads")

    if os.path.isdir(downloadDir):
        while True:
            print("Your Download folder is '" + downloadDir + "'")
            inDownloadDir = misc.ConfirmInput(
                "Are the scrapbook zip files in your downloads folder? ", True)
            if inDownloadDir:
                return downloadDir
            else:
                return misc.GetDir(
                    "Please enter the path to the folder where your files are at"
                )
            misc.SetHeader("Select the folder with the downloaded files")
            print()
            print(" Error!")
            print(" The input '" + inDownloadDir +
                  "' doesn't seemed to work, please try again")
            print()
            print()
    else:
        return misc.GetDir(
            "Please enter the path to the folder where your files are at")
示例#2
0
def main(args):
    parser = argparse.ArgumentParser(description='ScrappyDoo')
    # parser.add_argument('path', nargs='?', type="string")
    # parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),default=sys.stdout)
    parser.parse_args()
    args = parser.parse_args()
    misc.Welcome()
    folder = folderParser.SelectFolder()
    kitFiles = folderParser.FindAllKits(folder)

    #pre kit processing screen
    misc.SetHeader("Quick Message")
    print("We are going all of the Art Kits in: ", folder)
    print("For each zile file we find:")
    print(" * You can enter the name of the Art Kit it is part of")
    print(" * What type of elements it holds")
    print(" * Skip any file that is not part of an Art Kit")
    print(
        " * If an option has '(Default)', it can be choosen with just pressing 'Enter'"
    )
    print()
    print("Lets Get Started! ")
    misc.Pause()

    kits = kitutil.ProcessKits(kitFiles, folder)
    kitutil.ExtractKits(kits)
    misc.Pause()

    # Post processing - Move Files
    kitutil.MoveKitFolders(kits, folder)

    # Post processing - Delete zips
    misc.SetHeader("Kit Post Processing")
    print(
        "Would you like me to delete the zip files that were turn into kits?")
    print(
        "They shouldn't be needed any more if everything install correctly into Creative Memories"
    )
    print()
    print("WARNING: This can NOT be undone!")
    print()
    shouldDelete = misc.ConfirmInput(
        "Should I delete the zip files that you ?")
    if shouldDelete:
        kitutil.DeleteKitFiles(kits, folder)

    # Closing msg
    misc.SetHeader("Good Bye!")
    print("Everything is complete!")
    print("Thanks for using ScrappyDoo and have a nice day!")
    print()
    misc.Pause()
示例#3
0
def ProcessKits(kitFiles, dir):
    kitsZips = {}
    for x, file in enumerate(kitFiles):
        misc.SetHeader("Get Kit Information (" + str(x + 1) + " of " +
                       str(len(kitFiles)) + ")")
        print("To skip a file, please enter '#skip' for the name")
        print()
        print()
        print("Current File: ", file)
        kitNameInfo = GetKitName(file, kitsZips)
        if kitNameInfo is None:
            #user skipped the kit
            continue
        # Kit Name & the filename string of the kit
        name, fileKitStr = kitNameInfo
        if not fileKitStr in kitsZips:
            kitsZips[fileKitStr] = Kit(name, dir)
        kitType = GetKitType(file, name)
        kitsZips[fileKitStr].addFile(kitType, file)

    kits = {}
    # Conbine kits by Name
    for z in kitsZips:
        if kitsZips[z].name in kits:
            for type in kitsZips[z].files:
                if type not in kits[kitsZips[z].name].files:
                    kits[kitsZips[z].name].files[type] = []
                kits[kitsZips[z].name].files[type] += kitsZips[z].files[type]
        else:
            kits[kitsZips[z].name] = kitsZips[z]
    return kits
示例#4
0
def ExtractKits(kits):
    """ Takes a dictionary of kit objects and extracts them"""
    misc.SetHeader("Extracting Kits, Please Wait ...")
    errors = []
    for kitName in kits:
        try:
            kits[kitName].extract()
            if kits[kitName].hasError:
                errors.append(kits[kitName].error)
        except Exception as e:
            print(e)
            print()
            print()
            print("We had issues extracting ", kitName)
            print("So we are going to kip it and move on...")
            print()
            print()
            errors.append(kitName)
    if len(errors) > 0:
        print()
        print()
        print("The Following Kits Had Errors:")
        for e in errors:
            print(e)
        print("")
        print("")
        print("")
        input("press Enter to Continue ...")
示例#5
0
def FindAllKits(dir):
    misc.SetHeader("Finding all of the zip in: " + dir)

    kitFiles = []
    files = os.listdir(dir)
    for file in files:
        if file.lower().endswith(".zip"):
            kitFiles.append(file)
    return kitFiles
示例#6
0
def DeleteKitFiles(kits, folder):
    misc.SetHeader("Deleting Kits")
    print()

    for name in kits:
        for type in kits[name].files:
            for file in kits[name].files[type]:
                print("Deleting ", file)
                try:
                    os.remove(os.path.join(current, file))
                except Exception as e:
                    print("Error! Could not delete ", file)
                    print("Skipping... ")

    misc.Pause()
示例#7
0
def MoveKitFolders(kits, current):
    misc.SetHeader("Moving Kits")
    dest = ""
    goodInput = False
    while not goodInput:
        print("Where should we move the kits?")
        print(" 1) Into the Personal Art Kits folder (Default)")
        print(" 2) I want to enter a custom folder")
        print(" 3) Skip this step")
        action = input("Please Select Number Above:")
        if action is "":
            homedir = os.path.expanduser("~")
            dest = os.path.join(homedir, "Documents", "Personal Art Kits")
            goodInput = True
        if action.isdigit():
            actionNum = int(action)
            if actionNum == 1:
                homedir = os.path.expanduser("~")
                dest = os.path.join(homedir, "Documents", "Personal Art Kits")
                goodInput = True
            if actionNum == 2:
                dest = misc.GetDir("Please enter the destination folder")
                goodInput = True
            if actionNum == 3:
                return
        if not goodInput:
            print()
            print("Hmm, that input seems wrong. Try again!")
            print()

    if not os.path.isdir(dest):
        dest = misc.GetDir(
            dest + " does not exist! Please enter a new destination folder")

    errors = []
    for name in kits:
        print("Moving ", name)
        try:
            shutil.move(os.path.join(current, name), dest)
        except Exception as e:
            errors.append(name)
            print()
            print("Error! Could Not move kit", name)
            print("Skipping the move for this kit")
            print()

    print("Done Moving Kits!")
    print(
        "It is best to open Creative Memories to make sure all of the kits were installed properly"
    )
    if len(errors) > 0:
        print()
        print(
            "==========================================================================="
        )
        print(
            "ERROR!!! There were errors, not all files mght have been copied")
        print("The following folders had errors")
        for name in errors:
            print(" * ", name)
        print(
            "==========================================================================="
        )
        print()
        print()
    misc.Pause()