;; Emacs-Time-stamp: "2007-10-31 09:14:25" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-ftp.el\"") ;;; 2006.11.18 - check *.el for "bsb". ;;; 2006.11.18 - check *.el for "write-" as in "-file" and "-region" ;;; DONE. 2006.11.18 - check *.el for "append-to" as in "-to-file" or "-buffer" ;;; DONE. 2006.11.18 - check *.el for "save-buffer". ;;; login@debian:~/leninist.biz$ egrep -Hi 'save-buffer' *.el ;;; DONE. ;;; login@debian:~/leninist.biz$ egrep -Hi 'save-buffer' *.el ;;; login@debian:~/leninist.biz$ egrep -Hi 'append-to' *.el ;;; DONE. ;;; login@debian:~/leninist.biz$ egrep -Hi 'append-to' *.el ;;; login@debian:~/leninist.biz$ egrep -Hi 'write-f' *.el ;;; DONE. ;;; login@debian:~/leninist.biz$ ;;; login@debian:~/leninist.biz$ egrep -Hi 'write-r' *.el ;;; DONE. ;;; login@debian:~/leninist.biz$ ;; (defun lb-ftp-insert-file (arg1command) "Used by lb-lftp-dosomething-file when buffer exists or buffer does not exist but file does exist" ;; (let ( _rc) (save-excursion (save-match-data (goto-char (car (_-where-double-newlines))) ;; Put all "rm"s on top of all "put"s! (if (string-match "rm " arg1command) (insert "" lb-command "\n") ;; Just so happens that index.html is uploaded before BIG index.txt ;; put index.html ;; put index.txt (goto-char (cdr (_-where-double-newlines))) (insert "\n" arg1command "")) )) _rc)) ;; (lb-lftp-dosomething-file "~/leninist.biz/en/1989/HCM243/Revolution") ;; (lb-lftp-dosomething-file "~/leninist.biz/en/1989/HCM243/Revolution.tx2") ;; (lb-lftp-dosomething-file "~/leninist.biz/en/TAZ") (defun lb-lftp-dosomething-file (arg1pf &optional arg2action) "" ;; ;; SEE ALSO: ;; 12 lines matching "lftp" in buffer lia-sgml.el. (let (lb-re lb-str lb-path-cd lb-path-lcd lb-path-testit lb-buffer (_s " ") lb-post-domain-assumed-exist-on-server lb-post-domain-assumed-exist-on-server-NOT lb-command lb-date (lb-pre-buffer (current-buffer)) _rc) (save-match-data (save-excursion (progn (if (not arg2action) (setq arg2action "put")) ;; Add trailing space. (if (not (string-match " $" arg2action)) (setq arg2action (concat arg2action " "))) ;; (setq lb-path-lcd (file-name-directory arg1pf)) (if (or (not lb-path-lcd) (string= "./" lb-path-lcd)) (setq lb-path-lcd (concat lb-home lbg-path-from-lang "/"))) (if (and (not (string-match lb-home lb-path-lcd)) (not (string-match "^/home/" lb-path-lcd))) (error "%s: %s" "Expecting lb-home or ^/home in" lb-path-lcd)) (setq lb-lftp-source "lftp.source") (setq lbg-lftp-source (concat lb-path-lcd lb-lftp-source)) (if (file-exists-p (setq lb-pidfile (concat lb-lftp-source ".pid"))) (error "%s: %s" "lftp running?" lb-pidfile)) ;; no newline! (setq lb-command (concat arg2action (file-name-sans-directory arg1pf) ""))) ;; fix? Maybe already fixed in lb-ht ? ;; Kill this buffer at end of processing; not killed here. (cond ;; 2007.10.31 ;; fix! Use same insert logic for existing file *AND* existing buffer. ;; (1.) Add line to existing buffer. ((setq lb-buffer (find-buffer-visiting lbg-lftp-source)) (set-buffer lb-buffer) (when (not (_-string-exist-end-of-line-p lb-command)) ;; 2007.10.31 (lb-ftp-insert-file lb-command) (basic-save-buffer-1))) ;; (2.) Add line to existing file. ((file-exists-p lbg-lftp-source) ;; fix! Check paths! ;; Due to LOC, might rename folder after this file started. ;;;6 lines matching "231" in buffer lftp.source. ;;; 2:lcd /home/login/leninist.biz/es/1974/SR231/ ;;; 3:cd /leninist.biz/data/es/1974/SR231/ ;;; 5:!touch /home/login/leninist.biz/es/1974/SR231/lftp.source.pid ;;; 83:!rm -f /home/login/leninist.biz/es/1974/SR231/lftp.source.pid ;;; 85:!cat /home/login/leninist.biz/es/1974/SR231/lftp.source >>/home/login/leninist.biz/es/1974/SR231/.lftp.source.oldcat ;;; 87:!rm -f /home/login/leninist.biz/es/1974/SR231/lftp.source (set-buffer (find-file-literally lbg-lftp-source)) (setq backup-inhibited t) ;; fix? do this for existing buffer too? ;; Did path change due to LOC last-page-numbered? (goto-char (point-min)) (while (search-forward-string "cd " nil t) (if (and (looking-at "[^ \t\n]+") (setq lb-path-testit (match-string-no-properties 0)) (setq lb-path-testit (lb-get-id-from-path lb-path-testit)) (= 3 (length (split-string lb-path-testit "/")))) (if (not (string= (setq lb-str (lb-get-id-from-path lb-path-lcd)) lb-path-testit)) (error "%s: %s" lb-str (_-current-line))))) (goto-char (point-max)) (search-backward-regexp "^\\(m?rm\\|m?put\\) ") ;;1of2 (when (not (_-string-exist-end-of-line-p lb-command)) ;; 2007.10.31 (lb-ftp-insert-file lb-command) (basic-save-buffer-1))) ;; (3.) Create a fresh file and add to it. (t (set-buffer (find-file-literally lbg-lftp-source)) ;; BEGIN. (insert "\n") (insert _s"lcd " lb-path-lcd "\n") (insert _s"!touch " lb-pidfile "\n") (insert _s"!cp -f "lb-lftp-source" "lb-lftp-source".lag\n") (insert _s"cd " (setq lb-path-cd (concat "/" lb-domain "/data/" (progn (string-match (concat ".*" lb-domain "/" lb-re-lang "/" "\\(" ".*" "\\)") lb-path-lcd) (setq lb-post-domain-assumed-exist-on-server-NOT (match-string 2 lb-path-lcd)) (setq lb-post-domain-assumed-exist-on-server (match-string 1 lb-path-lcd))))) "\n") (loop for folder in (split-string lb-post-domain-assumed-exist-on-server-NOT "/") do (insert _s"mkdir " folder "\n") (setq lb-path-cd (concat lb-path-cd "/" folder)) (insert _s" cd " folder "\n")) ;; Add trailing slash. (setq lb-path-cd (concat lb-path-cd "/" "")) (insert "\n") ;; MIDDLE. (insert lb-command "\n") ;; END. (insert "\n") ;; (lb-get-id-from-path "~/leninist.biz/en/1989/HCM243/") ;; (lb-get-id-from-path "~/leninist.biz/en/1989/" nil) ;; (lb-get-id-from-path "~/leninist.biz/en/1989/" t) ;; (lb-get-id-from-path "~/leninist.biz/en/" t) (insert _s"cd .; lcd .; ls > .lftp.ls\n") ;; Walk up the branch. (loop for i from 1 to (length (split-string (lb-get-id-from-path lb-path-lcd t) "/")) do (insert _s"cd ..; lcd ..; ls > .lftp.ls\n")) (insert _s"lcd " lb-path-lcd "\n") (insert _s"cd " lb-path-cd "\n") (insert _s"" ;; 2007.01.01 - keep copies 2 months from now. (if (or (string< "2007-03-01T15:05:36-0800" (_-current-time)) lbg-ftp-save-source-p) "#" "") "!" "cat " lb-lftp-source " >>" ;; Hide it with leading ".". "." lb-lftp-source ".oldcat" "\n") (insert _s"!" "rm -f " lb-lftp-source " " lb-pidfile "\n") (insert _s"echo " (setq lb-date (lb-date)) "; echo ""\n") (insert _s"!find " lb-home " -follow -name " lb-lftp-source "\n") (insert "# " " -------------------------------------END------------------" "\n") (insert "\n") (search-backward-regexp "^\\(m?rm\\|m?put\\) ") ;;2of2 (basic-save-buffer-1)) ) ;; cond ;; No matter how it got here, bury it. (bury-buffer))) ;; Recursion. Almost. ;; (setq arg1pf "~/leninist.biz/en/sitemap") (when (string-match (concat lb-re-lang "/sitemap$") arg1pf) (lb-lftp-dosomething-file ;; fix! make sure zz/index.html is a symbolic link to sitemap. (concat (file-name-directory arg1pf) lb-file-indexhtml))) _rc)) (provide 'lb-ftp) ;;; ;