Add general storage parameters to node info call
[ganeti-local] / autotools / convert-constants
index 1d18540..0cb07bb 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 #
 
-# Copyright (C) 2011, 2012 Google Inc.
+# Copyright (C) 2011, 2012, 2013 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -30,7 +30,9 @@ from ganeti import compat
 from ganeti import constants
 from ganeti import errors
 from ganeti import luxi
+from ganeti import opcodes
 from ganeti import qlang
+from ganeti import jstore
 
 
 #: Constant name regex
@@ -85,6 +87,8 @@ def HaskellTypeVal(value):
   """
   if isinstance(value, basestring):
     return ("String", "\"%s\"" % StringValueRules(value))
+  elif isinstance(value, bool):
+    return ("Bool", "%s" % value)
   elif isinstance(value, int):
     return ("Int", "%d" % value)
   elif isinstance(value, long):
@@ -178,7 +182,7 @@ def FormatDict(all_items, pfx_name, py_name, hs_name, mydict):
 
   # finally generate the output
   kv_pairs = ["(%s, %s)" % (k, v) for k, v in zip(key_v, val_v)]
-  return ["-- | Converted from Python dictionary %s" % py_name,
+  return ["-- | Converted from Python dictionary @%s@" % py_name,
           "%s :: [(%s, %s)]" % (hs_name, key_type, val_type),
           "%s = [%s]" % (hs_name, ", ".join(kv_pairs)),
           ]
@@ -216,7 +220,7 @@ def ConvertVariable(prefix, name, value, all_items):
   elif hs_typeval is not None:
     # this is a simple value
     (hs_type, hs_val) = hs_typeval
-    lines.append("-- | Converted from Python constant %s" % fqn)
+    lines.append("-- | Converted from Python constant @%s@" % fqn)
     lines.append("%s :: %s" % (hs_name, hs_type))
     lines.append("%s = %s" % (hs_name, hs_val))
   elif isinstance(value, dict):
@@ -231,10 +235,17 @@ def ConvertVariable(prefix, name, value, all_items):
                                      value[k], all_items))
   elif isinstance(value, tuple):
     tvs = [HaskellTypeVal(elem) for elem in value]
+    # Custom rule for special cluster verify error tuples
+    if name.startswith("CV_E") and len(value) == 3 and tvs[1][0] is not None:
+      cv_ename = hs_name + "Code"
+      lines.append("-- | Special cluster verify code %s" % name)
+      lines.append("%s :: %s" % (cv_ename, tvs[1][0]))
+      lines.append("%s = %s" % (cv_ename, tvs[1][1]))
+      lines.append("")
     if compat.all(e is not None for e in tvs):
       ttypes = ", ".join(e[0] for e in tvs)
       tvals = FormatListElems(all_items, pfx_name, value, [e[1] for e in tvs])
-      lines.append("-- | Converted from Python tuple %s" % fqn)
+      lines.append("-- | Converted from Python tuple @%s@" % fqn)
       lines.append("%s :: (%s)" % (hs_name, ttypes))
       lines.append("%s = (%s)" % (hs_name, tvals))
     else:
@@ -253,7 +264,7 @@ def ConvertVariable(prefix, name, value, all_items):
       uniq_types = set(ttypes)
       if len(uniq_types) == 1:
         values = FormatListElems(all_items, pfx_name, value, tvals)
-        lines.append("-- | Converted from Python list or set %s" % fqn)
+        lines.append("-- | Converted from Python list or set @%s@" % fqn)
         lines.append("%s :: [%s]" % (hs_name, uniq_types.pop()))
         lines.append("%s = [%s]" % (hs_name, values))
       else:
@@ -263,7 +274,7 @@ def ConvertVariable(prefix, name, value, all_items):
   elif isinstance(value, RE_TYPE):
     tvs = HaskellTypeVal(value.pattern)
     assert tvs is not None
-    lines.append("-- | Converted from Python RE object %s" % fqn)
+    lines.append("-- | Converted from Python RE object @%s@" % fqn)
     lines.append("%s :: %s" % (hs_name, tvs[0]))
     lines.append("%s = %s" % (hs_name, tvs[1]))
   else:
@@ -289,12 +300,24 @@ def Convert(module, prefix):
   return "\n".join(lines)
 
 
+def ConvertMisc():
+  """Convert some extra computed-values to Haskell.
+
+  """
+  lines = [""]
+  lines.extend(ConvertVariable("opcodes", "OP_IDS",
+                               opcodes.OP_MAPPING.keys(), {}))
+  return "\n".join(lines)
+
+
 def main():
   print Convert(constants, "")
   print Convert(luxi, "luxi")
   print Convert(qlang, "qlang")
   print Convert(_autoconf, "autoconf")
   print Convert(errors, "errors")
+  print Convert(jstore, "jstore")
+  print ConvertMisc()
 
 
 if __name__ == "__main__":