Commits

anatoly techtonik committed 3b64a2f

bfg: list available tools

  • Participants
  • Parent commits 4ce0dd6

Comments (0)

Files changed (1)

 """User friendly command line interface for Bcfg2 wizardry"""
 
-import os
+import os, sys
 
 #: root self-sufficient directory with everything
 LOCALTREE = os.path.dirname(os.path.abspath(__file__))
+BINS = LOCALTREE + '/bin'
+LIBS = LOCALTREE + '/lib/python' +\
+         '.'.join([str(x) for x in sys.version_info[0:2]]) +\
+         '/site-packages/Bcfg2'
 
+
+# 01. Check environment and locate Bcfg2 binaries
+# [ ] validate OS and show warning for untested scenarios
+#      currently checked `setup.py --prefix` installation on Debian
+#      it creates bin/ lib/ share/, with Python stuff inside
+#      lib/pythonX.Y/site-packages, so this dir should be added to
+#      PYTHONPATH before executing Bcfg2 files
+
+# [x] check site-packages exists for current interpreter
+if not os.path.exists(LIBS):
+    print('Error: Bcfg2 libs are not found for current Python version')
+    sys.exit('       %s not found.' % LIBS)
+
+# [ ] add site-packages into PYTHONPATH
+
+# [x] list bcfg2 tools from bin/ dir if bfg.py is executed without params
+TOOLS = [x[6:] for x in os.listdir(BINS) if x.startswith('bcfg2')]
+# TOOL without name is bcfg2 client
+TOOLS.remove('')
+TOOLS.append('client')
+TOOLS.sort()
+
+import optparse
+opts, args = optparse.OptionParser().parse_args()
+if not args:
+    # [ ] print usage and list of Bcfg2 commands
+    for tool in TOOLS:
+        print('  ' + tool)
+