Exemplo n.º 1
0
    def __init__(self,stfile):
        sio = StringIO()
        writer = MarkupWriter(sio,indent=u'yes',omitXmlDeclaration=u'yes')
        writer.startDocument()
        writer.startElement(u'statfile')
        writer.simpleElement(u'filename',content=u(stfile.filename))

        writer.startElement(u'properties')
        for propertyIndex,record in enumerate(stfile.records):
            writer.startElement(u'property')
            writer.attribute(u'index',u(propertyIndex))
            writer.simpleElement(u'name',content=u(record.property))
            writer.simpleElement(u'volume',content=u(record.volume))
            writer.simpleElement(u'pvalue',content=u(record.pvalue))
            writer.simpleElement(u'tvalue',content=u(record.tvalue))
            writer.simpleElement(u'dof',content=u(record.dof))
            writer.simpleElement(u'mean',content=u(record.mean))
            writer.simpleElement(u'stdev',content=u(record.stdev))
            writer.simpleElement(u'sumOfRanks',content=u(record.sumOfRanks))
            writer.simpleElement(u'numSmall',content=u(record.numSmall))
            writer.simpleElement(u'numBig',content=u(record.numBig))
            writer.endElement(u'property')
        writer.endElement(u'properties')

        writer.startElement(u'sites')
        for siteIndex in range(stfile.numSites):
            writer.startElement(u'site')
            writer.attribute(u'index',u(siteIndex))
            writer.attribute(u'label',u'site')
            for propertyIndex,record in enumerate(stfile.records):
                writer.startElement(u'value')
                writer.attribute(u'index',u(propertyIndex))
                writer.text(u(record.sites[siteIndex]))
                writer.endElement(u'value')
            writer.endElement(u'site')
        for nonSiteIndex in range(stfile.numNonSites):
            writer.startElement(u'site')
            writer.attribute(u'index',u(nonSiteIndex))
            writer.attribute(u'label',u'nonsite')
            for propertyIndex,record in enumerate(stfile.records):
                writer.startElement(u'value')
                writer.attribute(u'index',u(propertyIndex))
                writer.text(u(record.nonsites[nonSiteIndex]))
                writer.endElement(u'value')
            writer.endElement(u'site')
        writer.endElement(u'sites')

        writer.endElement(u'statfile')
        writer.endDocument()
        self.data = sio.getvalue()
Exemplo n.º 2
0
def bb_enable_iface_with_config(devcf):
    """
    Configuration of eth interfaces via system-tools-backends.
        
    * Example of static interface configuration via system-tools-backends

    Function call:
    (sysret, xmlcfg, xmlcfgout) = bb_enable_iface_with_config('eth1', 'none', '10.0.0.6',
                                                              '10.255.255.255', '10.0.0.1',
                                                              '255.255.255.0', '10.0.0.0')
    xml passed to system-tools-backends:
    
    <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
    <interface type='ethernet'>
      <configuration>
        <address>10.0.0.8</address>
        <auto>1</auto>
        <bootproto>none</bootproto>
        <broadcast>10.0.0.255</broadcast>
        <file>eth1</file>
        <gateway>10.0.0.1</gateway>
        <netmask>255.255.255.0</netmask>
        <network>10.0.0.0</network>
      </configuration>
      <dev>eth1</dev>
      <enabled>1</enabled>
    </interface>
    <!-- GST: end of request -->
    
    * Example of dhcp interface configuration via system-tools-backend

    Function call:
    (sysret, xmlcfg, xmlcfgout) = bb_enable_iface_with_config('eth1', 'dhcp')

    xml passed to system-tools-backends:
    
    <interface type='ethernet'>
       <configuration>
         <auto>1</auto>
         <bootproto>dhcp</bootproto>
         <file>eth0</file>
       </configuration>
       <dev>eth0</dev>
       <enabled>1</enabled>
    </interface>
    <!-- GST: end of request -->
    
    """

    netcfg_xmlfile = tempfile.NamedTemporaryFile()
    netcfgout_xmlfile = tempfile.NamedTemporaryFile()
    writer = MarkupWriter(netcfg_xmlfile, encoding='UTF-8', indent=u"yes", 
                          standalone="yes")
    writer.startDocument()
    writer.startElement(u'interface')
    writer.attribute(u'type', u'ethernet')
    writer.startElement(u'configuration')
    if devcf.param['dhcp'] == 'True':
        conf = { 'auto' : '1', \
               'bootproto' : 'dhcp', \
               'file': devcf.param['eth_to_conf'] }
    else:
        broadcast = ipBroadcast(devcf.param['ip_computer'],
                                devcf.param['mask_computer'])
        conf = { 'address' : devcf.param['ip_computer'], \
                 'auto' : '1', \
                 'bootproto' :'none', \
                 'broadcast' : broadcast, \
                 'file': devcf.param['eth_to_conf'], \
                 'gateway' : devcf.param['gw_computer'], \
                 'netmask' : devcf.param['mask_computer'], \
                 'network' : devcf.param['net_computer']}
    for confparam in conf.keys():
        writer.startElement(unicode(confparam))
        writer.text(unicode(conf[confparam]))
        writer.endElement(unicode(confparam))
    writer.endElement(u'configuration')
    writer.startElement(u'dev')
    writer.text(unicode(devcf.param['eth_to_conf']))
    writer.endElement(u'dev')
    writer.startElement(u'enabled')
    writer.text(u'1')
    writer.endElement(u'enable')
    writer.endElement(u'interface')
    writer.text(u'\n')
    writer.comment(u' GST: end of request ')
    writer.endDocument()
    netcfg_xmlfile.flush()

    xmlcfg = open(netcfg_xmlfile.name).read( )
    net_cfg_cmd = "cat " + netcfg_xmlfile.name + " | /usr/share/setup-tool-backends/scripts/network-conf -d enable_iface_with_config | grep -vE \"^$\" > " + netcfgout_xmlfile.name
    os.system(net_cfg_cmd)
    xmlcfgout = open(netcfgout_xmlfile.name).read( )
    reader = PyExpat.Reader( )
    dom = reader.fromStream(open(netcfgout_xmlfile.name, "r"))
    successCfg = Evaluate("success/text( )",
                         dom.documentElement)[0].nodeValue
    if successCfg == '0':
        sysret = BBERRCFGDEV # Error configuration dev
    else:
        sysret = BBNOERR # Ok
    return (sysret, xmlcfg, xmlcfgout)