On Fri, 2011-05-27 at 09:45 -0400, Chris Lalancette wrote:
On 05/27/11 - 10:06:52AM, Mark McLoughlin wrote:
> Avoids:
>
> File "image_factory/imagefactory/Template.py", line 104, in __init__
> elif(template_string_type == "PATH"):
> UnboundLocalError: local variable 'template_string_type' referenced before
assignment
> ---
> imagefactory/Template.py | 11 +++++++----
> 1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/imagefactory/Template.py b/imagefactory/Template.py
> index 260db7a..61a9a4b 100644
> --- a/imagefactory/Template.py
> +++ b/imagefactory/Template.py
> @@ -81,6 +81,7 @@ class Template(object):
> self.url = None
> self.xml = None
>
> + path = None
> if(template):
> template_string = str(template)
> template_string_type = self.__template_string_type(template_string)
> @@ -90,6 +91,8 @@ class Template(object):
> url = template_string
> elif(template_string_type == "XML"):
> xml = template_string
> + elif(template_string_type == "PATH"):
> + path = template_string
>
> if(uuid):
> uuid_string = uuid
> @@ -101,16 +104,16 @@ class Template(object):
> self.identifier, self.xml = self.__fetch_template_with_url(url)
> elif(xml):
> self.xml = xml
> - elif(template_string_type == "PATH"):
> - template_file = open(template_string, "r")
> + elif(path):
> + template_file = open(path, "r")
> file_content = template_file.read()
> template_file.close()
> if(self.__string_is_xml_template(file_content)):
> self.xml = file_content
> else:
> - raise ValueError("File %s does not contain properly formatted
template xml:\n%s" % (template_string, self.__abbreviated_template(file_content)))
> + raise ValueError("File %s does not contain properly formatted
template xml:\n%s" % (path_string, self.__abbreviated_template(file_content)))
Looks OK except for the above line. I don't see path_string defined anywhere
in the old code or this patch. Did I miss something?
Good catch, thanks - it should just be path
Cheers,
Mark.