;;; TODO remove this module, it should be part of the vdir interface (define-module (vcomponent util parse-cal-path) :use-module (hnh util) :use-module ((calp util time) :select (report-time!)) :use-module (vcomponent base) :use-module (calp translation) :use-module ((vcomponent formats ical parse) :select (parse-calendar)) :use-module ((vcomponent formats vdir parse) :select (parse-vdir)) :export (parse-cal-path)) ;; Parse a vdir or ics file at the given path. (define (parse-cal-path path) ;; TODO check (access? path R_OK) ? (define st (stat path)) (define cal (case (stat:type st) [(regular) (prop (call-with-input-file path parse-calendar) '-X-HNH-SOURCETYPE 'file)] [(directory) (report-time! (G_ "Parsing ~a") path) (set-properties (parse-vdir path) (cons '-X-HNH-SOURCETYPE 'vdir) (cons '-X-HNH-DIRECTORY path))] [(block-special char-special fifo socket unknown symlink) => (lambda (t) (scm-error 'misc-error "parse-cal-path" (G_ "Can't parse file of type ~s") (list t) #f))])) (if (prop cal 'NAME) cal (prop cal 'NAME (or (prop cal 'X-WR-CALNAME) (string-append "[" (basename path) "]")))))