FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 12-13-2007, 01:24 AM
David Lutterkort
 
Default Store the image filename in the Image class

# HG changeset patch
# User David Lutterkort <dlutter@redhat.com>
# Date 1197512462 28800
# Node ID eb8ba74062f4d4f1fcf13578860d049d3e6e4611
# Parent 2f713d54e92e7699c43ac828ab4bab326275edd2
Store the image filename in the Image class

diff -r 2f713d54e92e -r eb8ba74062f4 virt-image
--- a/virt-image Wed Dec 12 18:21:02 2007 -0800
+++ b/virt-image Wed Dec 12 18:21:02 2007 -0800
@@ -147,17 +147,6 @@ def parse_args():

return options

-def parse_image_xml(fname):
- if fname is None:
- print >> sys.stderr, _("Must provide the location of an image XML file with --image")
- sys.exit(1)
- if not os.access(fname, os.R_OK):
- print >> sys.stderr, _("Can not read %s") % fname
- file = open(fname, "r")
- xml = file.read()
- file.close()
- return virtinst.ImageParser.parse(xml, os.path.dirname(fname))
-
def main():
options = parse_args()

@@ -166,7 +155,7 @@ def main():
conn = cli.getConnection(options.connect)
type = None

- image = parse_image_xml(options.image)
+ image = virtinst.ImageParser.parse_file(options.image)
capabilities = virtinst.CapabilitiesParser.parse(conn.getCapabili ties())

if options.boot is not None:
diff -r 2f713d54e92e -r eb8ba74062f4 virtinst/ImageParser.py
--- a/virtinst/ImageParser.py Wed Dec 12 18:21:02 2007 -0800
+++ b/virtinst/ImageParser.py Wed Dec 12 18:21:02 2007 -0800
@@ -30,10 +30,17 @@ class ParserException(Exception):

class Image:
"""The toplevel object representing a VM image"""
- def __init__(self, node = None, base = "."):
+ def __init__(self, node = None, base = None, filename = None):
self.storage = {}
self.domain = None
- self.base = base
+ self.filename = os.path.abspath(filename)
+ if base is None:
+ if filename is not None:
+ self.base = os.path.dirname(filename)
+ else:
+ self.base ="."
+ else:
+ self.base = base
self.name = None
self.label = None
self.descr = None
@@ -217,7 +224,7 @@ def xpathString(node, path, default = No
result = default
return result

-def parse(xml, base):
+def parse(xml, filename):
"""Parse the XML description of a VM image into a data structure. Returns
an object of class Image. BASE should be the directory where the disk
image files for this image can be found"""
@@ -245,10 +252,15 @@ def parse(xml, base):
if root.name != "image":
raise ParserException(_("Root element is not 'image'"))

- image = Image(root)
- image.base = base
+ image = Image(root, filename = filename)
finally:
doc.freeDoc()

return image

+def parse_file(filename):
+ file = open(filename, "r")
+ xml = file.read()
+ file.close()
+ return parse(xml, filename = filename)
+

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 02:52 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org