def archive_as_tarball(source_dir, dest_dir, tarball_name=None, compression='bz2', verbose=True):
 tarball_name = get_archive_tarball_name(source_dir, tarball_name, compression)
 if (not os.path.isabs(tarball_name)):
  tarball_path = os.path.join(dest_dir, tarball_name)
 else:
  tarball_path = tarball_name
 if verbose:
  logging.debug(('Archiving %s as %s' % (source_dir, tarball_path)))
 os.chdir(os.path.dirname(source_dir))
 tarball = tarfile.TarFile(name=tarball_path, mode='w')
 tarball = tarball.open(name=tarball_path, mode=('w:%s' % compression))
 tarball.add(os.path.basename(source_dir))
 tarball.close()

def archive_as_tarball ( source_dir , dest_dir , tarball_name = None , compression = 'bz2' , verbose = True ) : tarball_name = get_archive_tarball_name ( source_dir , tarball_name , compression ) if ( not os . path . isabs ( tarball_name ) ) : tarball_path = os . path . join ( dest_dir , tarball_name ) else : tarball_path = tarball_name if verbose : logging . debug ( ( 'Archiving %s as %s' % ( source_dir , tarball_path ) ) ) os . chdir ( os . path . dirname ( source_dir ) ) tarball = tarfile . TarFile ( name = tarball_path , mode = 'w' ) tarball = tarball . open ( name = tarball_path , mode = ( 'w:%s' % compression ) ) tarball . add ( os . path . basename ( source_dir ) ) tarball . close ( )
saves the given source directory to the given destination as a tarball if the name of the archive is omitted .