From 910f64e46525c08f34c2f52aaff38201bc6def38 Mon Sep 17 00:00:00 2001 From: Claude <becker@phys.ethz.ch> Date: Thu, 29 Nov 2018 14:12:39 +0100 Subject: [PATCH] restructure as python module --- README.md | 72 +++---------------- ...-permissions.py => check-home-permissions} | 6 +- bin/{deltalogcat.py => deltalogcat} | 6 +- bin/{deltalogparse.py => deltalogparse} | 6 +- bin/lib_path.py | 18 ----- bin/{showgroup.py => showgroup} | 10 ++- bin/{showuser.py => showuser} | 10 ++- bin/{sync-winhosts.py => sync-winhosts} | 6 +- bin/{xymon-home.py => xymon-home} | 8 +-- ...xymon-permissions.py => xymon-permissions} | 4 +- isgphys/__init__.py | 0 {lib/isg => isgphys}/argparser.py | 0 {lib/isg => isgphys}/dphysldap.py | 2 - {lib/isg => isgphys}/pyxymon.py | 0 lib/.gitignore | 2 - lib/__init__.py | 21 ------ lib/isg/lib_path.py | 18 ----- requirements-git.txt | 1 - requirements-pip.txt | 4 -- requirements.txt | 2 - setup.py | 17 +++++ 21 files changed, 48 insertions(+), 165 deletions(-) rename bin/{check-home-permissions.py => check-home-permissions} (99%) rename bin/{deltalogcat.py => deltalogcat} (98%) rename bin/{deltalogparse.py => deltalogparse} (99%) delete mode 100644 bin/lib_path.py rename bin/{showgroup.py => showgroup} (94%) rename bin/{showuser.py => showuser} (90%) rename bin/{sync-winhosts.py => sync-winhosts} (99%) rename bin/{xymon-home.py => xymon-home} (99%) rename bin/{xymon-permissions.py => xymon-permissions} (98%) create mode 100644 isgphys/__init__.py rename {lib/isg => isgphys}/argparser.py (100%) rename {lib/isg => isgphys}/dphysldap.py (99%) rename {lib/isg => isgphys}/pyxymon.py (100%) delete mode 100644 lib/.gitignore delete mode 100644 lib/__init__.py delete mode 100644 lib/isg/lib_path.py delete mode 100644 requirements-git.txt delete mode 100644 requirements-pip.txt delete mode 100644 requirements.txt create mode 100644 setup.py diff --git a/README.md b/README.md index 077798c..dba1a08 100644 --- a/README.md +++ b/README.md @@ -4,75 +4,23 @@ This repo contains python scripts and modules which may not be available as pack ## installation -Clone the repo: +Install the required packages -``` -git clone git@gitlab.phys.ethz.ch:core/python.git -cd python -``` - -Install the requirements. - -## requirements - -### system - -**Required** minimal packages: - -``` -apt install python3 python3-dev python3-setuptools python3-pip libacl1-dev libkrb5-dev +```sh +apt install python3 python3-dev python3-setuptools python3-pip python3-virtualenv virtualenv libacl1-dev libkrb5-dev ``` -### git / pip - -**Recommended** install from a clean venv (may be needed if you have any conflicting outdated modules installed as packages): +then clone the repo and install it inside a virtualenv ``` -python3 -m venv venv -source venv/bin/activate -pip3 install --upgrade pip -pip3 install -r requirements-git.txt -t lib/git -pip3 install -r requirements-pip.txt -t lib/pip +cd /opt +git clone git@gitlab.phys.ethz.ch:core/python.git +cd python +virtualenv -p python3 .venv +source .venv/bin/activate +pip install -e . deactivate -rm -r venv -``` - -**Alternative** modules in local lib directory (this will probably not work): - ``` -/usr/bin/pip3 install -r requirements-git.txt -t lib/git -/usr/bin/pip3 install -r requirements-pip.txt -t lib/pip -``` - - -## modules - -Store or load modules in these directories: - -- `lib/isg/`: modules developed at isg dphys -- `lib/git/`: modules installed with git (github) -- `lib/pip/`: modules installed with pip - -In your script or module the following 2 imports are required in order: - -```python -import lib_path -import lib -``` - -In `ipython3` the following import is required: - -```python -import lib -``` - -After that you can import modules from the lib paths, searched in the following order `isg` > `git` > `pip` > `system`.` - -## scripts - -Store scripts here: - -- `bin/` ## feature request diff --git a/bin/check-home-permissions.py b/bin/check-home-permissions similarity index 99% rename from bin/check-home-permissions.py rename to bin/check-home-permissions index 5a747c8..ec0aeba 100755 --- a/bin/check-home-permissions.py +++ b/bin/check-home-permissions @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 import os import sys @@ -6,9 +6,7 @@ import pwd import grp import stat import posix1e -import lib_path -import lib -import dphysldap +import isgphys.dphysldap as dphysldap home_dirs = 0 diff --git a/bin/deltalogcat.py b/bin/deltalogcat similarity index 98% rename from bin/deltalogcat.py rename to bin/deltalogcat index fe076d2..f07578c 100755 --- a/bin/deltalogcat.py +++ b/bin/deltalogcat @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 #import os import sys @@ -8,10 +8,8 @@ import select import pprint import json import argparse -import lib_path -import lib -import dphysldap import tabulate +import isgphys.dphysldap as dphysldap #SLEEP_INTERVAL = 1.0 update_every = 0.001 diff --git a/bin/deltalogparse.py b/bin/deltalogparse similarity index 99% rename from bin/deltalogparse.py rename to bin/deltalogparse index 81103a7..0d2dd39 100755 --- a/bin/deltalogparse.py +++ b/bin/deltalogparse @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 import sys import fcntl @@ -10,9 +10,7 @@ import logging import json import mmap import base64 -import lib_path -import lib -import dphysldap +import isgphys.dphysldap as dphysldap # security warning: using DEBUG may log sensitive data # log levels: CRITICAL | ERROR | WARNING | INFO | DEBUG | NOTSET diff --git a/bin/lib_path.py b/bin/lib_path.py deleted file mode 100644 index 40e9da8..0000000 --- a/bin/lib_path.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -#print('__file__: ' + __file__) - -script_path = os.path.dirname(os.path.realpath(__file__)) -#print('script_path: ' + script_path) - -lib_path = os.path.abspath('/'.join([script_path, '..'])) -#print('lib_path: ' + lib_path) - -sys.path.insert(0, lib_path) - -#print('sys.path: ') -#for path in sys.path: -# print(' ' * 4 + path) diff --git a/bin/showgroup.py b/bin/showgroup similarity index 94% rename from bin/showgroup.py rename to bin/showgroup index 6f23bed..41532aa 100755 --- a/bin/showgroup.py +++ b/bin/showgroup @@ -1,11 +1,9 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 -import sys import collections -import lib_path -import lib -import argparser -import dphysldap +import sys +import isgphys.argparser as argparser +import isgphys.dphysldap as dphysldap OPTS = collections.OrderedDict() OPTS['access'] = 'accessRight' diff --git a/bin/showuser.py b/bin/showuser similarity index 90% rename from bin/showuser.py rename to bin/showuser index e3151c3..102e921 100755 --- a/bin/showuser.py +++ b/bin/showuser @@ -1,11 +1,9 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 -import sys import collections -import lib_path -import lib -import argparser -import dphysldap +import sys +import isgphys.argparser as argparser +import isgphys.dphysldap as dphysldap OPTS = collections.OrderedDict() OPTS['access'] = 'accessRight' diff --git a/bin/sync-winhosts.py b/bin/sync-winhosts similarity index 99% rename from bin/sync-winhosts.py rename to bin/sync-winhosts index 07483fa..16ef73c 100755 --- a/bin/sync-winhosts.py +++ b/bin/sync-winhosts @@ -1,14 +1,12 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 -import lib_path -import lib -#import dphysldap import ssl import os from datetime import datetime from itertools import count, filterfalse from ldap3 import Server, Connection, ALL, Tls, SASL, GSSAPI, ServerPool, RANDOM +#import isgphys.dphysldap as dphysldap # ldap = dphysldap.Ldap(ca_certs_file=".\\ca-certificates.crt") main_windows_netgroup = "windows" diff --git a/bin/xymon-home.py b/bin/xymon-home similarity index 99% rename from bin/xymon-home.py rename to bin/xymon-home index 5361efe..fee371a 100755 --- a/bin/xymon-home.py +++ b/bin/xymon-home @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 import os import sys @@ -6,11 +6,9 @@ import pwd import grp import stat import glob -import lib_path -import lib import posix1e -import dphysldap -import pyxymon as pymon +import isgphys.dphysldap as dphysldap +import isgphys.pyxymon as pymon CHECK_NAME = 'permissions' CHECK_VERSION = 4 diff --git a/bin/xymon-permissions.py b/bin/xymon-permissions similarity index 98% rename from bin/xymon-permissions.py rename to bin/xymon-permissions index 1f3f9c3..fc54974 100755 --- a/bin/xymon-permissions.py +++ b/bin/xymon-permissions @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/opt/python/.venv/bin/python3 import os import sys @@ -7,7 +7,7 @@ import grp import stat import glob import posix1e -import pyxymon as pymon +import isgphys.pyxymon as pymon CHECK_NAME = 'permissions' CHECK_VERSION = 2 diff --git a/isgphys/__init__.py b/isgphys/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/isg/argparser.py b/isgphys/argparser.py similarity index 100% rename from lib/isg/argparser.py rename to isgphys/argparser.py diff --git a/lib/isg/dphysldap.py b/isgphys/dphysldap.py similarity index 99% rename from lib/isg/dphysldap.py rename to isgphys/dphysldap.py index 7aaeb68..d549ea7 100644 --- a/lib/isg/dphysldap.py +++ b/isgphys/dphysldap.py @@ -3,8 +3,6 @@ import ssl import collections import time -import lib_path -import lib import ldap3 import tabulate diff --git a/lib/isg/pyxymon.py b/isgphys/pyxymon.py similarity index 100% rename from lib/isg/pyxymon.py rename to isgphys/pyxymon.py diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index 57161b9..0000000 --- a/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -git/ -pip/ diff --git a/lib/__init__.py b/lib/__init__.py deleted file mode 100644 index b50046e..0000000 --- a/lib/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -#print('__file__: ' + __file__) - -lib_path = os.path.dirname(os.path.realpath(__file__)) -#print('lib_path: ' + lib_path) - -lib_pip = '/'.join([lib_path, 'pip']) -lib_git = '/'.join([lib_path, 'git']) -lib_isg = '/'.join([lib_path, 'isg']) - -sys.path.insert(0, lib_pip) -sys.path.insert(0, lib_git) -sys.path.insert(0, lib_isg) - -#print('sys.path: ') -#for path in sys.path: -# print(' ' * 4 + path) diff --git a/lib/isg/lib_path.py b/lib/isg/lib_path.py deleted file mode 100644 index 91a6ea0..0000000 --- a/lib/isg/lib_path.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -#print('__file__: ' + __file__) - -script_path = os.path.dirname(os.path.realpath(__file__)) -#print('script_path: ' + script_path) - -lib_path = os.path.abspath('/'.join([script_path, '../..'])) -#print('lib_path: ' + lib_path) - -sys.path.insert(0, lib_path) - -#print('sys.path: ') -#for path in sys.path: -## print(' ' * 4 + path) diff --git a/requirements-git.txt b/requirements-git.txt deleted file mode 100644 index 6c0c5aa..0000000 --- a/requirements-git.txt +++ /dev/null @@ -1 +0,0 @@ -git+https://github.com/skurfer/python-xymon.git#egg=xymon diff --git a/requirements-pip.txt b/requirements-pip.txt deleted file mode 100644 index bd3300e..0000000 --- a/requirements-pip.txt +++ /dev/null @@ -1,4 +0,0 @@ -gssapi -ldap3 -tabulate -pylibacl diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8f8d3ec..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r requirements-git.txt --r requirements-pip.txt diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..69fc7b7 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +import glob +from distutils.core import setup + +setup( + name='isgphys', + version='0.0.1', + description='ISG D-PHYS Python Modules and Scripts', + py_modules=['isgphys'], + scripts=glob.glob('bin/*'), + install_requires=[ + 'gssapi', + 'ldap3', + 'pylibacl', + 'tabulate', + 'xymon', + ] +) -- GitLab