Changeset 19207

Show
Ignore:
Timestamp:
08/14/06 16:38:16 (2 years ago)
Author:
patrick
Message:

MFT [rev 19086]:

  • Added a smartCopy() method that is more intelligent about copying
    files. The primary additions to this method are:
    • Only copy the file if it has actually changed
    • Delete the dest file if it exists and a copy is going to happen
  • This fixes some problems with read-only files and makes the
    installation process go much faster.

Much to my relief, this non-trivial merge applied cleanly with no
additional modifications required. :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.0/buildwin32.py

    r19042 r19207  
    3434 
    3535import glob 
    36 import os 
     36import os, os.path 
    3737import re 
    3838import shutil 
     
    4141import traceback 
    4242import getopt 
     43pj = os.path.join 
    4344 
    4445EXIT_STATUS_SUCCESS           = 0 
     
    765766   mkinstalldirs(os.path.join(prefix, 'share')) 
    766767 
     768def smartCopy(srcfile, dst): 
     769   """ Only copy file if it has changed, and delete it first. 
     770       Drop in replacement for shutil.copy2. 
     771       srcfile - Full path to source file to copy. 
     772       dst - Destination filename or directory. 
     773   """    
     774   if os.path.isdir(dst): 
     775      dst = os.path.join(dst, os.path.basename(srcfile)) 
     776         
     777   # Verify we need to copy and make sure to delete if needed 
     778   if os.path.isfile(dst): 
     779      stat_src = os.stat(srcfile) 
     780      stat_dst = os.stat(dst) 
     781      if (stat_src.st_size == stat_dst.st_size) and \ 
     782         (stat_src.st_mtime == stat_dst.st_mtime): 
     783         #print "skipping: ", dst 
     784         return   # File doesn't need to be copied 
     785      #print "removing: ", dst 
     786      os.remove(dst) 
     787    
     788   # Copy it 
     789   shutil.copy2(srcfile, dst) 
     790    
     791    
    767792def installDir(startDir, destDir, allowedExts = None, disallowedExts = None, 
    768793               disallowedFiles = None): 
     794   #print "   %s ==> %s"%(startDir, destDir) 
    769795   cwd = os.getcwd() 
    770796 
     
    802828                    disallowedFiles) 
    803829      else: 
    804          (root, f_ext) = os.path.splitext(f) 
    805          if allowedExts is None: 
    806             if f_ext not in disallowedExts: 
    807                shutil.copy2(f, destDir) 
    808          elif f_ext in allowedExts: 
    809             if f not in disallowedFiles: 
    810                shutil.copy2(f, destDir) 
     830         try: 
     831            (root, f_ext) = os.path.splitext(f) 
     832            if allowedExts is None: 
     833               if f_ext not in disallowedExts: 
     834                  smartCopy(f, pj(destDir,f)) 
     835            elif f_ext in allowedExts: 
     836               if f not in disallowedFiles: 
     837                  smartCopy(f, pj(destDir,f)) 
     838         except (IOError, os.error), why: 
     839            print "Can't copy %s to %s: %s" % (f, destDir, str(why)) 
    811840 
    812841   os.chdir(cwd) 
     
    851880   srcroot = os.path.join(gJugglerDir, 'modules', 'vapor') 
    852881 
    853    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     882   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    854883   extra_files = ['ChangeLog', 'README.txt', 'RELEASE_NOTES.txt'] 
    855884   for f in extra_files: 
    856       shutil.copy2(os.path.join(srcroot, f), destdir) 
     885      smartCopy(os.path.join(srcroot, f), destdir) 
    857886 
    858887def installTweek(prefix, buildDir): 
     
    882911   srcroot = os.path.join(gJugglerDir, 'modules', 'tweek') 
    883912 
    884    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     913   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    885914   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    886915   for f in extra_files: 
    887       shutil.copy2(os.path.join(srcroot, f), destdir) 
     916      smartCopy(os.path.join(srcroot, f), destdir) 
    888917 
    889918def installTweekJava(prefix, buildDir): 
     
    919948      # Install the base JAR files that make up the Tweek Java API. 
    920949      for j in jars: 
    921          shutil.copy2(os.path.join(srcdir, j), destdir) 
     950         smartCopy(os.path.join(srcdir, j), destdir) 
    922951 
    923952      # Install the tweek_jni DLL. 
     
    929958            destdir = os.path.join(destdir, arch) 
    930959            mkinstalldirs(destdir) 
    931             shutil.copy2(dll, destdir) 
     960            smartCopy(dll, destdir) 
    932961 
    933962      destdir = os.path.join(prefix, 'share', 'tweek', 'beans') 
     
    941970         jar = b + '.jar' 
    942971         xml = b + '.xml' 
    943          shutil.copy2(os.path.join(bean_srcdir, jar), destdir) 
    944          shutil.copy2(os.path.join(xml_srcdir, xml), destdir) 
     972         smartCopy(os.path.join(bean_srcdir, jar), destdir) 
     973         smartCopy(os.path.join(xml_srcdir, xml), destdir) 
    945974 
    946975      xml_srcdir  = os.path.join(gJugglerDir, 'modules', 'tweek', 'extensions', 
     
    951980         jar = b + '.jar' 
    952981         xml = b + '.xml' 
    953          shutil.copy2(os.path.join(bean_srcdir, jar), destdir) 
    954          shutil.copy2(os.path.join(xml_srcdir, xml), destdir) 
     982         smartCopy(os.path.join(bean_srcdir, jar), destdir) 
     983         smartCopy(os.path.join(xml_srcdir, xml), destdir) 
    955984 
    956985      # Install tweek.bat. 
    957986      srcdir = os.path.join(gJugglerDir, 'modules', 'tweek', 'java') 
    958987      destdir = os.path.join(prefix, 'bin') 
    959       shutil.copy2(os.path.join(srcdir, 'tweek.bat'), destdir) 
     988      smartCopy(os.path.join(srcdir, 'tweek.bat'), destdir) 
    960989 
    961990      # Install JacORB IDL compiler. 
    962991      srcdir = os.path.join(gJugglerDir, 'external', 'JacORB') 
    963992      installDir(srcdir, destdir, ['.jar']) 
    964       shutil.copy2(os.path.join(srcdir, 'idl.bat'), destdir) 
     993      smartCopy(os.path.join(srcdir, 'idl.bat'), destdir) 
    965994 
    966995      # Destination for all remaining .jar files. 
     
    9821011      srcroot = os.path.join(gJugglerDir, 'external', 'swing-laf') 
    9831012      for j in laf_jars: 
    984          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1013         smartCopy(os.path.join(srcroot, j), destdir) 
    9851014   else: 
    9861015      printStatus("Tweek Java API not built.  Skipping.") 
     
    10201049                          '3.0') 
    10211050   mkinstalldirs(destdir) 
    1022    shutil.copy2(os.path.join(srcdir, 'configuration.xsd'), destdir) 
     1051   smartCopy(os.path.join(srcdir, 'configuration.xsd'), destdir) 
    10231052 
    10241053   destdir = os.path.join(schema_root, 'www.vrjuggler.org', 'jccl', 'xsd', 
    10251054                          '3.1') 
    10261055   mkinstalldirs(destdir) 
    1027    shutil.copy2(os.path.join(srcdir, 'definition.xsd'), destdir) 
     1056   smartCopy(os.path.join(srcdir, 'definition.xsd'), destdir) 
    10281057 
    10291058   destdir = schema_root 
     
    10361065   srcroot = os.path.join(gJugglerDir, 'modules', 'jackal') 
    10371066 
    1038    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1067   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    10391068   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    10401069   for f in extra_files: 
    1041       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1070      smartCopy(os.path.join(srcroot, f), destdir) 
    10421071 
    10431072def installJCCLPlugins(prefix, buildDir): 
     
    10631092 
    10641093      for j in jars: 
    1065          shutil.copy2(os.path.join(srcdir, j), destdir) 
     1094         smartCopy(os.path.join(srcdir, j), destdir) 
    10661095 
    10671096      srcdir = os.path.join(gJugglerDir, 'modules', 'jackal', 'config') 
    1068       shutil.copy2(os.path.join(srcdir, 'jccl_config.xml'), destdir) 
     1097      smartCopy(os.path.join(srcdir, 'jccl_config.xml'), destdir) 
    10691098 
    10701099      # Install dependencies. 
     
    10781107      mkinstalldirs(destdir) 
    10791108      for j in dep_jars: 
    1080          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1109         smartCopy(os.path.join(srcroot, j), destdir) 
    10811110   else: 
    10821111      printStatus("JCCL Java API not built.  Skipping.") 
     
    10891118 
    10901119      destdir = os.path.join(prefix, 'share', 'jccl', 'beans') 
    1091       shutil.copy2(os.path.join(srcdir, 'jccl_rtrc.jar'), destdir) 
     1120      smartCopy(os.path.join(srcdir, 'jccl_rtrc.jar'), destdir) 
    10921121 
    10931122      srcdir = os.path.join(gJugglerDir, 'modules', 'jackal', 'plugins', 
    10941123                            'corba_rtrc') 
    1095       shutil.copy2(os.path.join(srcdir, 'jccl_rtrc.xml'), destdir) 
     1124      smartCopy(os.path.join(srcdir, 'jccl_rtrc.xml'), destdir) 
    10961125   else: 
    10971126      printStatus("JCCL Java plug-ins not built.  Skipping.") 
     
    11231152   srcroot = os.path.join(gJugglerDir, 'modules', 'sonix') 
    11241153 
    1125    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1154   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    11261155   extra_files = ['ChangeLog', 'README.txt'] 
    11271156   for f in extra_files: 
    1128       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1157      smartCopy(os.path.join(srcroot, f), destdir) 
    11291158 
    11301159def installSonixPlugins(prefix, buildDir): 
     
    11841213   srcroot = os.path.join(gJugglerDir, 'modules', 'gadgeteer') 
    11851214 
    1186    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1215   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    11871216   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    11881217   for f in extra_files: 
    1189       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1218      smartCopy(os.path.join(srcroot, f), destdir) 
    11901219 
    11911220def installGadgeteerDrivers(prefix, buildDir): 
     
    12671296   srcroot = os.path.join(gJugglerDir, 'modules', 'vrjuggler') 
    12681297 
    1269    shutil.copy2(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
     1298   smartCopy(os.path.join(gJugglerDir, 'COPYING.txt'), destdir) 
    12701299   extra_files = ['ChangeLog', 'RELEASE_NOTES.txt'] 
    12711300   for f in extra_files: 
    1272       shutil.copy2(os.path.join(srcroot, f), destdir) 
     1301      smartCopy(os.path.join(srcroot, f), destdir) 
    12731302 
    12741303def installVRJConfig(prefix, buildDir): 
     
    13111340         jar_file = os.path.join(jardir, j) 
    13121341         if os.path.exists(jar_file): 
    1313             shutil.copy2(jar_file, destdir) 
     1342            smartCopy(jar_file, destdir) 
    13141343 
    13151344      # Install the base set of VRJConfig JavaBeans. 
     
    13191348         jar_file = os.path.join(jardir, j) 
    13201349         if os.path.exists(jar_file): 
    1321             shutil.copy2(jar_file, destdir) 
    1322  
    1323       shutil.copy2(os.path.join(vrjconfig_src, 'VRJConfig.xml'), destdir) 
     1350            smartCopy(jar_file, destdir) 
     1351 
     1352      smartCopy(os.path.join(vrjconfig_src, 'VRJConfig.xml'), destdir) 
    13241353 
    13251354      # Install any custom editors that were compiled. 
     
    13311360         xml_file = os.path.join(custom_editor_src, e[0], e[1] + '.xml') 
    13321361         if os.path.exists(jar_file): 
    1333             shutil.copy2(xml_file, destdir) 
    1334             shutil.copy2(jar_file, destdir) 
     1362            smartCopy(xml_file, destdir) 
     1363            smartCopy(jar_file, destdir) 
    13351364 
    13361365      # Install any wizards that were compiled. 
     
    13401369         jar_file = os.path.join(jardir, e[1] + '.jar') 
    13411370         if os.path.exists(jar_file): 
    1342             shutil.copy2(jar_file, destdir) 
     1371            smartCopy(jar_file, destdir) 
    13431372 
    13441373      # Install vrjconfig.bat. 
    13451374      destdir = os.path.join(prefix, 'bin') 
    1346       shutil.copy2(os.path.join(vrjconfig_src, 'vrjconfig.bat'), destdir) 
     1375      smartCopy(os.path.join(vrjconfig_src, 'vrjconfig.bat'), destdir) 
    13471376 
    13481377      # Install dependencies. 
     
    13551384      destdir = os.path.join(prefix, 'share', 'vrjuggler', 'java') 
    13561385      for j in dep_jars: 
    1357          shutil.copy2(os.path.join(srcroot, j), destdir) 
     1386         smartCopy(os.path.join(srcroot, j), destdir) 
    13581387   else: 
    13591388      printStatus("VRJConfig not built.  Skipping.") 
     
    13791408         destdir = os.path.join(prefix, 'share', 'vrjuggler', 'beans') 
    13801409         mkinstalldirs(destdir) 
    1381          shutil.copy2(os.path.join(srcdir, name + '.jar'), destdir) 
     1410         smartCopy(os.path.join(srcdir, name + '.jar'), destdir) 
    13821411 
    13831412         srcdir = os.path.join(gJugglerDir, 'modules', 'vrjuggler', 'plugins', 
    13841413                               dir) 
    1385          shutil.copy2(os.path.join(srcdir, name + '.xml'), destdir) 
     1414         smartCopy(os.path.join(srcdir, name + '.xml'), destdir) 
    13861415      else: 
    13871416         printStatus("VR Juggler %s Java plug-ins not built.  Skipping." % name) 
     
    14051434 
    14061435      for d in dlls: 
    1407          shutil.copy2(d, destdir) 
    1408  
    1409       shutil.copy2(os.path.join(sys_dir, 'dbghelp.dll'), destdir) 
     1436         smartCopy(d, pj(destdir,d))          
     1437 
     1438      #smartCopy(d, pj(destdir,d)) 
     1439      smartCopy(os.path.join(sys_dir, 'dbghelp.dll'), destdir) 
    14101440   except KeyError, ex: 
    14111441      printStatus("WARNING: Could not install MSVC runtime DLLs") 
     
    14591489def installBoost(prefix): 
    14601490   printStatus("Installing Boost headers and libraries") 
     1491   print "Installing Boost headers and libraries" 
    14611492 
    14621493   srcroot = os.environ['BOOST_ROOT'] 
     
    14731504 
    14741505   for f in lib_list: 
    1475       shutil.copy2(f, destdir) 
     1506      #print "  ==> ", f 
     1507      smartCopy(f, destdir) 
    14761508 
    14771509def installGMTL(prefix): 
     
    14961528         dll = os.path.join(d, 'OpenAL32.dll') 
    14971529         if os.path.exists(dll): 
    1498             shutil.copy2(dll, destdir) 
     1530            smartCopy(dll, destdir) 
    14991531 
    15001532   srcdir = os.environ['ALUT_ROOT'] 
     
    15051537      alut_dll = os.path.join(srcdir, 'lib', 'alut.dll') 
    15061538      if os.path.exists(alut_dll): 
    1507          shutil.copy2(dll, destdir) 
     1539         smartCopy(dll, destdir) 
    15081540 
    15091541def installOmniORB(prefix):