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