1 ! (c)2010 Joe Groff bsd license
2 USING: arrays fry globs io.directories io.directories.hierarchy
3 io.files.info io.pathnames kernel regexp sequences vocabs.loader
5 IN: vocabs.metadata.resources
9 : (expand-vocab-resource) ( resource-path -- filenames )
10 dup file-info directory?
11 [ dup '[ _ directory-tree-files [ append-path ] with map ] [ prefix ] bi ]
14 : filter-resources ( vocab-files resource-globs -- resource-files )
15 '[ _ [ matches? ] with any? ] filter ;
17 : copy-vocab-resource ( to from file -- )
18 [ append-path ] curry bi@
19 dup file-info directory?
20 [ drop make-directories ]
21 [ swap [ parent-directory make-directories ] [ copy-file ] bi ] if ;
25 : vocab-dir-in-root ( vocab -- dir )
26 [ find-vocab-root ] [ vocab-dir ] bi append-path ;
28 : expand-vocab-resource-files ( vocab resource-glob-strings -- filenames )
29 [ vocab-dir-in-root ] dip [ <glob> ] map '[
31 [ (expand-vocab-resource) ] map concat
32 ] with-directory-tree-files ;
34 : vocab-resource-files ( vocab -- filenames )
36 [ drop f ] [ expand-vocab-resource-files ] if-empty ;
38 : copy-vocab-resources ( dir vocab -- )
39 dup vocab-resource-files
41 [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
42 [ 2drop make-directories ]
43 [ [ copy-vocab-resource ] 2with each ] 3bi