Search in sources :

Example 1 with Compare

use of primal.Verbs.Compare 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);
}
Also used : Test(org.junit.jupiter.api.Test) Execute(suite.os.Execute) List(java.util.List) Paths(java.nio.file.Paths) Compare(primal.Verbs.Compare) FileUtil(suite.os.FileUtil) Mk(primal.Verbs.Mk) Path(java.nio.file.Path) Read(primal.MoreVerbs.Read) Execute(suite.os.Execute) FileUtil(suite.os.FileUtil) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 Read (primal.MoreVerbs.Read)1 Compare (primal.Verbs.Compare)1 Mk (primal.Verbs.Mk)1 Execute (suite.os.Execute)1 FileUtil (suite.os.FileUtil)1