On Tue, May 24, 2011 at 10:34:55AM +0200, Iustin Pop wrote:
> On Thu, May 19, 2011 at 06:44:36PM +0100, Michael Hanselmann wrote:
> > Am 19. Mai 2011 17:56 schrieb Iustin Pop <[email protected]>:
> > > --- a/Makefile.am
> > > +++ b/Makefile.am
> > > +htools/Ganeti/Constants.hs: htools/Ganeti/Constants.hs.in \
> > > +       lib/constants.py lib/_autoconf.py $(CONVERT_CONSTANTS)
> > > +       set -e; \
> > > +       cat $< > $@; \
> > > +       $(CONVERT_CONSTANTS) >> $@
> > 
> > Can you change this to “{ cat $<; $(CONVERT…); } > $@” to match the
> > generation of .rst files?
> > 
> > > +
> > > +
> > >  lib/_autoconf.py: Makefile vcs-version | lib/.dir
> > 
> > One empty line only, please.
> > 
> > > --- /dev/null
> > > +++ b/autotools/convert-constants
> > > @@ -0,0 +1,78 @@
> > > +import re
> > > +
> > > +from ganeti import constants
> > > +
> > > +CONSTANT_RE = re.compile("^[A-Z][A-Z0-9_]+$")
> > > +
> > > +def nameRules(name):
> > 
> > Please change the names to match Ganeti's Python style (“NameRules”),
> > here and elsewhere.
> > 
> > > +  """Converts the upper-cased Python name to Haskell camelCase.
> > > +
> > > +  """
> > > +  elems = name.split("_")
> > > +  return elems[0].lower() + "".join(e.capitalize() for e in elems[1:])
> > > +
> > > +def stringValueRules(value):
> > 
> > Two empty lines at module level. Here and elsewhere.
> > 
> > > +  """Converts a string value from Python to Haskell.
> > > +
> > > +  """
> > > +  value = value.encode("string_escape") # escapes backslashes
> > > +  value = value.replace("\"", "\\\"")
> > > +  return value
> > > +
> > > +def convert():
> > > +  """Converts the constants to Haskell.
> > > +
> > > +  """
> > > +  lines = [""]
> > > +
> > > +  all_names = dir(constants)
> > > +
> > > +  for name in all_names:
> > > +    value = constants.__getattribute__(name)
> > 
> > Just wondering, why __getattribute__ instead of getattr()?
> > 
> > > +    hs_name = nameRules(name)
> > > +    if not CONSTANT_RE.match(name):
> > > +      lines.append("-- Skipped %s, not constant" % name)
> > > +    elif isinstance(value, basestring):
> > > +      lines.append("%s :: String" % hs_name)
> > > +      lines.append("%s = \"%s\"" % (hs_name, stringValueRules(value)))
> > > +    elif isinstance(value, int):
> > 
> > (int, long)?
> > 
> > > +      lines.append("%s :: Int" % hs_name)
> > > +      lines.append("%s = %d" % (hs_name, value))
> > > +    elif isinstance(value, float):
> > > +      lines.append("%s :: Double" % hs_name)
> > > +      lines.append("%s = %f" % (hs_name, value))
> > > +    else:
> > > +      lines.append("-- Skipped %s, %s not handled" % (name, type(value)))
> > > +    lines.append("")
> > > +
> > > +  return "\n".join(lines)
> 
> Interdiff:
> 
> 
> diff --git a/Makefile.am b/Makefile.am
> index eff6d9a..fa773c9 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -818,10 +818,7 @@ htools/Ganeti/HTools/Version.hs: 
> htools/Ganeti/HTools/Version.hs.in vcs-version
>  
>  htools/Ganeti/Constants.hs: htools/Ganeti/Constants.hs.in \
>       lib/constants.py lib/_autoconf.py $(CONVERT_CONSTANTS)
> -     set -e; \
> -     cat $< > $@; \
> -     $(CONVERT_CONSTANTS) >> $@
> -
> +     set -e; { cat $< ; $(CONVERT_CONSTANTS); } >> $@

Err, with an inter-interdiff :) :


diff --git a/Makefile.am b/Makefile.am
index fa773c9..4a4b9bf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -818,7 +818,7 @@ htools/Ganeti/HTools/Version.hs: 
htools/Ganeti/HTools/Version.hs.in vcs-version
 
 htools/Ganeti/Constants.hs: htools/Ganeti/Constants.hs.in \
        lib/constants.py lib/_autoconf.py $(CONVERT_CONSTANTS)
-       set -e; { cat $< ; $(CONVERT_CONSTANTS); } >> $@
+       set -e; { cat $< ; $(CONVERT_CONSTANTS); } > $@
 
 lib/_autoconf.py: Makefile vcs-version | lib/.dir
        set -e; \

thanks,
iustin

Reply via email to