def listrecursive(root, wholedir=False):
    allfiles = {}
    for rootfolder, dirs, files in os.walk(root):
        for file in files:
            fullpath = os.path.join(os.path.abspath(rootfolder), file)
            if wholedir:
                localname = os.path.join(topdir(root), os.path.relpath(fullpath, root))
            else:
                localname = os.path.relpath(fullpath, root)
            allfiles[fullpath] = datastruct.adjust_separator_for_pac(localname)
    return allfiles
def listrecursive(root, wholedir=False):
    allfiles = {}
    for rootfolder, dirs, files in os.walk(root):
        for file in files:
            fullpath = os.path.join(os.path.abspath(rootfolder), file)
            if wholedir:
                localname = os.path.join(topdir(root),
                                         os.path.relpath(fullpath, root))
            else:
                localname = os.path.relpath(fullpath, root)
            allfiles[fullpath] = datastruct.adjust_separator_for_pac(localname)
    return allfiles
Example #3
0
def cliUI(cmdline):
    sekai = fileadding_utils.staging()
    docompress = not cmdline.no_compress
    dryrun = cmdline.dry_run
    # staging operations
    if cmdline.stage:
        if cmdline.add:
            if os.path.isfile(cmdline.file):
                if os.path.isdir(cmdline.base_dir):
                    relpath = os.path.relpath(cmdline.file, cmdline.base_dir)
                    newbie = sekai.addfile(relpath, cmdline.file, compression=docompress)
                    if newbie:
                        print("Added new file with name: " + datastruct.adjust_separator_for_pac(relpath))
                    else:
                        print("File " + datastruct.adjust_separator_for_pac(relpath) + " will be replaced")
                else:
                    print("directory \"" + cmdline.add + "\" si not valid")
            elif os.path.isdir(cmdline.file):
                sekai.addDirectory(cmdline.file, compression=docompress, verbose=True, wholedir=True)
            else:
                print("file \"" + cmdline.file + "\" not found")
            sekai.saveEnviron()
        elif cmdline.merge:
            if os.path.isdir(cmdline.file):
                sekai.addDirectory(cmdline.file, compression=docompress, verbose=True, wholedir=False)
            else:
                print("directory \"" + cmdline.add + "\" si not valid")
            sekai.saveEnviron()
        elif cmdline.undo:
            undid = sekai.undoFile(cmdline.file)
            if not undid:
                print("Warning: command had no effect (typo in filename?)")
            sekai.saveEnviron()
        elif cmdline.remove:
            removed = sekai.removeFile(cmdline.file)
            if not removed:
                print("Warning: command had no effect (typo in filename?)")
            sekai.saveEnviron()
        elif cmdline.commit:
            sekai.commit()
            print("Commit completed")
            sekai.saveEnviron()
        elif cmdline.write:
            sekai.writeout(cmdline.file, dry_run=dryrun, debuggy=cmdline.debug)
            if not dryrun:
                sekai.clearEnviron()
        elif cmdline.peek:
            nonStaging(sekai.package, cmdline, sekai.target)
        elif cmdline.list:
            sekai.listInfo()
        elif cmdline.list_harder:
            sekai.listDetailed()

        # other operations

        elif cmdline.file: # targeting (initialize staging)
            sekai.loadPackage(cmdline.file)
            print("Staging environment initialized with target pacfile: " + sekai.target)
            sekai.saveEnviron()

        else:
            sekai.start_id = cmdline.offset
            sekai.saveEnviron()

    # non-staging operations
    elif cmdline.file is not None:
        pac = datastruct.Pacfile()
        with open(cmdline.file, "rb") as binfile:
            pac.load_from_file(binfile)
        nonStaging(pac, cmdline, cmdline.file)

    else:
        if cmdline.version:
            print(info.getInfoMsg())