summaryrefslogtreecommitdiffstats
path: root/tools/devassistant/files/crt/python/openlmi/tools/gen_code.sh
blob: 8a7349b8a7c240b91a9e11fed7e6243d87bbf5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash

# This script generates Python code skeleton for each class defined in the MOF files.
# At the moment, MOF files need to be registered in the CIMOM in order to be able
# to generate the code. This is rather unfortunate and requires root privileges.
#
# Make sure to set proper LMI_CIMOM_USERNAME and LMI_CIMOM_PASSWORD env. variables!
#
# This script takes optional argument of project name, i.e. when regenerating within
# an existing project. Leave blank for devassistant template preparation.


SITE_PACKAGES=`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`
TMPL_NAME="{{PROJECT_NAME}}"
TMPL_SUFFIX=".tpl"

if [ ! -z $1 ]; then
  TMPL_NAME=$1
  TMPL_SUFFIX=""
fi

openlmi-mof-register --just-mofs register ../mof/*.mof*
rm -f ../mof/${TMPL_NAME}.reg${TMPL_SUFFIX}

pushd ../src/lmi/*
for i in `cat ../../../mof/*.mof* | grep '^class.*:' | sed 's/^class[\t ]*\(.*\)[\t ]*:.*/\1/'`; do
  echo "Generating code for class '${i}'"
  python > ${i}.py << PYGEN
import pywbem
import pywbem.cim_provider2
import os

username = os.environ.get("LMI_CIMOM_USERNAME", "root")
password = os.environ.get("LMI_CIMOM_PASSWORD", "")

con = pywbem.WBEMConnection("https://localhost", (username, password))
cc = con.GetClass("${i}", "root/cimv2")

python_code, registration = pywbem.cim_provider2.codegen(cc)
print python_code

PYGEN

  # Fill the reg file
  cat >> ../../../mof/${TMPL_NAME}.reg${TMPL_SUFFIX} << REG
[${i}]
   provider: ${SITE_PACKAGES}/lmi/${TMPL_NAME}/${i}.py
   location: pyCmpiProvider
   type: instance
   namespace: root/cimv2
   group: pycmpi${TMPL_NAME}

REG

done
popd

openlmi-mof-register --just-mofs unregister ../mof/*.mof*