changeset 13:f522620c6a78

now works properly with tarballs
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 15:20:01 -0700
parents 542b46ac4e28
children c474362cf69a
files carton.py tests/doctest.txt tests/packageA/setup.py tests/packageC.tar.gz
diffstat 4 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/carton.py	Fri Jul 08 15:04:15 2011 -0700
+++ b/carton.py	Fri Jul 08 15:20:01 2011 -0700
@@ -143,13 +143,18 @@
             # remote tarball
             raise NotImplementedError
         else:
+            assert os.path.exists(source), "%s does not exist" % source
+            
             # local directory or tarball
-            # TODO: check for a tarball
-            source_buffer = StringIO()
-            source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
-            source_tar.add(source, arcname=os.path.basename(source))
-            source_tar.close()
-            buffer = source_buffer.getvalue()
+            if (not os.path.isdir(source)) and tarfile.is_tarfile(source):
+                # check for a tarball
+                buffer = file(source).read()
+            else:
+                source_buffer = StringIO()
+                source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
+                source_tar.add(source, arcname=os.path.basename(source))
+                source_tar.close()
+                buffer = source_buffer.getvalue()
 
         # could use git, hg, etc repos. but probably shouldn't
         
--- a/tests/doctest.txt	Fri Jul 08 15:04:15 2011 -0700
+++ b/tests/doctest.txt	Fri Jul 08 15:20:01 2011 -0700
@@ -14,7 +14,7 @@
 Invoke carton::
 
     >>> os.chdir(directory)
-    >>> packages = [os.path.join(here, i) for i in 'packageB', 'packageA']
+    >>> packages = [os.path.join(here, i) for i in 'packageC.tar.gz', 'packageB', 'packageA']
     >>> carton.main(['foo'] + packages)
     >>> os.listdir('.')
     ['foo.py']
@@ -29,7 +29,7 @@
     >>> os.path.isdir('foo')
     True
     >>> sorted(os.listdir(os.path.join('foo', 'src')))
-    ['packageA', 'packageB']
+    ['packageA', 'packageB', 'packageC']
 
 Clean up::
 
--- a/tests/packageA/setup.py	Fri Jul 08 15:04:15 2011 -0700
+++ b/tests/packageA/setup.py	Fri Jul 08 15:20:01 2011 -0700
@@ -9,7 +9,7 @@
 
 version = '0.0'
 
-deps = ['packageB']
+deps = ['packageB', 'packageC']
 
 setup(name='packageA',
       version=version,
Binary file tests/packageC.tar.gz has changed