]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/metadata/resources/resources.factor
Switch to https urls
[factor.git] / basis / vocabs / metadata / resources / resources.factor
1 ! Copyright (C) 2010 Joe Groff.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: globs io.directories io.files.info io.pathnames kernel
4 regexp sequences sets vocabs.loader 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         recursive-directory-files
23     ] [
24         drop { }
25     ] if swap prefix ;
26
27 ERROR: resource-missing pattern ;
28
29 : match-pattern ( pattern filenames -- filenames' )
30     over <glob> '[ _ matches? ] filter
31     [ resource-missing ] [ nip ] if-empty ;
32
33 : match-patterns ( patterns filenames -- filenames' )
34     '[ _ match-pattern ] gather ;
35
36 : vocab-resource-files ( vocab -- filenames )
37     dup vocab-resources [
38         swap vocab-dir-in-root
39         [
40             match-patterns [ expand-resource ] map concat
41         ] with-directory-files
42     ] [ drop f ] if* ;
43
44 : copy-vocab-resources ( dir vocab -- )
45     dup vocab-resource-files
46     [ 2drop ] [
47         [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
48         [ 2drop make-directories ]
49         [ [ copy-vocab-resource ] 2with each ] 3bi
50     ] if-empty ;