]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/metadata/resources/resources.factor
kernel: new combinator 2with = with with
[factor.git] / basis / vocabs / metadata / resources / resources.factor
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
4 vocabs.metadata ;
5 IN: vocabs.metadata.resources
6
7 <PRIVATE
8
9 : (expand-vocab-resource) ( resource-path -- filenames )
10     dup file-info directory?
11     [ dup '[ _ directory-tree-files [ append-path ] with map ] [ prefix ] bi ]
12     [ 1array ] if ;
13
14 : filter-resources ( vocab-files resource-globs -- resource-files )
15     '[ _ [ matches? ] with any? ] filter ;
16
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 ;
22
23 PRIVATE>
24
25 : vocab-dir-in-root ( vocab -- dir )
26     [ find-vocab-root ] [ vocab-dir ] bi append-path ;
27
28 : expand-vocab-resource-files ( vocab resource-glob-strings -- filenames )
29     [ vocab-dir-in-root ] dip [ <glob> ] map '[
30         _ filter-resources
31         [ (expand-vocab-resource) ] map concat
32     ] with-directory-tree-files ;
33
34 : vocab-resource-files ( vocab -- filenames )
35     dup vocab-resources
36     [ drop f ] [ expand-vocab-resource-files ] if-empty ;
37
38 : copy-vocab-resources ( dir vocab -- )
39     dup vocab-resource-files
40     [ 2drop ] [
41         [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
42         [ 2drop make-directories ]
43         [ [ copy-vocab-resource ] 2with each ] 3bi
44     ] if-empty ;