I am analyzing the repo script from Google (instructions at http://source.android.com/source/downloading.html)
The repo script is written in Python. There is a part in there that says:
if sys.argv[-1] =='#%s' % magic
Can somebody explain semantically what that line means? I am a bit rusty on my Python. The entire block of code for this is:
magic='--calling-python-from-/bin/sh--'
"""exec" python -E "$0" "$@" """#$magic"
if __name__ == '__main__':
import sys
if sys.argv[-1] =='#%s' % magic:
del sys.argv[-1]
One piece at the time:
sys.argvholds the list of command line arguments passed to a Python script. Meaning thatsys-argv[-1]is the last argument.'#%s' % magic. The%formats your string, which means the where you see%sthere’s going to be the value ofmagic(ifmagicis not a string it will be converted:str(magic)). In your code that string is going to be:'#--calling-python-from-/bin/sh--'.del sys.argv[-1]. This is self-explainatory: means that the last value of the listsys.argvis going to be removed.All together it means that: if the last command line argument is
#--calling-python-from-/bin/sh--that argument is going to be removed fromsys.argv.