Skip to content

Commit

Permalink
Parse every file from common/main in make-dist
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-coram committed Jul 18, 2023
1 parent 284986d commit ab09908
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 59 deletions.
12 changes: 7 additions & 5 deletions chronogram-cldr-parser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@
(territory (when territory-node
(plump:get-attribute territory-node "type")))
(calendars (funcall parse-calendar root)))
`((language . ,language)
,@(when territory
`((territory . ,territory)))
,@(when calendars
`((calendars . ,calendars)))))))
(values `((language . ,language)
,@(when territory
`((territory . ,territory)))
,@(when calendars
`((calendars . ,calendars))))
language
territory))))

;; (parse-cldr (uiop:read-file-string "cldr-staging/production/common/main/en_GB.xml"))
85 changes: 31 additions & 54 deletions chronogram-dist.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,46 @@

(defpackage #:chronogram-dist
(:use #:cl)
(:local-nicknames (:p :chronogram-cldr-parser))
(:export #:make-dist))

(in-package #:chronogram-dist)

(defun get-cldr-release-tag (system)
(string-trim '(#\linefeed #\return #\space)
(uiop:read-file-string
(asdf:system-relative-pathname system "CLDR_RELEASE"))))
(defun make-chronogram-info (contents dist-dir)
(multiple-value-bind (info language territory)
(chronogram-cldr-parser:parse-cldr contents)
(with-open-file (stream (if territory
(format nil "~a~a_~a.lisp"
dist-dir
language
territory)
(format nil "~a~a.lisp"
dist-dir
language))
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(let ((*package* (find-package 'chronogram-cldr-parser)))
(format stream "~s~%" info)))))

(defun get-archive-url (tag)
(format nil
"https://github.com/unicode-org/cldr-staging/archive/refs/tags/~a.zip"
tag))

(defun make-chronogram-info (contents dist-dir name)
(with-open-file (stream (format nil "~a~a.lisp" dist-dir name)
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(let ((*package* (find-package 'chronogram-cldr-parser)))
(format stream "~s~%" (chronogram-cldr-parser:parse-cldr contents)))))

(defun make-dist (&optional force-download)
(defun make-dist ()
(let* ((system (asdf:find-system 'chronogram t))
(dist-dir (asdf:system-relative-pathname system "chronogram-dist/"))
(cldr-submodule-available
(uiop:file-exists-p
(asdf:system-relative-pathname system
"cldr-staging/LICENSE.txt")))
(tag (when (or force-download (not cldr-submodule-available))
(get-cldr-release-tag system)))
(names '("en" "de" "hu" "ko")))
(cldr-dir (asdf:system-relative-pathname system "cldr-staging"))
(paths (uiop:directory-files (format nil "~a/production/common/main/"
cldr-dir))))
(unless cldr-submodule-available
(error "cldr-staging submodule not checked out"))
(ensure-directories-exist dist-dir)
(if tag
(uiop:with-temporary-file (:stream s)
(format t "Downloading cldr release ~a... " tag)
(force-output)
(let ((bytes (dex:get (get-archive-url tag))))
(write-sequence bytes s)
(finish-output s))
(format t "DONE~%")
(zip:with-zipfile (f s)
(loop :for name :in names
:for entry := (zip:get-zipfile-entry
(format nil "cldr-~a/~a" tag name) f)
:do (format t "Writing ~a~a.lisp... " dist-dir name)
:do (force-output)
:do (make-chronogram-info
(babel:octets-to-string (zip:zipfile-entry-contents entry)
:encoding :utf-8)
dist-dir
name)
:do (format t "DONE~%"))))
(loop :with cldr-dir
:= (asdf:system-relative-pathname system "cldr-staging/")
:for name :in names
:do (format t "Writing ~a~a.lisp... " dist-dir name)
:do (force-output)
:do (make-chronogram-info
(uiop:read-file-string
(format nil "~a/production/common/main/~a.xml"
cldr-dir
name))
dist-dir
name)
:do (format t "DONE~%")))))
(loop :with cldr-dir
:= (asdf:system-relative-pathname system "cldr-staging/")
:for path :in paths
:do (format t "Parsing ~a... " path)
:do (force-output)
:do (make-chronogram-info (uiop:read-file-string path)
dist-dir)
:do (format t "DONE~%"))))

0 comments on commit ab09908

Please sign in to comment.