Skip to content

Instantly share code, notes, and snippets.

@guoxx
Created August 31, 2012 13:53
Show Gist options
  • Save guoxx/3552942 to your computer and use it in GitHub Desktop.
Save guoxx/3552942 to your computer and use it in GitHub Desktop.
svn_addremove
import os, sys, io, string
def specifyFileExts():
return ("png", "jpg", "jpx", "plist")
def str_dealer(content):
if content.startswith(("?", "!")):
content = content.replace("?", "svn add ", 1)
content = content.replace("!", "svn del ", 1)
if content.endswith(specifyFileExts()) and content.count("@") > 0:
content = content + "@"
return content
else:
return None
def svn_addremove(path):
pipefd = os.pipe()
pid = os.fork()
if pid == 0:
os.dup2(pipefd[1], sys.stdout.fileno())
os.system("svn st " + path)
else:
os.wait()
resultLists = []
lineinfo = os.read(pipefd[0], 65536)
lines = string.split(lineinfo, "\n")
for content in lines:
content = str_dealer(content)
if content is not None:
resultLists.append(content)
os.system("\n".join(resultLists))
if __name__ == '__main__':
if len(sys.argv) > 1:
svn_path = sys.argv[1]
else:
svn_path = "."
print svn_path
svn_addremove(svn_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment