Skip to content

Instantly share code, notes, and snippets.

@royvandam
Created December 16, 2016 18:44
Show Gist options
  • Save royvandam/f7afb5296b09cfc41435d3a68220660e to your computer and use it in GitHub Desktop.
Save royvandam/f7afb5296b09cfc41435d3a68220660e to your computer and use it in GitHub Desktop.
Add files to svn:ignore propset the easy way...
#!/usr/bin/env python
# Call from your SVN directory the following way:
# svn status | grep '?' | tr -s ' ' | cut -d' ' -f2 | xargs -n1 ./svn_ignore.py
import sys, os, subprocess
def svn(action, argv=[], stdin=None):
cmd = ['svn', action]
cmd.extend(argv)
proc = subprocess.Popen(cmd, stdin=stdin,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
output = proc.communicate()[0].split('\n')
return proc.returncode, list( l for l in output if l )
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.stderr.write("usage: %s file_to_ignore\n" % sys.argv[0])
sys.exit(1)
filepath = sys.argv[1]
if not os.path.exists(filepath):
sys.stderr.write("Error: path '%s' does not exsist.\n" % filepath)
sys.exit(1)
path = os.path.dirname(filepath)
filename = os.path.basename(filepath)
result, ignored = svn('pg', ['svn:ignore', path])
if filename in ignored:
sys.stdout.write("File '%s' already ignored in path '%s'.\n" % (filename, path))
sys.exit(0)
ignored.append(filename)
sys.stdout.write("Adding '%s' to svn:ignore in path '%s'... " % (filename, path))
sys.stdout.flush()
result, output = svn('ps', ['svn:ignore', '%s' % '\n'.join(ignored), path])
sys.stdout.write("success\n" if result == 0 else "failed\n")
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment