From 05a16ff3dd14df0f2f47c799912d7a55d83e8dee Mon Sep 17 00:00:00 2001 From: Richard Kreuter Date: Thu, 8 Apr 2010 10:20:26 -0400 Subject: [PATCH] Implement subset of PEP 3101 so makedist.py will run on Python<2.6. --- buildscripts/makedist.py | 75 ++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/buildscripts/makedist.py b/buildscripts/makedist.py index cfdcb58b752..0b61f952c38 100755 --- a/buildscripts/makedist.py +++ b/buildscripts/makedist.py @@ -54,6 +54,7 @@ import socket import time import os.path import tempfile +import string # For the moment, we don't handle any of the errors we raise, so it # suffices to have a simple subclass of Exception that just @@ -638,25 +639,63 @@ class ScriptFile(object): self.distro_version = configurator.default("distro_version") self.distro_arch = configurator.default("distro_arch") + def bogoformat(self, fmt, **kwargs): + r = '' + i = 0 + while True: + c = fmt[i] + if c in '{}': + i+=1 + c2=fmt[i] + if c2 == c: + r+=c + else: + j=i + while True: + p=fmt[j:].find('}') + if p == -1: + raise Exception("malformed format string starting at %d: no closing brace" % i) + else: + j+=p + if len(fmt) > (j+1) and fmt[j+1]=='}': + j+=2 + else: + break + key = fmt[i:j] + r+=kwargs[key] + i=j + else: + r+=c + i+=1 + if i==len(fmt): + return r + + def fmt(self, formatter, **kwargs): + try: + return string.Formatter.format(formatter, kwargs) + finally: + return self.bogoformat(formatter, **kwargs) + def genscript(self): - return self.formatter.format(mongo_version=self.mongo_version, - distro_name=self.distro_name, - distro_version=self.distro_version, - distro_arch=self.distro_arch, - pkg_prereq_str=" ".join(self.pkg_prereqs), - pkg_name=self.pkg_name, - pkg_name_suffix=self.pkg_name_suffix, - pkg_version=self.pkg_version, - pkg_product_dir=self.pkg_product_dir, - # KLUDGE: rpm specs and deb - # control files use - # comma-separated conflicts, - # but there's no reason to - # suppose this works elsewhere - pkg_name_conflicts = ", ".join([self.pkg_name+conflict for conflict in self.pkg_name_conflicts]), - mongo_arch=self.mongo_arch, - mongo_pub_version=self.mongo_pub_version -) + return self.fmt(self.formatter, + mongo_version=self.mongo_version, + distro_name=self.distro_name, + distro_version=self.distro_version, + distro_arch=self.distro_arch, + pkg_prereq_str=" ".join(self.pkg_prereqs), + pkg_name=self.pkg_name, + pkg_name_suffix=self.pkg_name_suffix, + pkg_version=self.pkg_version, + pkg_product_dir=self.pkg_product_dir, + # KLUDGE: rpm specs and deb + # control files use + # comma-separated conflicts, + # but there's no reason to + # suppose this works elsewhere + pkg_name_conflicts = ", ".join([self.pkg_name+conflict for conflict in self.pkg_name_conflicts]), + mongo_arch=self.mongo_arch, + mongo_pub_version=self.mongo_pub_version + ) def __enter__(self): self.localscript=None