[REBOL] Re: make-doc-pro: Version 1.0.3 beta update
From: anton:lexicon at: 5-Jun-2002 3:30
Robert,
This problem (forgetting to uncomment testing code)
annoyed me so much I made a tool for pushing my
library files into the public cache.
You use it from the console like this:
push-cache %afile.r
It expects that you have a local mirror of your
rebsite under view/local/ directory, but you can
easily change it.
Anyway, the script is at the bottom.
(Watch out! I expect line wrap is pretty bad.)
It has a complete usage example.
My site is down. I'll probably set up a new one tomorrow.
Anton.
> > I have tried to run http://www.robertmuench.de/make-doc-pro.r but got
> > an error ...
> >
> > ** Access Error: Cannot open /d/rebview/public/rm_library.r
> > ** Where: do-boot
> > ** Near: do %../rm_library.r
>
> Hi, ups sorry I'm still loading my internal library. For the
> released version, I
> normally comment this.
rebol [
Title: "Push Cache"
File: %push-cache.r
Date: 20-Mar-2002
Version: 1.0.6
Needs: []
Author: "Anton Rolls"
Language: 'English
Purpose: {To push files from local/ directory into the public cache}
Usage: {
site: http://your-site/rebol/
anton-lib: http://anton.idatam.com.au/rebol/library/
do load-thru anton-lib/include.r
include [
anton-lib/dir-utils.r [version?]
anton-lib/push-cache.r [push-cache]
]
; now ready to use push-cache in script or in console
; eg. push-cache %afile.r ;(don't need to specify path)
}
ToDo: {
- somehow report success with /quiet for util/push-into-cache.r
- if errors writing the file in copy-file (check for owner-write)
show-file-modes
- /force for copying older onto newer
- incorporate into dir-utils? or maybe a new cache-utils? reb-utils?
- make doc/push-cache-flow-diagram.r
}
History: [
1.0.0 [6-Jan-2002 {First version} "Anton"]
1.0.1 [18-Feb-2002 {wrapped in context to comply with new include
framework,
filling it full of goodness, seems to function correctly
} "Anton"]
1.0.2 [21-Feb-2002 {added copy-file helper function} "Anton"]
1.0.3 [27-Feb-2002 {fixed bug by moving copy-file into push-cache}
Anton
]
1.0.4 [28-Feb-2002 {commented site, added usage, added cache-site,
change-cache-site} "Anton"]
1.0.5 [1-Mar-2002 {fixed bug checking for empty? common-path,
checking for existance of source file} "Anton"]
1.0.6 [20-Mar-2002 {reporting cache-file} "Anton"]
]
Notes: {
push-cache expects 'site to be set at the time this file is
included (or you do it). Consequently, this value is stored
in cache-site and won't change unless you use change-cache-site.
}
Public-Functions: [push-cache change-cache-site] ; for include
]
;site: http://anton.idatam.com.au/rebol/ ; <--- change to your site,
push-cache expects this
context [ ; protective wrap necessary for include framework
cache-site: site
change-cache-site: func [new-cache-site [url!]][cache-site: new-cache-site]
push-cache: func [
"copy (push) a file from local directory into the public cache"
file "file you would like to copy"
/quiet "don't print anything"
/local local-dir clean-file common-path cache-file
info1 info2 hash version1 version2 copy-file report
][
report: func [arg] either quiet [[]][[
print arg
]]
;report ["cache-site:" cache-site]
local-dir: join system/options/home %local/
copy-file: has [err][
make-dir/deep first split-path cache-file ; ensure directory exists
either error? set/any 'err try [
write cache-file read/binary clean-file
][
report "problem writing the file"
if not get-modes cache-file 'owner-write [
report join form cache-file " has false owner-write file-mode. (File is
read-only.)"
]
][
report "wrote file successfully"
]
]
if not exists? file [report "file not found" return]
clean-file: clean-path file ; get absolute path to file
either found? common-path: find/tail clean-file local-dir [ ; file has to
be under local-dir
either dir? clean-file [
report "it's a directory - no action taken"
][
cache-file: path-thru cache-site/:common-path
report ["cache-file:" cache-file]
; copy file here
either exists? cache-file [
report [common-path "already exists"]
info1: info? clean-file
info2: info? cache-file
either all [
info1/size = info2/size
(checksum read/binary clean-file) = (checksum read/binary cache-file)
][
; contents same
report "files the same - no action"
][
; contents different
hash: 2 * (to-integer none? script? clean-file) + (to-integer none?
script? cache-file)
switch hash [
0 [
; both are scripts
if (version1: version? clean-file) > (version2: version? cache-file)
[
report "newer version, copying"
copy-file
]
if version1 = version2 [
; file contents different, but versions the same
either info1/date > info2/date [
report "newer date, copying"
copy-file
][
; ignore
report "cache file has same date or newer - no action"
]
]
; (if older version - no action)
]
3 [
; neither are scripts
either info1/date > info2/date [
report "newer date, copying"
copy-file
][
; ignore
report "cache file has same date or newer - no action"
]
]
1 [
report "warning - one file is a script, the other not - no action."
]
2 [
report "warning - one file is a script, the other not - no action."
]
]
]
][
report "not in the cache, copying"
copy-file
]
]
][
report ["file not under" local-dir]
]
]
] ; end of context
-------- end -----------