def vcfIndex(vcf, tabix='tabix'): # /path/to/some.vcf -> some.vcf # /path/to/some.vcf.gz -> some.vcf bname = path.basename( vcf[:-3]) if vcf.endswith('.gz') else path.basename(vcf) # /path/to/some.bam -> /path/to/ dname = path.dirname(vcf) # some.vcf -> some # some.vcf.gz -> some fname = path.splitext(bname)[0] # some -> some # [1]some -> some rname = fname.split(']', 1)[1] if fname.startswith('[') else fname expectedIndex = path.join(dname, rname + '.vcf.gz.tbi') if path.isfile(expectedIndex): return vcf # if vcf is not a link, there is nowhere else to find index, create it using tabix tabix = shell.Shell({'tabix': tabix}).tabix gt = gztype(vcf) if gt == 'bgzip': if path.islink(vcf): linkvcf = path.readlink(vcf) if path.isfile(linkvcf + '.tbi'): shell.ln_s(linkvcf + '.tbi', expectedIndex) return vcf realvcf = path.realpath(vcf) if path.isfile(realvcf + '.tbi'): shell.ln_s(realvcf + '.tbi', expectedIndex) return vcf tabix(p='vcf', _=vcf).run() return vcf if gt == 'gzip': tmpvcf = path.join(dname, bname + '.tmp.vcf') shell.gunzip_to(vcf, tmpvcf) shell.bgzip(tmpvcf) tabix(p='vcf', _=tmpvcf + '.gz').run() shell.mv(tmpvcf + '.gz.tbi', expectedIndex) return vcf shell.bgzip(vcf, c=True, _stdout=vcf + '.gz') tabix(p='vcf', _=vcf + '.gz').run() return vcf + '.gz'
def doCopyDir(self, result): if result is not None: if result[1]: self.session.openWithCallback(self.callback, MessageBox, _('Copying ...'), type = 1, timeout = 1) symlinks = False aaa = self.SOURCELIST.getCurrentDirectory() src = self.SOURCELIST.getFilename() bbb = src[len(aaa):] dst = self.TARGETLIST.getCurrentDirectory() + bbb names = os.listdir(src) try: os.makedirs(dst) except: pass errors = [] for name in names: srcname = os.path.join(src, name) dstname = os.path.join(dst, name) try: if symlinks and os.path.islink(srcname): linkto = os.readlink(srcname) os.symlink(linkto, dstname) elif os.path.isdir(srcname): shutil.copytree(srcname, dstname, symlinks) else: shutil.copy2(srcname, dstname) continue except (IOError, os.error): why = None errors.append((srcname, dstname, str(why))) continue try: copystat(src, dst) except: pass self.doRefresh()
def prep_build(self, ext): if not CMakeBuild.hasbuilt: from distutils.sysconfig import get_python_inc import distutils.sysconfig as sysconfig cfg = self.cfg_type() extdir = os.path.abspath( os.path.dirname(self.get_ext_fullpath(ext.name))) lcb_api_flags = self.get_lcb_api_flags() cmake_args = lcb_api_flags + [ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DPYTHON_EXECUTABLE=' + sys.executable ] cmake_args += ['-DPYTHON_INCLUDE_DIR={}'.format(get_python_inc())] self.info.setbase(self.build_temp) self.info.cfg = cfg from distutils import sysconfig import os.path as op v = sysconfig.get_config_vars() print("LIBDIR {}, LIBPL {}".format(v.get("LIBDIR"), v.get("LIBPL"))) fpaths = [ op.join(v.get(pv, ''), v.get('LDLIBRARY', '')) for pv in ('LIBDIR', 'LIBPL') ] + [ os.path.normpath( os.path.join( get_python_inc(), "..", "..", "lib", "libpython{}.dylib".format('.'.join( map(str, sys.version_info[0:2]))))), os.path.join(get_python_inc(), "..", "..", "lib") ] python_lib = None python_libdir = None for entry in fpaths: if not op.exists(entry): print("fpath {} does not exist".format(entry)) continue try: print("got fpath {}:".format(entry)) if op.isfile(entry): print("fpath {} is file, selecting".format(entry)) python_lib = python_lib or entry continue else: entries = os.listdir(entry) print("fpath {} is directory, contents {}".format( entry, entries)) for subentry in entries: fullname = op.normpath(op.join(entry, subentry)) try: fullname = op.readlink(fullname) except: pass print("trying subentry:{}".format(fullname)) if op.exists(fullname): python_lib = python_lib or fullname python_libdir = op.normpath(entry) print("got match {}, breaking out".format( fullname)) continue except: pass cmake_args += ['-DHYBRID_BUILD=TRUE'] if CMakeBuild.hybrid else [] cmake_args += ['-DPYTHON_LIBFILE={}'.format(python_lib) ] if python_lib else [] cmake_args += ['-DPYTHON_LIBDIR={}'.format(python_libdir) ] if python_libdir else [] cmake_args += [ '-DPYTHON_VERSION_EXACT={}'.format('.'.join( map(str, sys.version_info[0:2]))) ] if python_libdir else [] build_args = ['--config', cfg] if platform.system() == "Windows": cmake_args += [ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( cfg.upper(), extdir), '-DLCB_NO_MOCK=1', '-DCMAKE_BUILD_PARALLEL_LEVEL=1' ] if sys.maxsize > 2**32: cmake_args += ['-A', 'x64'] build_args += ['--', '/m'] else: cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg.upper()] build_args += ['--', '-j2'] env = os.environ.copy() python_executable = win_cmake_path(sys.executable) pass_path = False if re.match(r'.*(CONAN|ALL).*', PYCBC_SSL_FETCH): try: import conans.conan env['PATH'] = env['PATH'] + ";{}".format( os.path.dirname(conans.conan.__file__)) pass_path = True except: logging.warning("Cannot find conan : {}".format( traceback.format_exc())) if re.match(r'.*(GITHUB|ALL).*', PYCBC_SSL_FETCH): pass_path = True if pass_path: pathsep = ';' if platform.system().lower().startswith( 'win') else ':' env['PYTHONPATH'] = pathsep.join(sys.path) cmake_args += [ '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON', '-DPYTHON_EXECUTABLE={}'.format(python_executable) ] if PYCBC_SSL_FETCH: cmake_args += ['-DPYCBC_SSL_FETCH={}'.format(PYCBC_SSL_FETCH)] PYCBC_CMAKE_DEBUG = env.get('PYCBC_CMAKE_DEBUG') if PYCBC_CMAKE_DEBUG: cmake_args += [ '--trace-source=CMakeLists.txt', '--trace-expand' ] cxx_compile_args = filter( re.compile(r'^(?!-std\s*=\s*c(11|99)).*').match, ext.extra_compile_args) env['CXXFLAGS'] = '{} {} -DVERSION_INFO=\\"{}\\"'.format( env.get('CXXFLAGS', ''), ' '.join(cxx_compile_args), self.distribution.get_version()) env['CFLAGS'] = '{} {}'.format(env.get('CFLAGS', ''), ' '.join(ext.extra_compile_args), self.distribution.get_version()) print( "Launching build with env: {}, build_args: {}, cmake_args: {}". format(env, build_args, cmake_args)) if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, stdout=sys.stdout, stderr=sys.stdout, cwd=self.build_temp, env=env) subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) CMakeBuild.hasbuilt = True build_dir = os.path.realpath(self.build_lib) if CMakeBuild.hybrid: if not self.compiler: self.run() for name in self.info.entries(): try: pkg_build_dir = os.path.join(build_dir, cbuild_config.couchbase_core) self.copy_binary_to(cfg, pkg_build_dir, self.info.lcb_pkgs_srcs(), name) self.copy_binary_to(cfg, self.info.pkg_data_dir, self.info.lcb_pkgs_srcs(), name) except: print("failure") raise