On Wed, Sep 12, 2012 at 11:52:09AM -0700, Ben Pfaff wrote: > I agree about raising an error if both are provided. > > There doesn't seem to be an issue with reading the file earlier. It > won't bother any in-tree users anyhow.
Schema file isn't such large in practice. for example, The size of vswitch.ovsschema is 16988 bytes. Here is the updated one. >From b26ede3940487d631ed1f2fff296e2bf0120e918 Mon Sep 17 00:00:00 2001 Message-Id: <b26ede3940487d631ed1f2fff296e2bf0120e918.1347502936.git.yamah...@valinux.co.jp> In-Reply-To: <[email protected]> References: <[email protected]> From: Isaku Yamahata <[email protected]> Date: Wed, 12 Sep 2012 14:35:11 +0900 Subject: [PATCH] python/ovs/db/idl: make SchemaHelper accept schema in json form This is needed when using schema that was retrieved from ovsdb by get_schema method. Signed-off-by: Isaku Yamahata <[email protected]> --- Changes v1 -> v2: - raise ValueError when both location and schema_json are specified - doc string --- python/ovs/db/idl.py | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-) diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 5b06d91..5330cea 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -1198,13 +1198,22 @@ class SchemaHelper(object): The location on disk of the schema used may be found in the 'schema_location' variable.""" - def __init__(self, location=None): - """Creates a new Schema object.""" + def __init__(self, location=None, schema_json=None): + """Creates a new Schema object. - if location is None: - location = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR + 'location' file path to ovs schema. None means default location + 'schema_json' schema in json preresentation in memory + """ + + if location and schema_json: + raise ValueError("both location and schema_json can't be " + "specified. it's ambiguous.") + if schema_json is None: + if location is None: + location = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR + schema_json = ovs.json.from_file(location) - self.schema_location = location + self.schema_json = schema_json self._tables = {} self._all = False @@ -1242,8 +1251,8 @@ class SchemaHelper(object): object based on columns registered using the register_columns() function.""" - schema = ovs.db.schema.DbSchema.from_json( - ovs.json.from_file(self.schema_location)) + schema = ovs.db.schema.DbSchema.from_json(self.schema_json) + self.schema_json = None if not self._all: schema_tables = {} -- 1.7.1.1 -- yamahata _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
