diff --git a/src/amuse/community/mocassin/patch_files.py b/src/amuse/community/mocassin/patch_files.py index 745536d73c..a913ee6fb1 100755 --- a/src/amuse/community/mocassin/patch_files.py +++ b/src/amuse/community/mocassin/patch_files.py @@ -6,53 +6,78 @@ import re PATCHESDIR = "patches" -QUILT_PC = ".pc" +QUILT_PC = ".pc" -def execute_command_line(arguments, cwd = None): - process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd = cwd) + +def execute_command_line(arguments, cwd=None): + process = subprocess.Popen( + arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd + ) stdoutstring, stderrstring = process.communicate() returncode = process.poll() return stdoutstring, stderrstring, returncode - + + def which(executablename): - stdoutstring, stderrstring, returncode = execute_command_line(['which', executablename]) + stdoutstring, stderrstring, returncode = execute_command_line( + ["which", executablename] + ) if not returncode == 0: return None else: return stdoutstring - + + def is_quilt_installed(): - path = which('quilt') + path = which("quilt") if path is None: return False - - stdoutstring, stderrstring, returncode = execute_command_line(['quilt', '--version']) + + stdoutstring, stderrstring, returncode = execute_command_line( + ["quilt", "--version"] + ) if not returncode == 0: return False - - version_re = re.compile(r'(\d).(\d\d)') - match = version_re.match(stdoutstring) + + version_re = re.compile(r"(\d).(\d\d)") + match = version_re.match(str(stdoutstring)) if not match: return False - + return True + def apply_patches_using_quilt(): - returncode = subprocess.call(['quilt', 'push', '-a']) + returncode = subprocess.call(["quilt", "push", "-a"]) if not returncode == 0: - raise Exception("error in applying the patches, please apply by hand using quilt push") - + raise Exception( + "error in applying the patches, please apply by hand using quilt push" + ) + + def undo_patches_using_quilt(): - returncode = subprocess.call(['quilt', 'pop', '-a']) + returncode = subprocess.call(["quilt", "pop", "-a"]) if not returncode == 0: - raise Exception("error in undoing the patches, please undo by hand using quilt pop -a") + raise Exception( + "error in undoing the patches, please undo by hand using quilt pop -a" + ) + def run_patch(patchname, patchfile): - arguments = ['patch', '-p1', '--backup', '--prefix={0}/{1}/'.format(QUILT_PC, patchname), '-E', '-i', patchfile] + arguments = [ + "patch", + "-p1", + "--backup", + "--prefix={0}/{1}/".format(QUILT_PC, patchname), + "-E", + "-i", + patchfile, + ] returncode = subprocess.call(arguments) if not returncode == 0: raise Exception("could not apply patch {0}".format(patchname)) - + + def apply_patches_using_patch(): with open("patches/series", "r") as f: lines = f.readlines() @@ -61,12 +86,13 @@ def apply_patches_using_patch(): for patch in patches: path = os.path.join(PATCHESDIR, patch) run_patch(patch, path) - -def main(undo_patches = False): - print("checking if quilt is installed ... ", end=' ') + + +def main(undo_patches=False): + print("checking if quilt is installed ... ", end=" ") if not is_quilt_installed(): print("no") - + if undo_patches: print("quilt is not installed, cannot undo the patches") sys.exit(1) @@ -75,7 +101,7 @@ def main(undo_patches = False): apply_patches_using_patch() else: print("yes") - + if undo_patches: print("quilt is install, will try to undo the patches") undo_patches_using_quilt() @@ -83,6 +109,7 @@ def main(undo_patches = False): print("applying patches to source code") apply_patches_using_quilt() print("all patches applied") - -if __name__ == '__main__': + + +if __name__ == "__main__": main()