;; Batch.
;; Emacs-Time-stamp: "2010-06-23 17:42:04"
(setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-batch.el\"")

;; _________________________________
;; IMPORTANT!  
;;   UPDATE DATABASE (.db files) IN FILESYSTEM!
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;x
;; Execute "$ bash lb.sh es 1" to refresh "es" file-system database.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ( pushd ~/leninist.biz; 
;;   emacs -batch -l lb-batch.el 2>&1 | mail -s lb-batch.el ysverdlov@localhost; 
;;   popd; ) 

;; _________________________________
;; IMPORTANT!
;;   SET LANGUAGE!
(progn
  (load "lb")

  (setq lb-lang "en")
  (setq lb-lang "es")

  )

;; 2010.06.21 - fix!  es/.db.list should be *NEW* and at least 183 lines. CHECK!
;; 2010.06.21 - fix!  en/.db.list should be *NEW* and at least 1793 lines. CHECK!
;; $ commands:
;; 501	 pushd ~/leninist.biz/ ;  bash lb.sh es 1 ; popd
;; 502	 pushd ~/leninist.biz/ ;  bash lb.sh en 1 ; popd

;; 2010.03.20
(with-temp-buffer
  (insert (_-timestamp t t) ": START.\n")
  (append-to-file
   (point-min) (point-max)
   (concat (file-name-sans-extension (file-stamp-get-stamp)) ".log")))

(defvar lbg-batch nil "Batch mode?") ;; (boundp 'lbg-batch)

;; 2007.02.12 - made symbolic link from ~/bin to ~/leninist.biz
(unless (featurep 'file-stamp) (load "file-stamp"))

;; 2009.05.31 - unless added:
(unless (member "~/leninist.biz/" load-path)
  (setq load-path (append (list "~/leninist.biz/") load-path)))

(unless (featurep 'lb)         (load "lb"))

;; NOTE: Unable to resolve HREF ... ?
;; NOTE:   ... defun lb-mu-href-replace-uptree
;; NOTE:   ... See: lb-defvar.el: lb-list-href-ok-not-file-exist

(setq lb-debug nil)

;; (kill-buffer " *load*")

;; 0-59/5 0-23/1 * * * ( pushd ~/leninist.biz; emacs -batch -l lb-batch.el 2>&1 | mail -s s ysverdlov@yahoo.com; popd; )

;; TO-DO: Each subdirectory needs an ".index"
;;
;; TO-DO: 
;;
;; TO-DO: 
;;
;; TO-DO: 
;;

;; emacs -batch --eval '(setq debug-on-error t)'
;; (setq debug-on-error t)

;; Each subdirectory has a .index to describe contents of database.

;; pf = pathfile
;; pt = point

;; (lb-batch-files-exist nil)
(defun lb-batch-files-exist (arg1p) ; 2005.05.21
  "Do files exist"
  ;; 
  (interactive "p") 
  (unless (featurep 'lb-batch) (save-some-buffers))
  (let (lb-pt0 lb-pt1 lb-pf lb-rc)
    (with-temp-buffer
      (insert-file lb-file-filelist)
      (goto-char (point-min))
      (while (< (point) (point-max))
	(if (looking-at "\n") (forward-char 1))
	(save-excursion (setq lb-pt0 (point)) (end-of-line)
			(setq lb-pt1 (point)))
	(setq lb-pf
	      (_-normalize-whitespace
	       (buffer-substring-no-properties lb-pt0 lb-pt1)))
	(message lb-pf)
	(if (and (not (string-match "^[ \t]*[#]" lb-pf))
		 (not (file-exists-p lb-pf)))
	    (progn (insert "File not found: ")
		   (end-of-line)
		   (if (looking-at "\n") (forward-char 1)))
	  (delete-region lb-pt0 lb-pt1)
	  (if (looking-at "\n") (replace-match ""))))
      (_-compress-multiple-newlines)
      ;; Buffer might have a single newline, nothing else.
      (if (< (point-max) 5) (erase-buffer))
      (setq lb-rc (buffer-string)))
    (if (string= "" lb-rc) nil lb-rc)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; fix!
;; Insert letter in  bar, e.g., missing "M" here:
;; leninist.Biz: Titles (English)

;; 2009.06.06
(lb-db-go-speed-racer-inventory)

;; 2008.06.08
(lb-qa-dotindex-source)

(lb-mu-htmm-to-html "~/leninist.biz/index.htmm")

(lb-mu-spawn-x-by-letter "titl" lb-AZ) ;; TIME-CONSUMING

(lb-mu-spawn-x-by-letter "auth" lb-AZ) ;; TIME-CONSUMING

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Copy /en/titl.html  -> to -> /en/index.html
(when nil
  (copy-file (concat lb-home lb-lang "/titl" "" lb-ext-html)
	     (concat lb-home lb-lang "/" lb-file-index "" lb-ext-html) t t)
  ;; INSTEAD: handle symlink manually.
  )

;; /index.html is hand-rolled.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(progn

  (lb-mu-spawn-formats "html") ;; DOES: (lb-mu-make-webpage "HTML")

  (lb-mu-spawn-formats "text") ;; DOES: (lb-mu-make-webpage "text")

  ;; We decided not to put printable formats online.  See www.useit.com !
  (if nil
      (lb-mu-spawn-formats "ps") ;; DOES: (lb-mu-make-webpage "PS")
    (lb-mu-make-webpage "PS"))
  (if nil
      (lb-mu-spawn-formats "pdf") ;; DOES: (lb-mu-make-webpage "PDF")
    (lb-mu-make-webpage "PDF"))

  ;; 
  (lb-mu-spawn-taz-)
  ;;
  )

;; 2010.03.20
(with-temp-buffer
  (insert (_-timestamp t t) ": END.\n\n")
  (append-to-file
   (point-min) (point-max)
   (concat (file-name-sans-extension (file-stamp-get-stamp)) ".log")))

(provide 'lb-batch)
;;;
					;