Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from dzuelke/tarball
Browse files Browse the repository at this point in the history
Fix tarball creation, for real :)
  • Loading branch information
kennethreitz committed Apr 8, 2014
2 parents c1a92d4 + 06b3e19 commit 1c2079d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
35 changes: 3 additions & 32 deletions bob/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,10 @@ def pipe(a, b, indent=True):

def archive_tree(dir, archive):
"""Creates a tar.gz archive from a given directory."""

abspath = os.path.abspath(dir)
base_root = None
is_top_level = False

with tarfile.open(archive, 'w:gz') as tar:

for root, _, files in os.walk(abspath):

# Mark the first pass as the top-level directory.
if is_top_level is None:
is_top_level = True

if not base_root:
base_root = root

transposed_base = root[len(base_root)+1:]

for file in files:

standard_path = os.path.join(root, file)

if is_top_level:
transposed_path = file
else:
transposed_path = os.path.join(transposed_base, file)

# Add the file to the archive, with the proper transposed path.
tar.add(standard_path, arcname=transposed_path)

# Close out the top-level directory marker.
is_top_level = False

# do not tar.add(dir) with empty arcname, that will create a "/" entry and tar will complain when extracting
for item in os.listdir(dir):
tar.add(dir+"/"+item, arcname=item)

def extract_tree(archive, dir):
"""Extract tar.gz archive to a given directory."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='bob-builder',
version='0.0.5',
version='0.0.6',
install_requires=deps,
description='Binary Build Toolkit.',
# long_description='Meh.',/
Expand Down

0 comments on commit 1c2079d

Please sign in to comment.