Created
October 1, 2013 18:26
-
-
Save copyninja/6782850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import [os [popen]] | |
[os.path [exists]] | |
[sys] | |
[re]) | |
(defun get-font-metadata [ fontfile] | |
"Given the font file function checks for its existence then runs the | |
otfinfo tool from lcdf-typetools package to extract metadata | |
information and returns the parsed dict." | |
(if (not (exists fontfile)) | |
(kwapply (print "Please give existent font file") | |
{"file" sys.stderr})) | |
(let [[cmd (.format "/usr/bin/otfinfo -i {}" fontfile)] | |
[fd (kwapply (popen cmd) {"mode" "r"})] | |
[regexp (.compile re "([a-zA-Z\s]+):\s*(.*)")] | |
[metadict {}] | |
[copyright-text []]] | |
(foreach [line (.readlines fd)] | |
(let [[regmatch (.match regexp line)]] | |
(if (!= regmatch None) | |
(assoc metadict (.group regmatch 1) | |
(.group regmatch 2)) | |
(.append copyright-text line)))) | |
(print copyright-text) | |
(if (in "Copyright" metadict) | |
(assoc metadict "Copyright" | |
(.format "{}\n{}" | |
(get metadict "Copyright") | |
(.join "" copyright-text)))) | |
metadict)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment