2017-04-18 22:18:58 -04:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# This is a valid shell script and also a valid Python script. When this file
|
|
|
|
# is executed as a shell script, it finds a python binary and executes this
|
|
|
|
# file as a Python script, passing along all of the command line arguments.
|
|
|
|
# When this file is executed as a Python script, it loads and runs Dotbot. This
|
|
|
|
# is useful because we don't know the name of the python binary.
|
|
|
|
|
|
|
|
''':' # begin python string; this line is interpreted by the shell as `:`
|
2019-11-09 12:23:21 -05:00
|
|
|
command -v python >/dev/null 2>&1 && exec python "$0" "$@"
|
|
|
|
command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
|
|
|
|
command -v python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
|
2017-04-18 22:18:58 -04:00
|
|
|
>&2 echo "error: cannot find python"
|
2018-06-07 13:04:19 -04:00
|
|
|
exit 1
|
2017-04-18 22:18:58 -04:00
|
|
|
'''
|
|
|
|
|
|
|
|
# python code
|
2014-03-19 23:07:30 -04:00
|
|
|
|
|
|
|
import sys, os
|
|
|
|
|
|
|
|
PROJECT_ROOT_DIRECTORY = os.path.dirname(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
|
2014-10-27 20:04:00 -04:00
|
|
|
def inject(lib_path):
|
|
|
|
path = os.path.join(PROJECT_ROOT_DIRECTORY, 'lib', lib_path)
|
|
|
|
sys.path.insert(0, path)
|
|
|
|
|
|
|
|
# version dependent libraries
|
2014-12-18 17:52:02 -05:00
|
|
|
if sys.version_info[0] >= 3:
|
2014-10-27 20:04:00 -04:00
|
|
|
inject('pyyaml/lib3')
|
|
|
|
else:
|
|
|
|
inject('pyyaml/lib')
|
|
|
|
|
2014-03-19 23:07:30 -04:00
|
|
|
if os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'dotbot')):
|
|
|
|
if PROJECT_ROOT_DIRECTORY not in sys.path:
|
|
|
|
sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
|
|
|
|
os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY)
|
|
|
|
|
|
|
|
import dotbot
|
|
|
|
|
|
|
|
def main():
|
|
|
|
dotbot.cli.main()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|