I'm cleaning build directories produced by GNOME build tool, JHBuild. This tool either downloads tarballs or clones git repositories, depending on set-up. After that, it proceeds to compilation (and then installation). Once in a while, something gets screwed up, and I need to clean the build directories so that I can start from scratch (because I don't know how to fix some of these problems).
Here's how I did it, and I'd like you to tell me if it can be improved:
import os
import subprocess
top_level = os.path.expanduser("~/src/gnome")
for filename in os.listdir(top_level):
full_path = "{}/{}".format(top_level, filename)
if os.path.isdir(full_path):
cmd = "cd ~/src/gnome/{} && git clean -dfx".format(filename)
if subprocess.call(cmd, shell=True) != 0:
cmd = "cd ~/src/gnome/{} && make distclean".format(filename)
if subprocess.call(cmd, shell=True) != 0:
cmd = "cd ~/src/gnome/{} && make clean".format(filename)
subprocess.call(cmd, shell=True)