Search code examples
pythonscons

Scons Multi-Directory copying/zipping


Problem:

I have 2 source directories, one in the "current" dir and one in some other directory"

1: C:/somedir/dir_a/[win32, win64]/[tests, documentation, a, b]

And
2: D:/projects/project_a/api/[win32, win64]/[tests, a, b, c]

sconstruct @ D:/projects/project_a/sconstruct

Now I would like to have both directories in a zip file, with the root "win32". Directory 2 (D:/..) has it's win32 folder + content copied in the sconstruct already which means (afaik) that D:/projects/project_a/api/win32 (or win64) is already a target as far as scons is concerned.

What I tried:

When I then try to copy over directory 1 (c:/..) to directory 2, it simply won't because the target is already there. So that's the first attempt already.

Second attempt I used env.Zip to get the 2 directories in a Zip, this worked, however they are rooted completely wrong. The zip looked as follows:

zip..somedir/dir_a/win32/[tests, documentation, a, b]
   |.api/win32/[tests, a, b, c]

Where I would have wanted:

zip..win32/[tests, documentation, a, b, c]

Is there any way of doing this in Scons properly?


Solution

  • Found Solution:

    Hi All,

    found a proper solution for the root-less copytree problem I had.

    Using the Accumulator found @ http://www.scons.org/wiki/AccumulateBuilder

    Then just calling it as:

    target = "dir where you want to copy contents of source"
    basedir = "source dir containing content to be copied"
    env.Accumulate(target, [os.path.join(basedir ,x) for x in os.listdir(basedir)])
    

    Hope this helps someone else in the future with a similar problem :)