python runscript without bash
(cherry picked from commit 9b148a6679722db5eb7ffabd3a27a8579f296319)
This commit is contained in:
parent
de77465383
commit
9389cfd3ee
43
bin/dotbot_from_python_manually.py
Normal file
43
bin/dotbot_from_python_manually.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
ARGS_TO_SCRIPT = "python >/dev/null /c/Users/Matt/dotfiles/dotbot/bin/dotbot -d /c/Users/Matt/dotfiles -c install.conf.yaml"
|
||||||
|
# These arguments are only linux/ bash safe
|
||||||
|
|
||||||
|
|
||||||
|
"""Script port from /c/Users/Matt/dotfiles/dotbot/bin/dotbot"""
|
||||||
|
import sys, os
|
||||||
|
DOTFILE_DIR = os.path.normpath(os.path.expandvars("%USERPROFILE%/dotfiles/"))
|
||||||
|
|
||||||
|
DIRECTORY_ARG = os.path.normpath(DOTFILE_DIR)
|
||||||
|
CONFIG_FILE_ARG = "install.conf.yaml"
|
||||||
|
|
||||||
|
sys.path.append(DOTFILE_DIR)
|
||||||
|
print(DOTFILE_DIR)
|
||||||
|
os.chdir(DOTFILE_DIR)
|
||||||
|
|
||||||
|
# PROJECT_ROOT_DIRECTORY = os.path.dirname(
|
||||||
|
# os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
# print(PROJECT_ROOT_DIRECTORY)
|
||||||
|
PROJECT_ROOT_DIRECTORY = DOTFILE_DIR
|
||||||
|
|
||||||
|
def inject(lib_path):
|
||||||
|
path = os.path.join(PROJECT_ROOT_DIRECTORY, 'lib', lib_path)
|
||||||
|
sys.path.insert(0, path)
|
||||||
|
|
||||||
|
# version dependent libraries
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
inject('pyyaml/lib3')
|
||||||
|
else:
|
||||||
|
inject('pyyaml/lib')
|
||||||
|
|
||||||
|
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(additional_args=["-d", DIRECTORY_ARG, "-c", CONFIG_FILE_ARG])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -44,12 +44,15 @@ def read_config(config_file):
|
||||||
reader = ConfigReader(config_file)
|
reader = ConfigReader(config_file)
|
||||||
return reader.get_config()
|
return reader.get_config()
|
||||||
|
|
||||||
def main():
|
def main(additional_args=None):
|
||||||
log = Messenger()
|
log = Messenger()
|
||||||
try:
|
try:
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
add_options(parser)
|
add_options(parser)
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
if additional_args is not None:
|
||||||
|
print("got explicit argumenets")
|
||||||
|
options = parser.parse_args(additional_args)
|
||||||
if options.version:
|
if options.version:
|
||||||
print('Dotbot version %s (yaml: %s)' % (dotbot.__version__, yaml.__version__))
|
print('Dotbot version %s (yaml: %s)' % (dotbot.__version__, yaml.__version__))
|
||||||
exit(0)
|
exit(0)
|
||||||
|
@ -85,6 +88,7 @@ def main():
|
||||||
if not options.config_file:
|
if not options.config_file:
|
||||||
log.error('No configuration file specified')
|
log.error('No configuration file specified')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
# read tasks from config file
|
||||||
tasks = read_config(options.config_file)
|
tasks = read_config(options.config_file)
|
||||||
if tasks is None:
|
if tasks is None:
|
||||||
log.warning('Configuration file is empty, no work to do')
|
log.warning('Configuration file is empty, no work to do')
|
||||||
|
|
Loading…
Reference in a new issue