From 1a3ebc46757e5bd16967c9b9352c23b48c849b73 Mon Sep 17 00:00:00 2001 From: George Hunt Date: Wed, 1 Sep 2021 19:17:08 +0100 Subject: [PATCH] add python approach to getting site_pachages path --- roles/jupyterhub/tasks/install.yml | 6 ++++++ roles/jupyterhub/templates/getsite.py | 7 +++++++ roles/jupyterhub/templates/patch_await.sh | 3 +-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100755 roles/jupyterhub/templates/getsite.py diff --git a/roles/jupyterhub/tasks/install.yml b/roles/jupyterhub/tasks/install.yml index 7182b5e92..10e8f7a7e 100644 --- a/roles/jupyterhub/tasks/install.yml +++ b/roles/jupyterhub/tasks/install.yml @@ -66,6 +66,12 @@ dest: "{{ jupyterhub_venv }}/bin/patch_await.sh" mode: 0755 +- name: Transfer a python program to fetch the site_packages path + template: + src: getsite.py + dest: "{{ jupyterhub_venv }}/bin/getsite.py" + mode: 0755 + - name: Now run the installed script ansible.builtin.shell: "{{ jupyterhub_venv }}/bin/patch_await.sh" diff --git a/roles/jupyterhub/templates/getsite.py b/roles/jupyterhub/templates/getsite.py new file mode 100755 index 000000000..81f1c611d --- /dev/null +++ b/roles/jupyterhub/templates/getsite.py @@ -0,0 +1,7 @@ +#!/opt/iiab/jupyterhub/bin/python3 + +import site + +for path in iter(site.getsitepackages()): + if path.find('site') != -1: + print(path) diff --git a/roles/jupyterhub/templates/patch_await.sh b/roles/jupyterhub/templates/patch_await.sh index a4a33b865..a9ea8c9a9 100755 --- a/roles/jupyterhub/templates/patch_await.sh +++ b/roles/jupyterhub/templates/patch_await.sh @@ -1,8 +1,7 @@ #!/bin/bash -x # add await to asyncio change password function -SITE_PACKAGES=$({{ jupyterhub_venv }}/bin/python -m site|grep -v exist|grep site) -SITE_PACKAGES=${SITE_PACKAGES:5:-2} +SITE_PACKAGES=$({{ jupyterhub_venv }}/bin/getsite.py) cat $SITE_PACKAGES/firstuseauthenticator/firstuseauthenticator.py |grep 'await self.render' if [ $? -ne 0 ];then echo Updating file