use of suite.os.FileUtil in project suite by stupidsing.
the class OtfTest method otfTest.
// main program and unit test combined.
@Test
public void otfTest() {
// input variables.
var directory = "/tmp/fonts";
// constants.
var familyKey = "Family";
var subfamilyKey = "Subfamily";
var keys = List.of(familyKey, subfamilyKey);
// make sure the input directory exists; we are not supposed to show errors.
Mk.dir(Paths.get(directory));
var commands = //
Read.each(//
directory).map(//
Paths::get).concatMap(//
FileUtil::findPaths).map(//
Path::toString).filter(path -> {
var pathLower = path.toLowerCase();
return pathLower.endsWith(".otf") || pathLower.endsWith(".ttf");
}).map2(path -> {
var exec = new Execute(new String[] { "otfinfo", "-i", path });
return //
Read.from(//
exec.out.split("\n")).map(//
line -> line.split(":")).filter(//
arr -> 2 <= arr.length).map2(arr -> arr[0].trim(), //
arr -> arr[1].trim()).filterKey(//
keys::contains).toMap();
}).map((k, m) -> {
var f = m.get(familyKey);
var sf = m.get(subfamilyKey);
var dir = "/home/ywsing/.fonts/" + f + "/";
var ext = k.substring(k.lastIndexOf(".") + 1).toLowerCase();
return "mkdir -p '" + dir + "'; mv '" + k + "' '" + dir + f + " " + sf + "." + ext + "'\n";
}).sort(//
Compare::objects).toJoinedString();
// output!
System.out.println(commands);
}