Function to read from s-expression file
This commit is contained in:
parent
7b5b9b75ad
commit
956835e2d1
|
@ -1,4 +1,4 @@
|
||||||
;;; chronometrist-migrate.el --- Commands to aid in migrating from timeclock to chronometrist s-expr format -*- lexical-binding: t; -*-
|
;;; chronometrist-migrate.el --- Commands to aid in migrating between event formats -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Author: contrapunctus <xmpp:contrapunctus@jabber.fr>
|
;; Author: contrapunctus <xmpp:contrapunctus@jabber.fr>
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@
|
||||||
(require 'emacsql-sqlite)
|
(require 'emacsql-sqlite)
|
||||||
|
|
||||||
(defvar chronometrist-file)
|
(defvar chronometrist-file)
|
||||||
(defvar chronometrist-migrate-table (make-hash-table))
|
(defvar chronometrist-migrate-table (make-hash-table :test #'equal))
|
||||||
|
|
||||||
;; TODO - support other timeclock codes (currently only "i" and "o"
|
;; TODO - support other timeclock codes (currently only "i" and "o"
|
||||||
;; are supported.)
|
;; are supported.)
|
||||||
(defun chronometrist-migrate-populate (in-file)
|
(defun chronometrist-migrate-populate-timelog (in-file)
|
||||||
"Read data from IN-FILE to `chronometrist-migrate-table'.
|
"Read data from IN-FILE to `chronometrist-migrate-table'.
|
||||||
|
|
||||||
IN-FILE should be a file in the format supported by timeclock.el.
|
IN-FILE should be a file in the format supported by timeclock.el.
|
||||||
|
@ -106,14 +106,40 @@ file names respectively."
|
||||||
(let ((output (find-file-noselect out-file)))
|
(let ((output (find-file-noselect out-file)))
|
||||||
(with-current-buffer output
|
(with-current-buffer output
|
||||||
(chronometrist-common-clear-buffer output)
|
(chronometrist-common-clear-buffer output)
|
||||||
(chronometrist-migrate-populate in-file)
|
(chronometrist-migrate-populate-timelog in-file)
|
||||||
(maphash (lambda (_key value)
|
(maphash (lambda (_key value)
|
||||||
(chronometrist-plist-pp value output)
|
(chronometrist-plist-pp value output)
|
||||||
(insert "\n\n"))
|
(insert "\n\n"))
|
||||||
chronometrist-migrate-table)
|
chronometrist-migrate-table)
|
||||||
(save-buffer)))))
|
(save-buffer)))))
|
||||||
|
|
||||||
(defvar chronometrist-migrate-db )
|
(defvar chronometrist-migrate-db)
|
||||||
|
|
||||||
|
(defun chronometrist-migrate-populate-sexp (in-file)
|
||||||
|
"Read data from IN-FILE to `chronometrist-migrate-table'.
|
||||||
|
|
||||||
|
IN-FILE should be a file in the Chronometrist s-expression format.
|
||||||
|
See `chronometrist-file' for a description."
|
||||||
|
(clrhash chronometrist-migrate-table)
|
||||||
|
(with-current-buffer (find-file-noselect in-file)
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let ((index 0)
|
||||||
|
expr)
|
||||||
|
(while (setq expr (ignore-errors (read (current-buffer))))
|
||||||
|
(let* ((new-date (->> (plist-get expr :start)
|
||||||
|
(s-left 10)))
|
||||||
|
(existing-value (gethash new-date
|
||||||
|
chronometrist-migrate-table)))
|
||||||
|
(cl-incf index)
|
||||||
|
(puthash new-date
|
||||||
|
(if existing-value
|
||||||
|
(append existing-value
|
||||||
|
(list expr))
|
||||||
|
(list expr))
|
||||||
|
chronometrist-migrate-table)))
|
||||||
|
(unless (zerop index)
|
||||||
|
index)))))
|
||||||
|
|
||||||
(defun chronometrist-migrate-sexp-file->sql-db (&optional in-file out-file)
|
(defun chronometrist-migrate-sexp-file->sql-db (&optional in-file out-file)
|
||||||
"Migrate your existing `chronometrist-file' to an SQL database.
|
"Migrate your existing `chronometrist-file' to an SQL database.
|
||||||
|
@ -135,6 +161,7 @@ file names respectively."
|
||||||
out-file
|
out-file
|
||||||
" already exists - overwrite? "))
|
" already exists - overwrite? "))
|
||||||
t)
|
t)
|
||||||
|
(chronometrist-migrate-populate-sexp in-file)
|
||||||
(emacsql chronometrist-migrate-db
|
(emacsql chronometrist-migrate-db
|
||||||
[:create-table events ([name tags start stop])])
|
[:create-table events ([name tags start stop])])
|
||||||
(maphash (lambda (_key value)
|
(maphash (lambda (_key value)
|
||||||
|
|
|
@ -139,9 +139,11 @@
|
||||||
9. Function - chronometrist-events-query-spec-match-p (plist specifiers)
|
9. Function - chronometrist-events-query-spec-match-p (plist specifiers)
|
||||||
*** chronometrist-migrate.el
|
*** chronometrist-migrate.el
|
||||||
1. Variable - chronometrist-migrate-table
|
1. Variable - chronometrist-migrate-table
|
||||||
2. Function - chronometrist-migrate-populate (in-file)
|
2. Function - chronometrist-migrate-populate-timelog (in-file)
|
||||||
3. Function - chronometrist-migrate-timelog-file->sexp-file (&optional in-file out-file)
|
3. Function - chronometrist-migrate-timelog-file->sexp-file (&optional in-file out-file)
|
||||||
4. Function - chronometrist-migrate-check ()
|
4. Function - chronometrist-migrate-populate-sexp (in-file)
|
||||||
|
5. Function - chronometrist-migrate-sexp-file->sql-db (&optional in-file out-file)
|
||||||
|
6. Function - chronometrist-migrate-check ()
|
||||||
*** chronometrist-plist-pp.el
|
*** chronometrist-plist-pp.el
|
||||||
1. Variable - chronometrist-plist-pp-keyword-re
|
1. Variable - chronometrist-plist-pp-keyword-re
|
||||||
2. Variable - chronometrist-plist-pp-whitespace-re
|
2. Variable - chronometrist-plist-pp-whitespace-re
|
||||||
|
|
Reference in New Issue
Block a user