- samtools_src = os.path.abspath( sys.argv[2] )
- if not os.path.exists( samtools_src ): raise IOError( "samtools src dir `%s` does not exist." % samtools_src )
-
- cfiles = glob.glob( os.path.join( samtools_src, "*.c" ) )
- hfiles = glob.glob( os.path.join( samtools_src, "*.h" ) )
- ncopied = 0
- for p in cfiles + hfiles:
- f = os.path.basename(p)
- if f in samtools_exclude: continue
- if os.path.exists( os.path.join( samtools_dest, f )): continue
- shutil.copy( p, samtools_dest )
- ncopied += 1
- print "installed latest source code from %s: %i files copied" % (samtools_src, ncopied)
+ if len(sys.argv) < 4: raise ValueError("missing PATH to tabix source directory")
+
+ for destdir, srcdir, exclude in zip(
+ (samtools_dest, tabix_dest),
+ sys.argv[2:4],
+ (samtools_exclude, tabix_exclude)):
+
+ srcdir = os.path.abspath( srcdir )
+ if not os.path.exists( srcdir ): raise IOError( "samtools src dir `%s` does not exist." % srcdir )
+
+ cfiles = locate( "*.c", srcdir )
+ hfiles = locate( "*.h", srcdir )
+ ncopied = 0
+
+ def _compareAndCopy( src, srcdir, destdir, exclude ):
+
+ d, f = os.path.split(src)
+ if f in exclude: return None
+ common_prefix = os.path.commonprefix( (d, srcdir ) )
+ subdir = re.sub( common_prefix, "", d )[1:]
+ targetdir = os.path.join( destdir, subdir )
+ if not os.path.exists( targetdir ):
+ os.makedirs( targetdir )
+ old_file = os.path.join( targetdir, f )
+ if os.path.exists( old_file ):
+ md5_old = hashlib.md5("".join(open(old_file,"r").readlines())).digest()
+ md5_new = hashlib.md5("".join(open(src,"r").readlines())).digest()
+ if md5_old != md5_new:
+ raise ValueError( "incompatible files for %s and %s" % (old_file, src ))
+
+ shutil.copy( src, targetdir )
+ return old_file
+
+ for src_file in hfiles:
+ _compareAndCopy( src_file, srcdir,destdir, exclude )
+ ncopied += 1
+
+ cf = []
+ for src_file in cfiles:
+ cf.append( _compareAndCopy( src_file, srcdir, destdir, exclude ) )
+ ncopied += 1
+
+ sys.stdout.write("installed latest source code from %s: %i files copied" % (srcdir, ncopied))
+ # redirect stderr to pysamerr and replace bam.h with a stub.
+ sys.stdout.write("applying stderr redirection")
+
+ _update_pysam_files(cf, destdir)
+
+