Difference between command-line tar and shutil.make_archive?
Question: When I generate a tar.gz file using `tar cfz cl.tar.gz Sources` as compared to
the python `shutil.make_archive ( "py", "gztar", "Sources" )`, I get different
results:

    
    
    $ tar -tf cl.tar.gz | head -3
    algorithm/
    aligned_storage.hpp
    algorithm/cxx11/
    
    
    $ tar -tf py.tar.gz | head -3
    ./algorithm/
    ./aligned_storage.hpp
    ./algorithm/cxx11/
    

Most of the time this makes no difference; but if you pass `--strip-
components` when un-tarring then the two archives behave differently.

I'd really like to get the same structure from the python code that I did from
the shell script, but I'm not quite sure how to do that. I'm using Python
2.7.3 on Mac OS 10.8.1, if that makes a difference.


Answer: The
[make_archive](http://docs.python.org/library/shutil.html#shutil.make_archive)
function takes two arguments, `root_dir` and `base_dir`. If you set base_dir
to something else, it gets rid of the `./` prefix. For example:

    
    
    $ tree
    .
    ├── blah
    │   ├── file1
    │   └── file2
    
    $ python
    >>> import shutil
    >>> shutil.make_archive("test", "gztar", ".", "blah")
    
    $ tar -tf test.tar.gz 
    blah/
    blah/file1
    blah/file2
    

This is limited to a single directory. If you want to add more than a single
directory or file like this, you will have to use the
[tarfile](http://docs.python.org/library/tarfile.html) module directly.

