]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/metadata/resources/resources.factor
9c66456ab6327ae6b6647333ad6bd853e1779cc0
[factor.git] / basis / vocabs / metadata / resources / resources.factor
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
4 vocabs.metadata ;
5 IN: vocabs.metadata.resources
6
7 <PRIVATE
8
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 ;
14
15 PRIVATE>
16
17 : vocab-dir-in-root ( vocab -- dir )
18     vocab-source-path parent-directory ;
19
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 ;
24
25 ERROR: resource-missing pattern ;
26
27 : match-pattern ( pattern filenames -- filenames' )
28     over <glob> '[ _ matches? ] filter
29     [ resource-missing ] [ nip ] if-empty ;
30
31 : match-patterns ( patterns filenames -- filenames' )
32     '[ _ match-pattern ] gather ;
33
34 : vocab-resource-files ( vocab -- filenames )
35     [ vocab-resources ] [ vocab-dir-in-root ] bi
36     [
37         match-patterns [ expand-resource ] map concat
38     ] with-directory-files ;
39
40 : copy-vocab-resources ( dir vocab -- )
41     dup vocab-resource-files
42     [ 2drop ] [
43         [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
44         [ 2drop make-directories ]
45         [ [ copy-vocab-resource ] 2with each ] 3bi
46     ] if-empty ;