From fa19521b35915d6ec7555a8728a461cc79dc0d06 Mon Sep 17 00:00:00 2001 From: Jeremy Schulman Date: Mon, 30 Dec 2013 09:51:31 -0500 Subject: [PATCH] updates --- lib/jnpr/junos/factory/table.py | 38 ++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/jnpr/junos/factory/table.py b/lib/jnpr/junos/factory/table.py index 184caec71..b7e06a7d9 100644 --- a/lib/jnpr/junos/factory/table.py +++ b/lib/jnpr/junos/factory/table.py @@ -96,7 +96,7 @@ def _keyspec(self): def _clearkeys(self): self._key_list = [] - + ##### ------------------------------------------------------------------------- ##### PUBLIC METHODS ##### ------------------------------------------------------------------------- @@ -164,32 +164,46 @@ def get(self, *vargs, **kvargs): ## savexml - saves the table XML to a local file ## -------------------------------------------------------------------------- - def savexml(self, path, hostname=False, timestamp=False, tsfmt=_TSFMT ): + def savexml(self, path, hostname=False, timestamp=False, append=None): """ - save a copy of the table XML data to a local file + Save a copy of the table XML data to a local file. The name of the + output file (:path:) can include the name of the Device host, the + timestamp of this action, as well as any user-defined appended value. + These 'add-ons' will be added to the :path: value prior to the file + extension in the order (hostname,timestamp,append), separated by + underscore (_). + + For example, if both hostname=True and append='BAZ1', then when + :path: = '/var/tmp/foo.xml' and the Device.hostname is "srx123", the + final file-path will be "/var/tmp/foo_srx123_BAZ1.xml" :path: - output XML file + file-path to write the XML file on the local filesystem :hostname: if True, will append the hostname to the :path: :timestamp: - if True, will append the timestamp to the :path: - - :tsfmt: - allows you to override the timestamp format. the format is defined - by strftime() + if True, will append the timestamp to the :path: using the default + timestamp format + if the timestamp will use the value as the timestamp format as + defied by strftime() + + :append: + any value that you'd like appended to the :path: value preceeding the + filename extension. """ fname, fext = os.path.splitext(path) - if hostname is True: - fname += "_%s" % self.D.hostname + if hostname is True: fname += "_%s" % self.D.hostname - if timestamp is True: + if timestamp is not False: + tsfmt = _TSFMT if timestamp is True else timestamp tsfmt_val = datetime.fromtimestamp(time()).strftime(tsfmt) fname += "_%s" % tsfmt_val + if append is not None: fname += "_%s" % append + path = fname + fext return etree.ElementTree(self.xml).write(file(path,'w'))