Advertisement
symdrome

Untitled

Feb 29th, 2024
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.46 KB | None | 0 0
  1. (in-package :ftp-log)
  2.  
  3. (ql:quickload :cl-ppcre)
  4. (ql:quickload :cl-strftime)
  5. (ql:quickload :file-attributes)
  6.  
  7. (defun get-log-file-list (logd op)
  8.   "Gets a list of names from the current log file"
  9.   (with-open-file (logfile
  10.            (format nil "~A~A-~A-ftp.log" logd op (cl-strftime:format-time nil "%d%m%Y"))
  11.            :if-does-not-exist :create)
  12.     (loop for line = (read-line logfile nil nil)
  13.       while line
  14.       collect (cl-ppcre:do-register-groups (fline)
  15.               ("\\S+\\s(\\w+.+)" line) (return fline)))))
  16.  
  17. (defun ftp-log (src fpattern logd op)
  18.   "Compares the files in the directory with the current log and updates the current log"
  19.   (let ((ftp-dir-files (directory (format nil "~A~A" src fpattern))))
  20.     (if (> (length ftp-dir-files) 0)
  21.     (let ((loglist (get-log-file-list logd op)))
  22.       (loop for file in ftp-dir-files
  23.         do
  24.            (if (not (member (format nil "~A.~A" (pathname-name file) (pathname-type file))
  25.                     loglist :test #'equal))
  26.                (with-open-file (logfile
  27.                     (format nil "~A~A-~A-ftp.log"
  28.                         logd op (cl-strftime:format-time nil "%d%m%Y"))
  29.                     :direction :output :if-does-not-exist :create :if-exists :append)
  30.              (write-line (format nil "~A ~A.~A"
  31.                          (cl-strftime:format-time nil :rfc-3339 (org.shirakumo.file-attributes:modification-time logfile))
  32.                          (pathname-name file) (pathname-type file) ) logfile))
  33.                nil))
  34.       nil))))
  35.  
  36. (defun main ()
  37.   (ftp-log "/data/genoa/upload/mp4/" "*.wav" "/data/genoa/tmp/" "genoa"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement