Skip to content

Instantly share code, notes, and snippets.

@acken
Created March 20, 2014 22:49
Show Gist options
  • Save acken/9675693 to your computer and use it in GitHub Desktop.
Save acken/9675693 to your computer and use it in GitHub Desktop.
OpenIDE reactive script for automatically adding and removing .cs files as they are created/deleted
#!/usr/bin/env python
import os
import sys
import subprocess
def runProcess(exe,workingDir=""):
if workingDir == "":
workingDir = os.getcwd()
subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=workingDir)
def getFile(event, token):
start = event.find(token) + len(token)
return event[start:]
def handleFile(file, action):
dir = os.path.dirname(file)
runProcess(['oi', 'C#', action+'file', file], dir)
def main(argv):
if len(argv) > 1:
if argv[1] == 'reactive-script-reacts-to':
# Write one event pr line that this script will react to
print 'codemodel raw-filesystem-change-filecreated*.cs"'
print 'codemodel filesystem-change-filedeleted*.cs"'
return
event = argv[1]
if '-filecreated' in event:
file = getFile(event, ' raw-filesystem-change-filecreated ')
handleFile(file, 'add')
else:
file = getFile(event, ' filesystem-change-filedeleted ')
handleFile(file, 'remove')
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment