-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive2.rkt
99 lines (87 loc) · 2.65 KB
/
archive2.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#lang racket
(require racket/path)
(require racket/runtime-path)
(require "core.rkt"
"iso.rkt"
"cdrom.rkt"
"dir.rkt"
)
(define (main)
(with-handlers ([exn? (lambda (e)
(when (directory-exists? (get 'temp))
(delete-directory/files (get 'temp))))])
(match (get 'archive-type)
['NOVALUE (printf "Exiting.~n")]
['iso
(archive-iso)]
['disc
(archive-cdrom)
]
['dir (archive-dir)]
)
;; Remove the tempdir when we're done
(when (directory-exists? (get 'temp))
(delete-directory/files (get 'temp)))
))
(define (parser)
(command-line
#:usage-help
"Archive discs, ISOs, or directories."
#:once-any
[("--iso") ISO-PATH
"For archiving ISOs"
(put 'archive-type 'iso)
(put 'iso-path ISO-PATH)]
[("--disc")
"Path to the disc (/dev/sr0)"
(put 'archive-type 'disc)]
[("--dir") DIR-PATH
"Directory to tar and archive"
(put 'archive-type 'dir)
(put 'dir-path DIR-PATH)
]
#:once-each
[("--dry-run")
"Does not execute any commands."
(put 'dry-run true)]
[("--dd") DD-PATH
((format "Path to `dd` against. /dev/sr0 or similar"))
(put 'dd-path DD-PATH)]
[("--redundancy") REDUNDANCY
((format "Percentage of redundancy in the PAR2 archive; default is ~a" (get 'redundancy)))
(put 'redundancy (string->number REDUNDANCY))]
[("--split-size") SPLIT-SIZE
((format "Size of splits in MB/GB; default is ~a" (get 'split-size)))
(put 'split-size SPLIT-SIZE)]
[("--gzip")
"Compress. (Only used when doing a directory archive.)"
(put 'gzip true)]
[("--bucket") BUCKET
((format "Name of the B2 bucket to sync to"))
(put 'bucket BUCKET)]
[("--temp") TEMP
"Temporary directory for working."
(put 'temp TEMP)]
[("--destination") DESTINATION
((format "Local path to place the archive"))
(put 'destination DESTINATION)]
#:args ()
(main)
))
(parser)
(module+ test
(require rackunit)
(printf "SHOWING HELP~n")
(exit-handler (lambda x 'exited))
(current-command-line-arguments
(vector "--help"))
(parser)
(current-command-line-arguments
(vector
"--iso" "photos-fs101-2010-fedora.iso"
"--redundancy" "20"
"--split-size" "50M"
"--destination" "/tmp/destination"))
(parser)
(check-equal? (get 'iso-path) "photos-fs101-2010-fedora.iso")
)