wscript
changeset 2622 6440851b111a
parent 2345 79f77914c31c
child 2846 7689461231ac
equal deleted inserted replaced
2621:b0e140bbeeee 2622:6440851b111a
   456         if subprocess.Popen(genhtml_command, shell=True).wait():
   456         if subprocess.Popen(genhtml_command, shell=True).wait():
   457             raise SystemExit(1)
   457             raise SystemExit(1)
   458     finally:
   458     finally:
   459         os.chdir("..")
   459         os.chdir("..")
   460 
   460 
       
   461 
       
   462 
       
   463 
       
   464 ##
       
   465 ## The default WAF DistDir implementation is rather slow, because it
       
   466 ## first copies everything and only later removes unwanted files and
       
   467 ## directories; this means that it needless copies the full build dir
       
   468 ## and the .hg repository tree.  Here we provide a replacement DistDir
       
   469 ## implementation that is more efficient.
       
   470 ##
       
   471 import Scripting
       
   472 from Scripting import g_dist_exts, g_excludes, BLDDIR
       
   473 import Utils
       
   474 import os
       
   475 
       
   476 def copytree(src, dst, symlinks=False, excludes=(), build_dir=None):
       
   477     """Recursively copy a directory tree using copy2().
       
   478 
       
   479     The destination directory must not already exist.
       
   480     If exception(s) occur, an Error is raised with a list of reasons.
       
   481 
       
   482     If the optional symlinks flag is true, symbolic links in the
       
   483     source tree result in symbolic links in the destination tree; if
       
   484     it is false, the contents of the files pointed to by symbolic
       
   485     links are copied.
       
   486 
       
   487     XXX Consider this example code rather than the ultimate tool.
       
   488 
       
   489     Note: this is a modified version of shutil.copytree from python
       
   490     2.5.2 library; modified for WAF purposes to exclude dot dirs and
       
   491     another list of files.
       
   492     """
       
   493     names = os.listdir(src)
       
   494     os.makedirs(dst)
       
   495     errors = []
       
   496     for name in names:
       
   497         srcname = os.path.join(src, name)
       
   498         dstname = os.path.join(dst, name)
       
   499         try:
       
   500             if symlinks and os.path.islink(srcname):
       
   501                 linkto = os.readlink(srcname)
       
   502                 os.symlink(linkto, dstname)
       
   503             elif os.path.isdir(srcname):
       
   504                 if name in excludes:
       
   505                     continue
       
   506                 elif name.startswith('.') or name.startswith(',,') or name.startswith('++'):
       
   507                     continue
       
   508                 elif name == build_dir:
       
   509                     continue
       
   510                 else:
       
   511                     ## build_dir is not passed into the recursive
       
   512                     ## copytree, but that is intentional; it is a
       
   513                     ## directory name valid only at the top level.
       
   514                     copytree(srcname, dstname, symlinks, excludes)
       
   515             else:
       
   516                 ends = name.endswith
       
   517                 to_remove = False
       
   518                 if name.startswith('.') or name.startswith('++'):
       
   519                     to_remove = True
       
   520                 else:
       
   521                     for x in g_dist_exts:
       
   522                         if ends(x):
       
   523                             to_remove = True
       
   524                             break
       
   525                 if not to_remove:
       
   526                     shutil.copy2(srcname, dstname)
       
   527             # XXX What about devices, sockets etc.?
       
   528         except (IOError, os.error), why:
       
   529             errors.append((srcname, dstname, str(why)))
       
   530         # catch the Error from the recursive copytree so that we can
       
   531         # continue with other files
       
   532         except shutil.Error, err:
       
   533             errors.extend(err.args[0])
       
   534     try:
       
   535         shutil.copystat(src, dst)
       
   536     except WindowsError:
       
   537         # can't copy file access times on Windows
       
   538         pass
       
   539     except OSError, why:
       
   540         errors.extend((src, dst, str(why)))
       
   541     if errors:
       
   542         raise shutil.Error, errors
       
   543 
       
   544 
       
   545 def DistDir(appname, version):
       
   546     "make a distribution directory with all the sources in it"
       
   547     import shutil
       
   548 
       
   549     # Our temporary folder where to put our files
       
   550     TMPFOLDER=appname+'-'+version
       
   551 
       
   552     # Remove an old package directory
       
   553     if os.path.exists(TMPFOLDER): shutil.rmtree(TMPFOLDER)
       
   554 
       
   555     global g_dist_exts, g_excludes
       
   556 
       
   557     # Remove the Build dir
       
   558     build_dir = getattr(Utils.g_module, BLDDIR, None)
       
   559 
       
   560     # Copy everything into the new folder
       
   561     copytree('.', TMPFOLDER, excludes=g_excludes, build_dir=build_dir)
       
   562 
       
   563     # TODO undocumented hook
       
   564     dist_hook = getattr(Utils.g_module, 'dist_hook', None)
       
   565     if dist_hook:
       
   566         os.chdir(TMPFOLDER)
       
   567         try:
       
   568             dist_hook()
       
   569         finally:
       
   570             # go back to the root directory
       
   571             os.chdir('..')
       
   572     return TMPFOLDER
       
   573 
       
   574 Scripting.DistDir = DistDir