#!/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
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
"""
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):
# 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)),
]
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):
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:
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:
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:
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__":