X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOME_XmlHandler.cxx;h=2cbee860ba38cfeae5209799354f9e59bb068b15;hb=90886bc9d3ab3a3204e8a9fbf9f414a493b65856;hp=a2d0d05fb594af53212e00ae84a30aca98146092;hpb=2897c5eb38f6722bfdd2e09b8d0d41781925a360;p=tools%2Finstall.git diff --git a/src/SALOME_XmlHandler.cxx b/src/SALOME_XmlHandler.cxx index a2d0d05..2cbee86 100644 --- a/src/SALOME_XmlHandler.cxx +++ b/src/SALOME_XmlHandler.cxx @@ -1,19 +1,89 @@ // File : SALOME_XmlHandler.cxx // Created : Thu Dec 18 12:01:00 2002 -// Author : Vadim SANDLER -// Project : PAL/SALOME -// Module : InstallWizard -// Copyright : 2004 CEA -// $Header$ +// Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com) +// Project : SALOME +// Module : Installation Wizard +// Copyright : 2002-2014 CEA + +#include "globals.h" #include "SALOME_XmlHandler.hxx" #include "SALOME_ProductsView.hxx" #include "SALOME_InstallWizard.hxx" #include +#include +#include +#include +#include + +// ================================================================ +/*! + * ::isBoolAttributeSet [ static ] + * Returns true if the attribute stores boolean value and + * corresponds to True value + */ +// ================================================================ +static bool isBoolAttributeSet( const QString& attr ) { + return ( attr.lower() == "true" || + attr.lower() == "yes" || + attr.lower() == "ok" || + ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) ); +} +// ================================================================ +/*! + * ::environmentVariable [ static ] + * Seraches for the environment variable and returns it's + * position on the given string + */ +// ================================================================ +QString environmentVariable( const QString& str, int& start, int& len ) { + QString varName = QString::null; + len = 0; + + // Environment variable can be given in the form: + // - ${VARIABLE} or + // - $(VARIABLE) or + // - $VARIABLE or + // - %VARIABLE% + // The first symbol should be the letter. + QRegExp rx( "\\$\\{([a-zA-Z]+[a-zA-Z0-9_]*)\\}|\\$\\(([a-zA-Z]+[a-zA-Z0-9_]*)\\)|\\$([a-zA-Z]+[a-zA-Z0-9_]*)|\\%([a-zA-Z]+[a-zA-Z0-9_]*)\\%" ); + + int pos = rx.search( str, start ); + if ( pos != -1 ) + { + start = pos; + len = rx.matchedLength(); + QStringList caps = rx.capturedTexts(); + for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ ) + varName = *caps.at( i ); + } + return varName; +} +// ================================================================ +/*! + * ::substituteVars [ static ] + * Substitutes environment variables in the given string + * by their values + */ +// ================================================================ +static QString substituteVars( const QString& str ) { + QString res = str; + + int start( 0 ), len( 0 ); + while ( true ) { + QString envName = environmentVariable( res, start, len ); + if ( envName.isNull() ) + break; + + QString newStr = QString::null; + if ( ::getenv( envName ) ) + newStr = QString( ::getenv( envName ) ); + + res.replace( start, len, newStr ); + } -bool isBoolAttributeSet( const QString& attr ) { - return ( attr == "true" || attr == "yes" || attr == "ok" || ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) ); + return res; } // ================================================================ @@ -23,22 +93,23 @@ bool isBoolAttributeSet( const QString& attr ) { */ // ================================================================ StructureParser::StructureParser( SALOME_InstallWizard* wizard ) - : QXmlDefaultHandler(), - myWizard( wizard ), - myTree( 0 ), + : myWizard( wizard ), + myModules( 0 ), + myPrereqs( 0 ), myTargetDir( 0 ), myTempDir( 0 ) { } // ================================================================ /*! - * StructureParser::setProductsList + * StructureParser::setProductsLists * Sets products list view */ // ================================================================ -void StructureParser::setProductsList( ProductsView* tree ) +void StructureParser::setProductsLists( ProductsView* mtree, ProductsView* ptree ) { - myTree = tree; + myModules = mtree; + myPrereqs = ptree; } // ================================================================ /*! @@ -48,7 +119,10 @@ void StructureParser::setProductsList( ProductsView* tree ) // ================================================================ void StructureParser::setTargetDir( QLineEdit* dir ) { + QString home = QDir::homeDirPath(); myTargetDir = dir; + if ( myTargetDir && !home.isEmpty() ) + myTargetDir->setText( home + QDir::separator() + "salome" ); } // ================================================================ /*! @@ -59,100 +133,217 @@ void StructureParser::setTargetDir( QLineEdit* dir ) void StructureParser::setTempDir( QLineEdit* dir ) { myTempDir = dir; + if ( myTempDir ) + myTempDir->setText( "/tmp" ); } // ================================================================ /*! - * StructureParser::startElement - * Begins parsing of the xml dom-element - */ -// ================================================================ -bool StructureParser::startElement( const QString& /*namespaceURI*/, - const QString& /*localName*/, - const QString& qName, - const QXmlAttributes& attributes) + * StructureParser::getConfigInfo + * Parse 'config' part of the XML file + */ +// ================================================================ +void StructureParser::getConfigInfo(const QDomElement &theElem) { -#ifdef DEBUG - cout << qName << endl; - cout << attributes.length() << endl; -#endif - QCheckListItem* element; - if (( qName == "config" ) && ( attributes.length() > 0 ) ) { - QString myVersion, myCaption, myCopyright, myLicense, myOS; - if ( attributes.value( "version" ) ) { - myVersion = attributes.value( "version" ).stripWhiteSpace(); + QString myVersion, myCaption, myCopyright, myLicense, myPlatforms, myOptLibs; + if ( theElem.attribute( "version" ) ) { + myVersion = theElem.attribute( "version" ).stripWhiteSpace(); if ( myWizard && !myVersion.isEmpty() ) myWizard->setVersion( myVersion ); } - if ( attributes.value( "caption" ) ) { - myCaption = attributes.value( "caption" ).arg( myVersion ).stripWhiteSpace(); + if ( theElem.attribute( "caption" ) ) { + myCaption = theElem.attribute( "caption" ).arg( myVersion ).stripWhiteSpace(); if ( myWizard && !myCaption.isEmpty() ) myWizard->setCaption( myCaption ); } - if ( attributes.value( "copyright" ) ) { - myCopyright = attributes.value( "copyright" ).stripWhiteSpace(); + if ( theElem.attribute( "copyright" ) ) { + myCopyright = theElem.attribute( "copyright" ).stripWhiteSpace(); if ( myWizard && !myCopyright.isEmpty() ) myWizard->setCopyright( myCopyright ); } - if ( attributes.value( "license" ) ) { - myLicense = attributes.value( "license" ).stripWhiteSpace(); + if ( theElem.attribute( "license" ) ) { + myLicense = theElem.attribute( "license" ).stripWhiteSpace(); if ( myWizard && !myLicense.isEmpty() ) myWizard->setLicense( myLicense ); } - if ( attributes.value( "os" ) ) { - myOS = attributes.value( "os" ).stripWhiteSpace(); - if ( myWizard && !myOS.isEmpty() ) - myWizard->setOS( myOS ); + if ( theElem.attribute( "platforms" ) ) { +// myPlatforms = theElem.attribute( "platforms" ).stripWhiteSpace(); +// if ( myWizard && !myPlatforms.isEmpty() ) +// myWizard->setPlatforms( myPlatforms ); + } + if ( theElem.attribute( "targetdir" ) ) { + if ( myTargetDir ) + myTargetDir->setText( substituteVars( theElem.attribute( "targetdir" ) ) ); + } + if ( theElem.attribute( "tempdir" ) ) { + if ( myTempDir ) + myTempDir->setText( substituteVars( theElem.attribute( "tempdir" ) ) ); + } + if ( theElem.attribute( "optionallibs" ) ) { + myOptLibs = theElem.attribute( "optionallibs" ).stripWhiteSpace(); + if ( myWizard && !myOptLibs.isEmpty() ) + myWizard->setOptionalLibs( myOptLibs ); + } +} +// ================================================================ +/*! + * StructureParser::getButtonsInfo + * Parse 'buttons' part of the XML file + */ +// ================================================================ +void StructureParser::getButtonsInfo(const QDomNode &theNode) +{ + QString aLabel, aTootip, aScript; + for( QDomNode node = theNode.firstChild(); !node.isNull(); node = node.nextSibling() ) { + if ( !node.isElement() ) + continue; + QDomElement elem = node.toElement(); + if ( isBoolAttributeSet( elem.attribute( "disable" ) ) ) + continue; + aLabel = ""; aTootip = ""; aScript = ""; + if ( elem.attribute( "label" ) ) + aLabel = elem.attribute( "label" ).stripWhiteSpace(); + if ( elem.attribute( "tooltip" ) ) + aTootip = elem.attribute( "tooltip" ).stripWhiteSpace(); + if ( elem.attribute( "script" ) ) + aScript = elem.attribute( "script" ).stripWhiteSpace(); + if ( !aLabel.isEmpty() ) { + if ( node == theNode.firstChild() ) + myWizard->addFinishButton( aLabel, aTootip, aScript, true ); + else + myWizard->addFinishButton( aLabel, aTootip, aScript ); } - } - else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) { - if ( isBoolAttributeSet( attributes.value( "disable" ) ) ) - return true; - - QString install = attributes.value( "install" ); - QStringList supported = QStringList::split( ",", attributes.value( "supported" ) ); - QString script = attributes.value( "script" ); - QStringList deps = QStringList(); - if ( attributes.value( "dependancies" ) != "" ) - deps = QStringList::split( ",", attributes.value( "dependancies" ), false ); - element = myTree->addItem( attributes.value( "name" ), attributes.value( "version" ), install, supported, script ); - QStringList diskspace = QStringList::split(",",attributes.value( "installdiskspace" ) ); - QString descr = QString::null; - if ( attributes.value( "description" ) != "" ) - descr = attributes.value( "description" ).stripWhiteSpace(); - bool pickUp = isBoolAttributeSet( attributes.value( "pickupenv" ) ); - myWizard->setDependancies( element, - Dependancies( attributes.value( "name" ), - deps, - ( diskspace.count() > 0 ? diskspace[ 0 ].toInt() : 0 ), - ( diskspace.count() > 1 ? diskspace[1].toInt() : ( diskspace.count() > 0 ? diskspace[0].toInt() : 0 ) ), - attributes.value( "temporarydiskspace" ).toInt(), - install, - descr, - pickUp ) ); } - else if (( qName == "path" ) && ( attributes.length() > 0 ) && myWizard ) { - if ( myTargetDir ) - myTargetDir->setText( attributes.value( "targetdir" ) ); +} +// ================================================================ +/*! + * StructureParser::getProductsInfo + * Parse 'products' part of the XML file + */ +// ================================================================ +void StructureParser::getProductsInfo( const QDomNode &theNode ) +{ + MapDependencies mapDeps; + QCheckListItem* element; + + QDomNode docNode = theNode.parentNode(); + getDependenciesInfo( docNode, mapDeps ); - if ( myTempDir ) { - if ( attributes.value( "tempdir" ) == "" ) - myTempDir->setText( "/tmp" ); + for( QDomNode prodNode = theNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) { + if ( !prodNode.isElement() ) + continue; + for( QDomNode instNode = prodNode.firstChild(); !instNode.isNull(); instNode = instNode.nextSibling() ) { + if ( !instNode.isElement() ) + continue; + QDomElement instElem = instNode.toElement(); + if ( instElem.attribute( "os" ) != myWizard->getPlatform() && instElem.attribute( "os" ) != "all" ) + continue; + if ( isBoolAttributeSet( instElem.attribute( "disable" ) ) ) + break; // current product is skipped + QDomElement prodElem = prodNode.toElement(); + + QStringList diskspace = QStringList::split( ",", instElem.attribute( "installdiskspace" ) ); + long binreq = diskspace[ 0 ].toInt(); + long srcreq = diskspace[ 1 ].toInt(); + long cmplreq = diskspace[ 2 ].toInt(); + + QString name = prodElem.attribute( "name" ).stripWhiteSpace(); + QString type = prodElem.attribute( "type" ).stripWhiteSpace().lower(); + BoolTristate woGuiMode = NotDefined; + bool pickUp = isBoolAttributeSet( instElem.attribute( "pickupenv" ) ); + QString script = instElem.attribute( "script" ); + QStringList typesList = QStringList::split( ",", type ); + if ( typesList.find( "component" ) != typesList.end() ) { + QString woGuiAttr = instElem.attribute( "woguimode" ); + if ( !woGuiAttr.isNull() ) + woGuiMode = BoolTristate( isBoolAttributeSet( woGuiAttr ) ); + element = myModules->addItem( name, + "unknown", + script ); + } else - myTempDir->setText( attributes.value( "tempdir" ) ); - } + element = myPrereqs->addItem( name, + "unknown", + script ); + QString descr = QString::null; + if ( prodElem.attribute( "description" ) != "" ) + descr = prodElem.attribute( "description" ).stripWhiteSpace(); + myWizard->setDependancies + ( element, + Dependancies( name, + mapDeps[ name ], + binreq, + srcreq, + cmplreq, + instElem.attribute( "temporarydiskspace" ).toInt(), + instElem.attribute( "version" ), + descr, + type, + pickUp, + woGuiMode ) ); + } } - return true; } // ================================================================ /*! - * StructureParser::endElement - * Finishes parsing of the xml dom-element + * StructureParser::getDependencies + * Parse 'dependencies' part of the XML file */ // ================================================================ -bool StructureParser::endElement( const QString&, - const QString&, - const QString& ) +void StructureParser::getDependenciesInfo( QDomNode &theNode, MapDependencies &theDepends ) { - return true; + QDomNode depsNode = theNode.namedItem( "dependencies" ); + QStringList depsList = QStringList(); + for( QDomNode prodNode = depsNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) { + if ( !prodNode.isElement() ) + continue; + QDomElement prodElem = prodNode.toElement(); + QString prodName = prodElem.attribute( "name" ).stripWhiteSpace(); + if ( theDepends.contains( prodName ) ) + continue; + depsList.clear(); + for ( QDomNode depNode = prodNode.firstChild(); !depNode.isNull(); depNode = depNode.nextSibling() ) { + if ( !depNode.isElement() ) + continue; + QDomElement depElem = depNode.toElement(); + QString depName = depElem.text(); + if ( depName.isEmpty() ) + continue; + if ( !depsList.contains( depName ) ) + depsList.append( depName ); + } + theDepends[ prodName ] = depsList; + } } +// ================================================================ +/*! + * StructureParser::readXmlFile + * Read XML configuration file for the current platform + */ +// ================================================================ +void StructureParser::readXmlFile(QString theFileName) +{ + QDomDocument doc( "xml_doc" ); + QFile file( theFileName ); + if ( !file.open( IO_ReadOnly ) ) + return; + if ( !doc.setContent( &file ) ) { + file.close(); + return; + } + file.close(); + + QDomElement docElem = doc.documentElement(); + for( QDomNode node = docElem.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QString nodeName = node.nodeName(); + if ( nodeName == "config" && node.isElement() ) { + getConfigInfo( node.toElement() ); + } + else if ( nodeName == "buttons" && node.hasChildNodes() && myModules && myWizard ) { + getButtonsInfo( node ); + } + else if ( nodeName == "products" && node.hasChildNodes() && myModules && myWizard ) { + getProductsInfo( node ); + } + } +}