def check_git(): try: version = _subprocess.check_output(['git', '--version']) except OSError: print('Dependency error: git not found.') print('Please install git version 2.4 or more recent to continue') version = version.rstrip().split(' ')[-1].split('.') version_A, version_B, version_C = map(int, version) if not (version_A >= 2 and version_B >= 4): print('Dependency warning: git version < 2.4') print('''Proceeding but if git-related issues encountered, try updating git to version 2.4 or more recent''') else: print('git %s found: ok' % '.'.join(version))
def check_git(): try: version = _subprocess.check_output(['git','--version']) except OSError: print('Dependency error: git not found.') print('Please install git version 2.4 or more recent to continue') version = version.rstrip().split(' ')[-1].split('.') version_A, version_B, version_C = map(int, version) if not (version_A >= 2 and version_B >= 4): print('Dependency warning: git version < 2.4') print('''Proceeding but if git-related issues encountered, try updating git to version 2.4 or more recent''') else: print('git %s found: ok' % '.'.join(version))
def check_no_error(path='', system=False, java_commands=False, extra=False, extra_pre=False, success_returncode=1): ''' check a binary executable can be called. A failure is considered as OSError, not a non-zero exit status. Can check in default baga location or a specified path or the system path or java. Additional commands and be appended with 'extra' list or pre-pended with 'extra-pre' list e.g., specifying 'python2' for when python3 defaults but python >3.3 is installed but not supported. ''' if java_commands: p = _subprocess.Popen(['java'] + java_commands, stdout=_subprocess.PIPE, stderr=_subprocess.STDOUT) output = p.stdout.read() if 'Error:' in output: print(output) return (False) else: print(output) return (True) else: if system: cmd = path[-1:] elif path[0][0] == _os.path.sep or path[0] == '': # absolute path to elsewhere provided cmd = [_os.path.sep.join(path)] else: cmd = [_os.path.sep.join(['external_programs'] + path)] if extra: cmd += extra if extra_pre: cmd = extra_pre + cmd try: o = _subprocess.check_output(cmd) o = '\n'.join(['external> ' + l for l in o.split('\n')]) + '\n' print(o) # eventually put in the debugging log <== too much noise # some programs output a help screen if commands not given # . . . they are installed and available return (True) except _subprocess.CalledProcessError as e: if e.returncode == success_returncode: # some programs that exit return non-zero code if commands not given # usually this is 1, but occasionally it is 2 (e.g. cutadapt) # but a fail on 2 is e.g. python calling a non-existent python program # should be set in the dependencies dictionary if not 1 (default) # . . . but they are installed and available return (True) else: return (False) except OSError as e: print('{}: {}'.format(cmd[0], e)) return (False)
def check_no_error(path = '', system = False, java_commands = False, extra = False, extra_pre = False, success_returncode = 1): ''' check a binary executable can be called. A failure is considered as OSError, not a non-zero exit status. Can check in default baga location or a specified path or the system path or java. Additional commands and be appended with 'extra' list or pre-pended with 'extra-pre' list e.g., specifying 'python2' for when python3 defaults but python >3.3 is installed but not supported. ''' if java_commands: p = _subprocess.Popen(['java'] + java_commands, stdout=_subprocess.PIPE, stderr=_subprocess.STDOUT) output = p.stdout.read() if 'Error:' in output: print(output) return(False) else: print(output) return(True) else: if system: cmd = path[-1:] elif path[0][0] == _os.path.sep or path[0] == '': # absolute path to elsewhere provided cmd = [_os.path.sep.join(path)] else: cmd = [_os.path.sep.join(['external_programs'] + path)] if extra: cmd += extra if extra_pre: cmd = extra_pre + cmd try: o = _subprocess.check_output(cmd) o = '\n'.join(['external> '+l for l in o.split('\n')])+'\n' print(o) # eventually put in the debugging log <== too much noise # some programs output a help screen if commands not given # . . . they are installed and available return(True) except _subprocess.CalledProcessError as e: if e.returncode == success_returncode: # some programs that exit return non-zero code if commands not given # usually this is 1, but occasionally it is 2 (e.g. cutadapt) # but a fail on 2 is e.g. python calling a non-existent python program # should be set in the dependencies dictionary if not 1 (default) # . . . but they are installed and available return(True) else: return(False) except OSError as e: print('{}: {}'.format(cmd[0], e)) return(False)