Skip to content
Snippets Groups Projects
Commit bd764928 authored by Joe Garcia's avatar Joe Garcia
Browse files

re-l documentation!

parent 452975ad
No related branches found
No related tags found
No related merge requests found
...@@ -51,9 +51,11 @@ def getLine(f,linenumber=1):#returns native string (ascii or unicode) ...@@ -51,9 +51,11 @@ def getLine(f,linenumber=1):#returns native string (ascii or unicode)
v='' v=''
return v return v
#deterimine if the script is a single-parameter env-based script file
def isRelScript(filepath): def isRelScript(filepath):
return getLine(filepath,linenumber=1)=='#!/usr/bin/env re-l' return getLine(filepath,linenumber=1)=='#!/usr/bin/env re-l'
#extract the interpreter from a scriptfile
def extractRelInterpreter(filepath): def extractRelInterpreter(filepath):
if not isRelScript(filepath): if not isRelScript(filepath):
raise RuntimeError("Not a re-l script!") raise RuntimeError("Not a re-l script!")
...@@ -63,11 +65,12 @@ def extractRelInterpreter(filepath): ...@@ -63,11 +65,12 @@ def extractRelInterpreter(filepath):
return l.split(':',1)[1].strip() return l.split(':',1)[1].strip()
raise RuntimeError("Couldn't find re-lative interpreter line (starts with '#re-l:')") raise RuntimeError("Couldn't find re-lative interpreter line (starts with '#re-l:')")
def relexec(interpreter,scriptfile,*_args): #executes a scriptfile using a relative interpreter with given commandline args
def relexec(scriptrelativeinterpreter,scriptfile,*_args):
args=[None,None]+list(_args) args=[None,None]+list(_args)
LOG('%s %s' % (interpreter,scriptfile)) LOG('%s %s' % (scriptrelativeinterpreter,scriptfile))
scriptpath=os.path.dirname(os.path.realpath(scriptfile)) scriptpath=os.path.dirname(os.path.realpath(scriptfile))
interpreter=os.path.normpath(os.path.join(scriptpath,interpreter)) interpreter=os.path.normpath(os.path.join(scriptpath,scriptrelativeinterpreter))
LOG('%s %s' % (scriptpath,interpreter)) LOG('%s %s' % (scriptpath,interpreter))
args[0]=interpreter args[0]=interpreter
args[1]=scriptfile args[1]=scriptfile
...@@ -84,6 +87,17 @@ def relexec(interpreter,scriptfile,*_args): ...@@ -84,6 +87,17 @@ def relexec(interpreter,scriptfile,*_args):
raise RuntimeError('Exec Failed') raise RuntimeError('Exec Failed')
def main(): def main():
if len(sys.argv)<2 or (len(sys.argv)<3 and not isRelScript(sys.argv[1])):
print('re-l relative interpreter proxy script')
print('Usage: with re-l anywhere in the path modify any script shebang to be:')
if 'darwin' in sys.platform:
print('\t#!/usr/bin/env re-l relative/path/to/interpeter')
else:
print('\t#!/usr/bin/env re-l')
print('and then for the second or third line, add the line:')
print('\t#re-l:relative/path/to/interpeter')
print('where the interpreter is identified relative to the script file itself')
sys.exit(0)
if len(sys.argv)==2 or isRelScript(sys.argv[1]): if len(sys.argv)==2 or isRelScript(sys.argv[1]):
assert(isRelScript(sys.argv[1])) assert(isRelScript(sys.argv[1]))
relexec(extractRelInterpreter(sys.argv[1]),sys.argv[1],*sys.argv[2:]) relexec(extractRelInterpreter(sys.argv[1]),sys.argv[1],*sys.argv[2:])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment