summaryrefslogtreecommitdiffstats
path: root/openlmi-mof-register
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2013-11-25 12:32:27 +0100
committerJan Safranek <jsafrane@redhat.com>2013-11-25 12:32:27 +0100
commita693e68d280d39d9a592892d22ea14d51fdccae9 (patch)
tree9551ac6c18d113aef567faa10714e1df9efa5c1b /openlmi-mof-register
parenta868f7e9f64ac7e91240b3c69f219372f8515cd4 (diff)
downloadopenlmi-providers-a693e68d280d39d9a592892d22ea14d51fdccae9.zip
openlmi-providers-a693e68d280d39d9a592892d22ea14d51fdccae9.tar.gz
openlmi-providers-a693e68d280d39d9a592892d22ea14d51fdccae9.tar.xz
openlmi-mof-register: parse '#pragma include' in mof files and copy all included mofs to cache.
/usr/bin/mofcomp from pywbem is used for the parsing.
Diffstat (limited to 'openlmi-mof-register')
-rwxr-xr-xopenlmi-mof-register20
1 files changed, 19 insertions, 1 deletions
diff --git a/openlmi-mof-register b/openlmi-mof-register
index 85fbcd3..6a0c154 100755
--- a/openlmi-mof-register
+++ b/openlmi-mof-register
@@ -307,6 +307,20 @@ def db_get_registrations(cursor, mofs, reg):
ret = cursor.fetchall()
return ret
+def parse_includes(mofs, namespace):
+ # Get list of all files included from mofs, including the original mofs
+ # Misuse mofcomp --dry-run
+ out = subprocess.check_output(["/usr/bin/mofcomp", "-v", "-d", "-n", namespace]
+ + mofs)
+
+ final_mofs = []
+ include = re.compile("^Compiling file (.*)")
+ for line in out.split("\n"):
+ match = include.match(line)
+ if match:
+ final_mofs.append(match.group(1))
+ return final_mofs
+
def db_register(mofs, reg, version, namespace, cimom):
db = db_init()
dbc = db.cursor()
@@ -326,17 +340,19 @@ def db_register(mofs, reg, version, namespace, cimom):
log_msg("ERROR: Cannot update multiple registrations")
db_close(db)
return
- for moffile in mofs:
+ for moffile in parse_includes(mofs, namespace):
# backup the mof file and create the database record
bmof = os.path.basename(moffile)
copyfile(moffile, REG_DB_PATH + "/mof/" + bmof)
dbc.execute("INSERT INTO mof (fname, registration_id) VALUES (?, ?)",
(bmof, reg_id))
+ log_msg("%s added to database" % (bmof,))
if reg:
# backup the reg file and create the database record
copyfile(reg, REG_DB_PATH + "/reg/" + os.path.basename(reg))
dbc.execute("INSERT INTO reg (fname, registration_id) VALUES (?, ?)",
(os.path.basename(reg), reg_id))
+ log_msg("%s added to database" % (reg,))
if cimom['sfcbd']:
dbc.execute("INSERT INTO cimom_opts (cimom, registration_id, namespace, version) \
VALUES (?, ?, ?, ?)", ('sfcbd', reg_id, namespace, version))
@@ -356,6 +372,7 @@ def db_unregister(mofs, reg, version, namespace, cimom):
for bmof in dbc.execute("SELECT fname FROM mof WHERE (registration_id = ?)", (reg_id,)):
try:
os.unlink(REG_DB_PATH + "/mof/" + bmof[0])
+ log_msg("%s removed from database" % (bmof[0]))
except OSError as e:
log_msg("Error deleting " + bmof[0] + ": " + e.strerror)
dbc.execute("SELECT fname FROM reg WHERE registration_id = ?", (reg_id,))
@@ -363,6 +380,7 @@ def db_unregister(mofs, reg, version, namespace, cimom):
if breg:
try:
os.unlink(REG_DB_PATH + "/reg/" + breg[0])
+ log_msg("%s removed from database" % (breg[0]))
except OSError as e:
log_msg("Error deleting " + breg[0] + ": " + e.strerror)
dbc.execute("DELETE FROM registration WHERE (id = ?)", (reg_id,))