2010-04-04 03:57:33 +04:00
# customised version of 'waf dist' for Samba tools
# uses git ls-files to get file lists
2010-04-04 04:06:34 +04:00
import Utils , os , sys , tarfile , stat , Scripting
2010-04-04 03:57:33 +04:00
from samba_utils import *
2010-04-04 05:00:42 +04:00
dist_dirs = None
2010-04-04 03:57:33 +04:00
def add_tarfile ( tar , fname , abspath ) :
''' add a file to the tarball '''
tinfo = tar . gettarinfo ( name = abspath , arcname = fname )
tinfo . uid = 0
tinfo . gid = 0
tinfo . uname = ' root '
tinfo . gname = ' root '
fh = open ( abspath )
tar . addfile ( tinfo , fileobj = fh )
fh . close ( )
2010-04-05 03:58:23 +04:00
def dist ( appname = ' ' , version = ' ' ) :
2010-04-08 00:52:28 +04:00
if not appname :
2010-04-05 03:58:23 +04:00
# this copes with a mismatch in the calling arguments for dist()
appname = Utils . g_module . APPNAME
version = Utils . g_module . VERSION
if not version :
version = Utils . g_module . VERSION
2010-04-04 03:57:33 +04:00
srcdir = os . path . normpath ( os . path . join ( os . path . dirname ( Utils . g_module . root_path ) , Utils . g_module . srcdir ) )
2010-04-04 05:00:42 +04:00
if not dist_dirs :
print ( ' You must use samba_dist.DIST_DIRS() to set which directories to package ' )
2010-04-04 03:57:33 +04:00
sys . exit ( 1 )
dist_base = ' %s - %s ' % ( appname , version )
dist_name = ' %s .tar.gz ' % ( dist_base )
tar = tarfile . open ( dist_name , ' w:gz ' )
2010-04-04 05:00:42 +04:00
for dir in dist_dirs . split ( ) :
2010-04-04 03:57:33 +04:00
if dir . find ( ' : ' ) != - 1 :
destdir = dir . split ( ' : ' ) [ 1 ]
dir = dir . split ( ' : ' ) [ 0 ]
else :
destdir = ' . '
absdir = os . path . join ( srcdir , dir )
2010-04-04 05:00:42 +04:00
git_cmd = [ ' git ' , ' ls-files ' , ' --full-name ' , absdir ]
2010-04-04 04:23:43 +04:00
try :
files = Utils . cmd_output ( git_cmd ) . split ( )
except :
print ( ' git command failed: %s ' % ' ' . join ( git_cmd ) )
sys . exit ( 1 )
2010-04-04 03:57:33 +04:00
for f in files :
abspath = os . path . join ( srcdir , f )
if dir != ' . ' :
f = f [ len ( dir ) + 1 : ]
if destdir != ' . ' :
f = destdir + ' / ' + f
fname = dist_base + ' / ' + f
add_tarfile ( tar , fname , abspath )
tar . close ( )
print ( ' Created %s ' % dist_name )
2010-04-05 03:58:23 +04:00
return dist_name
2010-04-04 03:57:33 +04:00
@conf
2010-04-04 05:00:42 +04:00
def DIST_DIRS ( dirs ) :
2010-04-04 03:57:33 +04:00
''' set the directories to package, relative to top srcdir '''
2010-04-04 05:00:42 +04:00
global dist_dirs
if not dist_dirs :
dist_dirs = dirs
2010-04-04 04:06:34 +04:00
Scripting . dist = dist