def sxpr_file(self, fin): try: vals = sxp.parse(fin) except: raise ArgError('Coercion to sxpr failed') if len(vals) == 1: return vals[0] else: raise ArgError('Too many sxprs')
def parseCommandLine(argv): GOPTS.reset() args = GOPTS.parse(argv) if GOPTS.vals.help or GOPTS.vals.help_config: if GOPTS.vals.help_config: print GOPTS.val_usage() return (None, None) # Process remaining args as config variables. for arg in args: if '=' in arg: (var, val) = arg.strip().split('=', 1) GOPTS.setvar(var.strip(), val.strip()) if GOPTS.vals.config: try: config = sxp.parse(file(GOPTS.vals.config))[0] except IOError, ex: raise OptionError("Cannot read file %s: %s" % (config, ex[1]))
def set_config(self): """If the config file exists, read it. If not, ignore it. The config file is a sequence of sxp forms. """ self.config_path = os.getenv(self.config_var, self.config_default) if os.path.exists(self.config_path): try: fin = file(self.config_path, "rb") try: config = sxp.parse(fin) finally: fin.close() if config is None: config = ["xend-config"] else: config.insert(0, "xend-config") self.config = config except Exception, ex: self._logError("Reading config file %s: %s", self.config_path, str(ex)) raise
def set_config(self): """If the config file exists, read it. If not, ignore it. The config file is a sequence of sxp forms. """ self.config_path = os.getenv(self.config_var, self.config_default) if os.path.exists(self.config_path): try: fin = file(self.config_path, 'rb') try: config = sxp.parse(fin) finally: fin.close() if config is None: config = ['xend-config'] else: config.insert(0, 'xend-config') self.config = config except Exception, ex: self._logError('Reading config file %s: %s', self.config_path, str(ex)) raise
def main(argv): is_xml = False try: (opts, config) = parseCommandLine(argv) except StandardError, ex: err(str(ex)) if not opts: return if not opts.is_xml: if type(config) == str: try: config = sxp.parse(file(config))[0] except IOError, exn: raise OptionError("Cannot read file %s: %s" % (config, exn[1])) if serverType == SERVER_XEN_API: from xen.xm.xenapi_create import sxp2xml sxp2xml_inst = sxp2xml() doc = sxp2xml_inst.convert_sxp_to_xml(config, transient=True) if opts.vals.dryrun and not opts.is_xml: SXPPrettyPrint.prettyprint(config) if opts.vals.xmldryrun and serverType == SERVER_XEN_API: from xml.dom.ext import PrettyPrint as XMLPrettyPrint XMLPrettyPrint(doc)
def get_domain_uuid_by_sxp(self, path): try: sxp_obj = sxp.parse(open(path, 'r')) sxp_obj = sxp_obj[0] except IOError, e: raise XendConfigError("Unable to read file: %s" % path)