defs.rkt 4.28 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1
#lang racket/base
Robert Ricci's avatar
Robert Ricci committed
2
(require scribble/base)
3
(require scribble/decode)
4
(require scribble/manual)
5 6
(require racket/class)
(require racket/draw)
7 8
(require racket/system)
(require racket/port)
9
(require racket/vector)
10
(require racket/file)
Robert Ricci's avatar
Robert Ricci committed
11 12 13

(provide (all-defined-out))

14
; Check to see if we are building Apt or CloudLab documentation
Gary Wong's avatar
Gary Wong committed
15 16 17 18 19 20 21
(define tb-mode
  (cond
   ((vector-member "clab" (current-command-line-arguments))
    'clab)
   ((vector-member "pnet" (current-command-line-arguments))
    'pnet)
   (else 'apt)))
22

23
(define (apt?) (if (equal? tb-mode 'apt) #t #f))
24
(define (clab?)  (if (equal? tb-mode 'clab) #t #f))
Gary Wong's avatar
Gary Wong committed
25
(define (pnet?)  (if (equal? tb-mode 'pnet) #t #f))
26

27 28 29 30 31 32 33 34
; Check to see if we are building for web or PDF; there is probably some
; nicer way to do this by inspecting the scribble/run state directly, but
; I haven't figured it out
(define doc-mode
    (if (vector-member "pdf" (current-command-line-arguments))
      'pdf
      'html))

Gary Wong's avatar
Gary Wong committed
35 36 37 38 39
(define (apt-vs-clab #:apt [apt-version (list)] #:clab [clab-version (list)] #:pnet [pnet-version (list)])
  (case tb-mode
	('apt apt-version)
	('clab clab-version)
	('pnet pnet-version)))
40

Gary Wong's avatar
Gary Wong committed
41 42 43 44 45
(define (apt-vs-clab* #:apt [apt-version ""] #:clab [clab-version ""] #:pnet [pnet-version ""])
  (decode-flow (list (case tb-mode
			   ('apt apt-version)
			   ('clab clab-version)
			   ('pnet pnet-version)))))
46

47
(define (apt-only . stuff)
48
  (apt-vs-clab #:apt stuff))
49

50
(define (clab-only . stuff)
51
  (apt-vs-clab #:clab stuff))
52

Gary Wong's avatar
Gary Wong committed
53 54 55
(define (pnet-only . stuff)
  (apt-vs-clab #:pnet stuff))

56
(define apt-base-url
Gary Wong's avatar
Gary Wong committed
57 58 59 60
  (case tb-mode
	('apt "https://www.aptlab.net/")
	('clab "https://www.cloudlab.us/")
	('pnet "https://www.phantomnet.org/")))
61

62
(define apt-doc-url
Gary Wong's avatar
Gary Wong committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  (case tb-mode
	('apt "http://docs.aptlab.net/")
	('clab "http://docs.cloudlab.us/")
	('pnet "http://docs.phantomnet.org/")))

(define forum-url
  (case tb-mode
	('apt "https://groups.google.com/forum/#!forum/apt-users")
	('clab "https://groups.google.com/forum/#!forum/cloudlab-users")
	('pnet "https://groups.google.com/forum/#!forum/phantomnet-users")))

(define tb (lambda () (case tb-mode
			    ('apt "Apt")
			    ('clab "CloudLab")
			    ('pnet "PhantomNet"))))
78

79 80 81 82
; We want the 'version' to be the date of the most recent commit
(define apt-version
  (with-output-to-string
    (lambda () (system "git show -s --date=short --format='%cd (%h)' HEAD"))))
83

84 85
; Arbitrary width that works reasonably well with the manual class's main
; column width
86 87 88 89 90 91
(define screenshot-width 650)

(define apturl
  (case-lambda
    [() apt-base-url]
    [(page) (string-append apt-base-url page)]))
Robert Ricci's avatar
Robert Ricci committed
92

93
(define (TODO . what)
94
  (bold "TODO: " (decode-content what)))
95 96 97 98 99 100 101 102

(define nodetype
  (lambda (typename howmany . properties)
          (tabular #:style 'boxed #:sep (hspace 3)
                   (cons
                     (list (bold typename)
                           (string-append (number->string howmany) " nodes"))
                     properties))))
103

104
(define (screenshot path)
105 106
  (let* ([aptpath (string-append "screenshots/apt/" path)]
         [clabpath (string-append "screenshots/clab/" path)]
Gary Wong's avatar
Gary Wong committed
107 108 109 110 111 112 113 114 115 116 117
         [pnetpath (string-append "screenshots/pnet/" path)]
         [fullpath (case tb-mode
			 ('apt aptpath)
			 ('clab
			  (if (file-exists? clabpath)
			      clabpath
			    (cdr (cons (displayln (string-append "WARNING: CloudLab missing screenshot " path)) aptpath))))
			 ('pnet
			  (if (file-exists? pnetpath)
			      pnetpath
			    (cdr (cons (displayln (string-append "WARNING: PhantomNet missing screenshot " path)) aptpath)))))]
118 119
         [b (make-object bitmap% fullpath)]
         [width (send b get-width)]
Robert Ricci's avatar
Robert Ricci committed
120
         [scale-factor (* 1.0 (/ screenshot-width width))])
121 122 123
    (list (image #:scale scale-factor fullpath fullpath) (linebreak))))

(define (instructionstep step #:screenshot [screenshot-path #f] . body)
124 125
  (item (bold (decode-content (list step)))
        (linebreak)
126
        (decode-flow body)
127 128
        (if screenshot-path
          (screenshot  screenshot-path)
129
          (void))))
130 131 132

(define (under-construction)
  (bold "This section is under construction"))
133 134 135 136 137

(define (future-work tag)
  (margin-note "There are planned features relating to this section: see \""
               (secref tag)
               "\" for more details."))
138 139 140

(define (ssh)
  (tt "ssh"))
141 142

(define (code-sample filename)
143
  (code-inset (verbatim (file->string (string-append "code-samples/" filename)))))