2015-02-10 00:38:40 +00:00
|
|
|
import os, docopt, tables, md5, iterutils, re
|
|
|
|
|
2016-01-25 15:13:34 +00:00
|
|
|
type
|
|
|
|
FileEntry* = tuple[relPath: string, checksum: string]
|
|
|
|
DirAnalysis* = tuple[allEntries: seq[FileEntry],
|
|
|
|
byRelPath: Table[string, FileEntry],
|
|
|
|
byChecksum: Table[string, FileEntry]]
|
|
|
|
|
|
|
|
proc analyzeDir(root: string): DirAnalysis =
|
|
|
|
let fileCount = countFiles(root)
|
|
|
|
|
|
|
|
proc countFiles(root: string): int =
|
|
|
|
# TODO
|
|
|
|
|
2015-02-10 00:38:40 +00:00
|
|
|
proc studyDir(root: string, ignore: Iterable[string]): TableRef[string, string] =
|
|
|
|
result = newTable[string, string]()
|
|
|
|
|
|
|
|
for path in walkDirRec(root):
|
|
|
|
var relPath = substr(path, len(root))
|
|
|
|
|
|
|
|
if foldl(ignore, proc (acc: bool, it: string): bool = acc and match(relPath, re(it)), true): continue
|
|
|
|
|
|
|
|
var fileInfo = getFileInfo(path)
|
|
|
|
|
|
|
|
if fileInfo.kind == pcFile:
|
|
|
|
result.add(relPath, $(toMD5(readFile(path))))
|
|
|
|
elif fileInfo.kind == pcDir:
|
|
|
|
result.add(relPath, "directory")
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
|
|
|
|
let doc = """
|
|
|
|
treediff
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
treediff [-i <regex>]... [<path>]...
|
|
|
|
treediff (-h | --help)
|
|
|
|
treediff (-v | --version)
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h --help Show this usage information.
|
|
|
|
-v --version Show the program version.
|
|
|
|
"""
|
|
|
|
|
|
|
|
let args = docopt(doc, version = "treediff 0.1")
|
|
|
|
|
|
|
|
for root in @(args["<path>"]):
|
|
|
|
echo "Looking at ", root
|
|
|
|
|
|
|
|
echo studyDir(root, @(args["<regex>"]))
|
|
|
|
echo ""
|