1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: fry globs io.directories io.directories.hierarchy io.files.info
4 io.pathnames kernel regexp sequences sets vocabs.loader
6 IN: vocabs.metadata.resources
10 : copy-vocab-resource ( to from file -- )
11 [ append-path ] curry bi@
12 dup file-info directory?
13 [ drop make-directories ]
14 [ swap make-parent-directories copy-file ] if ;
18 : vocab-dir-in-root ( vocab -- dir )
19 vocab-source-path parent-directory ;
21 : expand-resource ( resource-path -- filenames )
22 dup dup file-info directory? [
23 dup directory-tree-files [ append-path ] with map
24 ] [ drop { } ] if swap prefix ;
26 ERROR: resource-missing pattern ;
28 : match-pattern ( pattern filenames -- filenames' )
29 over <glob> '[ _ matches? ] filter
30 [ resource-missing ] [ nip ] if-empty ;
32 : match-patterns ( patterns filenames -- filenames' )
33 '[ _ match-pattern ] gather ;
35 : vocab-resource-files ( vocab -- filenames )
36 [ vocab-resources ] [ vocab-dir-in-root ] bi
38 match-patterns [ expand-resource ] map concat
39 ] with-directory-files ;
41 : copy-vocab-resources ( dir vocab -- )
42 dup vocab-resource-files
44 [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
45 [ 2drop make-directories ]
46 [ [ copy-vocab-resource ] 2with each ] 3bi