Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Created November 3, 2016 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcgeld/9188268570c205fc783498b6d964bd0f to your computer and use it in GitHub Desktop.
Save marcgeld/9188268570c205fc783498b6d964bd0f to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
import groovy.io.FileType
def printelnerr = System.err.&println
def appName = this.getClass().getName()
def cli = new CliBuilder(usage:"${appName} --basedir <path_to_dir> --diffdir <path_to_dir> [--pattern old/new]")
cli.with {
b(longOpt: 'basedir', 'path to directory with files (Original)', args: 1, required: true)
d(longOpt: 'diffdir', 'path to directory with files to diff', args: 1, required: true)
p(longOpt: 'pattern', 'Filename transform pattern. Separated with \'/\' (char)', args: 2, required: false, valueSeparator: '/')
h(longOpt: 'help', 'Print help', required: false)
}
def options = cli.parse(args)
if (!options) return
if (options.h) cli.usage()
File basedir = new File(options.b)
File diffdir = new File(options.d)
String oldNamePattern = ""
String newNamePattern = ""
if (!basedir.isDirectory())
{
printelnerr "basedir: '${basedir}' is not a directory "
System.exit(-1)
}
if (!diffdir.isDirectory())
{
printelnerr "diffdir: '${diffdir}' is not a directory "
System.exit(-1)
}
if (options.ps)
{
(oldNamePattern, newNamePattern) = options.ps
}
int filesDiffed = 0
int filesDifferent = 0
basedir.eachFileRecurse (FileType.FILES) { baseFile ->
filesDiffed++
def baseFileRows = []
def diffFileRows = []
if (options.ps)
{
diffFile = new File( diffdir.toString(), baseFile.getName().replace( oldNamePattern, newNamePattern ) )
}
else {
diffFile = new File( diffdir.toString(), baseFile.getName() )
}
baseFile.eachLine { line ->
baseFileRows << line
}
diffFile.eachLine { line ->
diffFileRows << line
}
// Add all commons in one list
def commonRows = baseFileRows.intersect( diffFileRows )
diffFileRows.removeAll( commonRows )
if ( diffFileRows.size() > 0 )
{
filesDifferent++
println "different files: ${baseFile} <-> ${diffFile}"
println "Files different! Diffrent rows are:"
diffFileRows.each{
println "\t${it}"
}
}
}
println "different files ${filesDifferent} of ${filesDiffed}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment