On 10/12/2010, at 6:34 AM, Erick Tryzelaar wrote:
> On Wed, Dec 8, 2010 at 1:34 PM, john skaller
> <[email protected]> wrote:
>>
>> Another approach is probably better: directories simply don't exist.
>> All files live in the root, they just have structured names.
>> This interpretation is the most consistent and easiest to work with.
>>
>> You'd so something like:
>>
>> copy fred/(.*\.flx) joe/\1
>>
>> which clearly descends into subdirectories of the src, or if that isn't
>> wanted:
>>
>> copy fred/([^/]*\.flx) joe/\1
>>
>> because here the regex can't match a path name with a / in it.
>>
>> It's a bit messy because "." means "any character" and so you have to
>> use "\." when you mean the "." character.
>>
>> I plan to implement this :)
>
> Conceptually this is pretty simple, though may be pretty inefficient
> to do it on top of python's regular expression library. The naive
> approach is to just do a full treewalk and to a regex substitution. To
> eliminate the treewalk you'd have to parse the regex to see which
> files match the partial directory. For instance, if you wrote (in
> python's regex extension):
>
> copy_regex(r'(?:(foo/.*/bar)|(bar/.*\.baz))', r'dst/\1')
>
> You could optimize it to just do a treewalk down foo/, and just match
> everything in bar/, but I'm not sure how to support that.
I told you before :) The "root" from and to directories should be
given separately. Otherwise you can't easily tell what's going on easily:
copy_regular(from="foo", to="bar",pattern="..regex..",rename="..")
copy_path(...)
There are two copies: one for just regular files, and one which also
recognises directories as files. The regular copy does NOT copy
directories, but it does autocreate them for the target.
The copy_path function copies everything copy regular would AND
it copies directories too. So it will copy a whole directory across
if the dirname matches the patten, which means its children
get copied whether or not they match the pattern. Also the only
way to copy an empty directory.
So for example:
copy_regular(from="test",to="build/test",pattern="regress/rt/.*")
will copy all the regression tests to the build (default rename is \0).
You could also do it with:
copy_path(from="test",to="build/test",pattern="regress/rt")
Note this only matches a single file .. it just happens to be a directory
so the whole directory is copied: copy_regular refuses to match
directories.
The easy way to do this is search the "from" directory (recursively)
first to get a linear list, then filter it, and then map to a list of pairs,
then do the copy.
This is naive because it won't handle overlap: to fix that copy everything to a
temporary first, then mv the temporaries. The only issue is if the mv's collide,
it is indeterminate which file you'll get.
--
john skaller
[email protected]
------------------------------------------------------------------------------
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language