1 ! (c)2010 Joe Groff bsd license
2 USING: fry globs io.directories io.directories.hierarchy io.files.info
3 io.pathnames kernel regexp sequences sets vocabs.loader
5 IN: vocabs.metadata.resources
9 : copy-vocab-resource ( to from file -- )
10 [ append-path ] curry bi@
11 dup file-info directory?
12 [ drop make-directories ]
13 [ swap make-parent-directories copy-file ] if ;
17 : vocab-dir-in-root ( vocab -- dir )
18 vocab-source-path parent-directory ;
20 : expand-resource ( resource-path -- filenames )
21 dup dup file-info directory? [
22 dup directory-tree-files [ append-path ] with map
23 ] [ drop { } ] if swap prefix ;
25 ERROR: resource-missing pattern ;
27 : match-pattern ( pattern filenames -- filenames' )
28 over <glob> '[ _ matches? ] filter
29 [ resource-missing ] [ nip ] if-empty ;
31 : match-patterns ( patterns filenames -- filenames' )
32 '[ _ match-pattern ] gather ;
34 : vocab-resource-files ( vocab -- filenames )
35 [ vocab-resources ] [ vocab-dir-in-root ] bi
37 match-patterns [ expand-resource ] map concat
38 ] with-directory-files ;
40 : copy-vocab-resources ( dir vocab -- )
41 dup vocab-resource-files
43 [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
44 [ 2drop make-directories ]
45 [ [ copy-vocab-resource ] 2with each ] 3bi