[Factor start.lisp into logical components clinton@unknownlamer.org**20080117175940 Now everything is part of the system proper ] { addfile ./src/config.lisp hunk ./src/config.lisp 1 - +(in-package :com.tee-it-up-golf.config) + +(defun make-golf-application () + (if *golf-app* + *golf-app* + (setf + *golf-app* + (make-instance 'golf-web:golf-application + :url-prefix "/" + :www-roots (list `("static/" + . ,(format nil "~A~A" + *golf-data-root* "wwwroot/"))) + + :javascript-log-level nil)))) + +(defun update-database-pathnames () + (setf (logical-pathname-translations "golf") + *golf-database-pathnames*)) + +(defvar *golf-dev-mode* t + "Flag if application is in developer mode (enable debugging)") + +(defvar *golf-data-root* "/home/clinton/local/var/tee-it-up/" + "Parent of wwwroot/ and log/") + +(defvar *golf-server* nil + "UCW Server for tee-it-up") + +(defvar *golf-request-length-limit* (* 10 1024 1024) + "Maximum request length in bytes") + +(defvar *golf-file-upload-root* "uploads" + "Subdirectory beneath *golf-data-root* to place uploaded files") + +(defvar *golf-database-pathnames* + `(("bdb;*" ,(format nil "~A~A" *golf-data-root* "bdb/*")) + ("audio;*" ,(format nil "~A~A" *golf-data-root* "audio-files/*"))) + "Logical pathname translations for elephant and audio file databases") + +(defvar *golf-app* nil) + +(update-database-pathnames) addfile ./src/entry-points.lisp hunk ./src/entry-points.lisp 1 - +(in-package :com.tee-it-up-golf.web) + +(defun create-entry-points () + + (defentry-point "^()$" (:application *golf-app* + :class regexp-dispatcher) + () + (call 'golf-frontend-window)) + + (defentry-point "^(index.ucw)$" (:application *golf-app* + :class regexp-dispatcher) + () + (call 'golf-frontend-window)) + + (defentry-point "^(admin.ucw)$" (:application *golf-app* + :class regexp-dispatcher) + () + (call 'golf-admin-window)) + + (defentry-point "^(audio.ucw)$" (:application *golf-app* + :class regexp-dispatcher) + (file) + (call 'audio-file-window + :audio-file (make-instance 'audio-file + :type "application/ogg" + :data file))) + + (defentry-point "^archive/(\\d{4})/(\\d{1,2})/(\\d{1,2})$" + (:application *golf-app* :class regexp-dispatcher) + () + (let ((year (parse-integer (aref *dispatcher-registers* 0))) + (month (parse-integer (aref *dispatcher-registers* 1))) + (day (parse-integer (aref *dispatcher-registers* 2)))) + (call 'full-show-viewer + :show (car (get-shows-by 'show-date + (encode-universal-time 0 0 0 day month year) + nil + :limit 1)))))) hunk ./src/packages.lisp 9 +(defpackage :com.tee-it-up-golf.config + (:use :common-lisp :ucw :ucw-compat) + (:nicknames :golf-config) + (:export + :*golf-dev-mode* + :*golf-data-root* + :*golf-server* + :*golf-request-length-limit* + :*golf-file-upload-root* + :*golf-app* ; maybe put into golf-app: package? This would allow + ; editing of config.lisp with fewer potential + ; conflicts. OTOH *golf-app* could simply be physically + ; placed in another file. + + :update-database-pathnames + :make-golf-application)) + hunk ./src/packages.lisp 31 + :brief-date hunk ./src/packages.lisp 72 - (:use :common-lisp :ucw :ucw-compat :golf-db :golf-util) + (:use :common-lisp :ucw :ucw-compat :golf-db :golf-util :golf-config) hunk ./src/packages.lisp 91 - ;; Methods + ;; Methods + + :create-entry-points hunk ./src/packages.lisp 97 - (:use :common-lisp :golf-web :golf-db :golf-util :ucw :ucw-compat) - (:nicknames :golf-user)) + (:use :common-lisp :golf-config :golf-web :golf-db :golf-util :ucw :ucw-compat) + (:nicknames :golf-user) + (:export + :start-site + :stop-site + :restart-site)) addfile ./src/site-control.lisp hunk ./src/site-control.lisp 1 - +(in-package :com.tee-it-up-golf.user) + +(defvar *golf-reaper* nil + "CLON Scheduler that expires sessions and deletes any stale uploads etc.") + +(defun start-reaping () + (stop-reaping) + (labels ((reaper () + (format *debug-io* "Reaping sessions... ~D~%" + (length (ucw::remove-expired-sessions *golf-app*))) + (format *debug-io* "Reaping files... ~D~%" + (length + (mapc (lambda (file) + (ignore-errors (delete-file file))) + (cl-fad:list-directory *file-upload-root*)))))) + (setq *golf-reaper* + (clon:schedule-function + #'reaper + (clon:make-scheduler (clon:make-typed-cron-schedule :hour '*)) + :thread t :name "ucw stale bread reaper")))) + +(defun stop-reaping () + (if *golf-reaper* + (setq *golf-reaper* + (sb-ext:unschedule-timer *golf-reaper*)))) + +(defun start-site () + (connect) + (make-golf-application) + (create-entry-points) + (prog1 + (setq *golf-server* + (ucw:create-server + :backend `(:iolib :port 50004 + :host "0.0.0.0") + :applications (list *golf-app*) + :log-level (if *golf-dev-mode* ucw::+debug+ ucw::+warn+) + :log-root-directory (format nil "~A~A" *golf-data-root* "log/"))) + + (setf (ucw::request-content-length-limit-of + (ucw::server.backend *golf-server*)) + *golf-request-length-limit*) + + (setf ucw:*debug-on-error* *golf-dev-mode*) + (setf ucw::*inspect-components* nil) + (setf (javascript-log-level *golf-app*) nil) + + (setq *file-upload-root* (format nil "~A/~A/" + *golf-data-root* *golf-file-upload-root*)) + (start-reaping))) + +(defun stop-site () + (disconnect) + (stop-reaping) + (ucw:shutdown-server *golf-server*) + (if (eq *golf-server* *default-server*) + (setq *default-server* nil)) + (setq *golf-server* nil)) + +(defun restart-site () + (stop-site) + (start-site)) hunk ./start.lisp 1 -(in-package :cl-user) - -;; Ugly, but neccessary to make the logical pathname stuff work for now - -(defvar *golf-data-root* "/home/clinton/local/var/tee-it-up/" - "Parent of wwwroot/ and log/") - -(setf (logical-pathname-translations "golf") - `(("bdb;*" ,(format nil "~A~A" *golf-data-root* "bdb/*")) - ("audio;*" ,(format nil "~A~A" *golf-data-root* "audio-files/*")))) - hunk ./start.lisp 2 -(asdf:operate 'asdf:load-op :clon) hunk ./start.lisp 7 -(defvar *golf-dev-mode* t - "Flag if application is in developer mode (enable debugging)") - -(defvar *golf-data-root* cl-user::*golf-data-root* - "Parent of wwwroot/ and log/") - -(defvar *golf-server* nil - "UCW Server for tee-it-up") - -(defvar *golf-request-length-limit* (* 10 1024 1024) - "Maximum request length in bytes") - -(defvar *golf-file-upload-root* "uploads" - "Subdirectory beneath *golf-data-root* to place uploaded files") - -(setf ucw:*debug-on-error* *golf-dev-mode*) -(setf ucw::*inspect-components* nil) - -(defvar *golf-app* - (make-instance 'golf-application - :url-prefix "/" - :www-roots (list `("static/" - . ,(format nil "~A~A" - *golf-data-root* "wwwroot/"))) - - :javascript-log-level nil)) - -(setf (javascript-log-level *golf-app*) nil) - -(defentry-point "^()$" (:application *golf-app* - :class regexp-dispatcher) - () - (call 'golf-web:golf-frontend-window)) - -(defentry-point "^(index.ucw)$" (:application *golf-app* - :class regexp-dispatcher) - () - (call 'golf-web:golf-frontend-window)) - -(defentry-point "^(admin.ucw)$" (:application *golf-app* - :class regexp-dispatcher) - () - (call 'golf-web:golf-admin-window)) - -(defentry-point "^(audio.ucw)$" (:application *golf-app* - :class regexp-dispatcher) - (file) - (call 'audio-file-window - :audio-file (make-instance 'audio-file - :type "application/ogg" - :data file))) - -(defentry-point "^archive/(\\d{4})/(\\d{1,2})/(\\d{1,2})$" - (:application *golf-app* :class regexp-dispatcher) - () - (let ((year (parse-integer (aref *dispatcher-registers* 0))) - (month (parse-integer (aref *dispatcher-registers* 1))) - (day (parse-integer (aref *dispatcher-registers* 2)))) - (call 'full-show-viewer - :show (car (get-shows-by 'show-date - (encode-universal-time 0 0 0 day month year) - nil - :limit 1))))) - -(defvar *golf-reaper* nil - "CLON Scheduler that expires sessions and deletes any stale uploads etc.") - -(defun start-reaping () - (stop-reaping) - (labels ((reaper () - (format *debug-io* "Reaping sessions... ~D~%" - (length (ucw::remove-expired-sessions *golf-app*))) - (format *debug-io* "Reaping files... ~D~%" - (length - (mapc (lambda (file) - (ignore-errors (delete-file file))) - (cl-fad:list-directory *file-upload-root*)))))) - (setq *golf-reaper* - (clon:schedule-function - #'reaper - (clon:make-scheduler (clon:make-typed-cron-schedule :hour '*)) - :thread t :name "ucw stale bread reaper")))) - -(defun stop-reaping () - (if *golf-reaper* - (setq *golf-reaper* - (sb-ext:unschedule-timer *golf-reaper*)))) hunk ./start.lisp 8 -(defun start-site () - (connect) - (prog1 - (setq *golf-server* - (ucw:create-server - :backend `(:iolib :port 50004 - :host "0.0.0.0") - :applications (list *golf-app*) - :log-level (if *golf-dev-mode* ucw::+debug+ ucw::+warn+) - :log-root-directory (format nil "~A~A" *golf-data-root* "log/"))) - (setf (ucw::request-content-length-limit-of - (ucw::server.backend golf-user::*golf-server*)) - *golf-request-length-limit*) - (setq *file-upload-root* (format nil "~A/~A/" - *golf-data-root* *golf-file-upload-root*)) - (start-reaping))) hunk ./start.lisp 9 -(defun stop-site () - (disconnect) - (stop-reaping) - (ucw:shutdown-server *golf-server*) - (if (eq *golf-server* *default-server*) - (setq *default-server* nil)) - (setq *golf-server* nil)) hunk ./start.lisp 10 -(defun restart-site () - (stop-site) - (start-site)) hunk ./tee-it-up.asd 9 - :components ((:module :src - :components - ((:file "packages") - (:file "util") - (:file "database" :depends-on ("util")) - (:file "ucw-compat") - (:file "web-common" - :depends-on ("ucw-compat" "database" "util")) - (:file "web-admin" :depends-on ("web-common")) - (:file "web-frontend" :depends-on ("web-common")) - (:file "tests")) - :serial t)) ; todo: when deps stop being serial... + :components + ((:module + :src + :components + ((:file "packages") + (:file "util" :depends-on ("packages")) + (:file "authentication" :depends-on ("packages")) + (:file "config" :depends-on ("packages")) + + (:file "database" :depends-on ("util" "config" "packages")) + (:file "ucw-compat" :depends-on ("packages")) + + (:file "web-common" + :depends-on ("config" "ucw-compat" "database" "util" "packages")) + (:file "web-admin" :depends-on ("web-common")) + (:file "web-frontend" :depends-on ("web-common")) + (:file "entry-points" :depends-on ("config" "web-common" "web-frontend" "web-admin")) + + (:file "site-control" :depends-on ("config" "web-common")) + + (:file "tests")))) }