From 764ed0fdc40b323f215430e70ee710eba5d148c0 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Thu, 10 Sep 2015 12:26:43 -0400 Subject: [PATCH 1/5] Added _is_root() Cross-platform way to check admin rights http://stackoverflow.com/questions/1026431/cross-platform-way-to-check-admin-rights-in-a-python-script-under-windows --- bash_kernel/install.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index f123bfc..c0680d2 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -22,6 +22,14 @@ def install_my_kernel_spec(user=True): print('Installing IPython kernel spec') install_kernel_spec(td, 'bash', user=user, replace=True) +def _is_root(): + """Cross-platform way to check admin rights""" + import ctypes, os + try: + return os.geteuid() == 0 + except AttributeError: + return ctypes.windll.shell32.IsUserAnAdmin() != 0 + def main(argv=None): install_my_kernel_spec() From 2b8d126b1e498c948a507ebbaf41bbd89aa693a8 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Thu, 10 Sep 2015 12:29:40 -0400 Subject: [PATCH 2/5] Added commandline swtich "--user" for home directory installation when root. --- bash_kernel/install.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index c0680d2..ca76f3a 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -30,8 +30,9 @@ def _is_root(): except AttributeError: return ctypes.windll.shell32.IsUserAnAdmin() != 0 -def main(argv=None): - install_my_kernel_spec() +def main(argv=[]): + user = '--user' in argv or not _is_root() + install_my_kernel_spec(user=user) if __name__ == '__main__': - main() + main(argv=sys.argv) From 6862c63063ce51ca131a41ba2e3a16fbc1b0aa30 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Fri, 11 Sep 2015 09:40:37 -0400 Subject: [PATCH 3/5] Assume not an admin on non-Unix platforms --- bash_kernel/install.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index ca76f3a..3de6cd3 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -23,12 +23,11 @@ def install_my_kernel_spec(user=True): install_kernel_spec(td, 'bash', user=user, replace=True) def _is_root(): - """Cross-platform way to check admin rights""" import ctypes, os try: return os.geteuid() == 0 except AttributeError: - return ctypes.windll.shell32.IsUserAnAdmin() != 0 + return False # assume not an admin on non-Unix platforms def main(argv=[]): user = '--user' in argv or not _is_root() From 5eb4c499454f72d73d8cfbfad283bd7edbc84955 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Fri, 11 Sep 2015 09:42:59 -0400 Subject: [PATCH 4/5] ctypes no longer necessary --- bash_kernel/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index 3de6cd3..15610bb 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -23,7 +23,7 @@ def install_my_kernel_spec(user=True): install_kernel_spec(td, 'bash', user=user, replace=True) def _is_root(): - import ctypes, os + import os try: return os.geteuid() == 0 except AttributeError: From b464fcf54bc46a7ec05e294cb7ecceff0a331656 Mon Sep 17 00:00:00 2001 From: Carl Osterwisch Date: Fri, 25 Sep 2015 11:38:01 -0400 Subject: [PATCH 5/5] Removed redundant import of os module --- bash_kernel/install.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bash_kernel/install.py b/bash_kernel/install.py index 15610bb..68d2fa1 100644 --- a/bash_kernel/install.py +++ b/bash_kernel/install.py @@ -23,7 +23,6 @@ def install_my_kernel_spec(user=True): install_kernel_spec(td, 'bash', user=user, replace=True) def _is_root(): - import os try: return os.geteuid() == 0 except AttributeError: