Esempio n. 1
0
def loadConfiguration(pathUser, pathDefault, voName):

  #Initialise configuration AD	
  info.confAdVo = AdWrapper(1)

  if pathUser:

     # conf file has to be changed from default one
     if not os.path.isfile(pathUser):
        print "Fatal Error: config file not found:\n" + os.path.abspath(pathUser)
        sys.exit (1)
     else:
     	# Create an AD Wrapper for the configuration file
        ad = AdWrapper(1)

        if ad.fromFile(pathUser):
           print "Fatal Error: Unable to parse config file:\n " + os.path.abspath(pathUser)
           sys.exit (1)

	# Dump warning message on deprecated attributes
	checkDeprecatedAttributes(ad, pathUser)

	# Set the Configuration AD	 
	mergeConfigAttributes(ad, info.confAdVo)  
	
	# Set the Configuration file name
        info.confFile = os.path.abspath(pathUser)

  if pathDefault:

     # conf file has to be changed from default one
     if not os.path.isfile(pathDefault):
        print "Fatal Error: config file not found:\n"+os.path.abspath(pathDefault)
        sys.exit (1)
     else:
     	# Create an AD Wrapper for the configuration file
        ad = AdWrapper(1)
        if ad.fromFile(pathDefault):
           print "Fatal Error: Unable to parse config file:\n " + os.path.abspath(pathDefault)
           sys.exit (1)

	# Dump warning message on deprecated attributes
	checkDeprecatedAttributes(ad, pathDefault)

	# Set the Configuration AD	 
	mergeConfigAttributes(ad, info.confAdVo)  
	
  # Override the VO if a valid one has been found
  if(voName):
    # Override in any case the voName
    info.confAdVo.overrideVo(voName);

    err, apiMsg = info.confAdVo.get_error()
    if err:
	    print err

  # Print the configuration file loaded if it's in debug mode
  if info.debug:
    # Print the configuration file loaded
    print "####\nConfiguration file loaded:", info.confFile, info.confAdVo.toLines()
Esempio n. 2
0
def parseVo(voSrc, configFile, voName, eMsg, override):

	# Check the source of the VO Name
	if (voSrc == VO_SOURCE_CERT_EXTENSION or voSrc == VO_SOURCE_VO_OPT) and not configFile :
		# Only vo is provided, generate file name:
		configFile = generateVoPath(voName)	

	# Retrieve the configuration directory
	confDir = os.path.dirname(configFile)

	# Look for configuration Vo file
	if not os.path.isfile(configFile):
	
		if voSrc == VO_SOURCE_CERT_EXTENSION or voSrc == VO_SOURCE_VO_OPT:	
			# In these cases vo file was autogenerated user config file may not be there
			return [0, voName, 0, configFile]

		else: 
			errMsg(eMsg,'UI_FILE_NOT_FOUND', configFile)
			return [1, "", 0, configFile]
	
	# Parsing Ad VO file
	ad = AdWrapper(1)
	if ad.fromFile(configFile):
		errMsg(eMsg , "UI_JDL_ADD_ERROR", "Unable to parse Vo conf file (not a valid classad):\n " + configFile )
		return [1, "", 0, configFile] 

		
	#The VirtualOrganisation Attribute must match with the specified voName
	virtualOrganisation = ad.getVirtualOrganisation();
		
	# Check if the Virtual Organisation is present inside the AD
	if virtualOrganisation:

		# Check if the VO name has been set
		if voName:
			#The VirtualOrganisation Attribute must match with the specified voName
			if virtualOrganisation.lower()!=voName.lower():
				if override == 1:
					virtualOrganisation = voName
				else:
					errMsg(eMsg,'UI_JDL_VO_MATCH', voName , val ,configFile)
					return [1, "", 0, configFile]
		# SUCCESS
		return [0, virtualOrganisation , ad, configFile ]
	else:
		errMsg(eMsg,'UI_JDL_ADD_ERROR', "Missing VirtualOrganisation attribute inside JDL Default Attributes section \"JdlDefaultAttributes\" of configuration file " + configFile )
		return [1, "", 0, configFile]
Esempio n. 3
0
def check_prefix():
  prefix = ""
  confPrefix=""
  found = 0
  env = ""
  #Those files are mandatory for ui-commandline:
  fileList    = ["glite_wmsui_cmd_var.conf", "glite_wmsui_cmd_err.conf" ]
  #Those files are used by the single Virtual Organisation:
  fileListVo = ["glite_wmsui.conf"]
#  pathList = ['/','/usr/local/etc' , '']

  uipath = ""
  try:
    uipath = os.environ['EMI_UI_CONF']
  except:
    uipath = ""

  pathList = ['/','/usr/local/etc' ,uipath,'']

  etcPath = "etc"
  for path in pathList:

     prefix = path
     if path:
       if path[0] == "$":
           #It's an environment path
           try:
              prefix = os.environ[ path[1:] ]
              env= path

           except:
              pass
     if not prefix:
        pass
     confPrefix = prefix + os.sep + etcPath
#     print "confPrefix=" + str(confPrefix) + "\n"
     #Look for UI configuration files:
     found = 1

#     print "found=" + str(found) + "\n"

     for file in fileList:

#	  print "file=" + str(confPrefix + os.sep + file) + "\n"

          if not os.path.isfile(confPrefix + os.sep + file):
             found = 0
             break
     if found ==1:
        break
  if not found:
      if env:
          errMsg = "Fatal Error: " + env + " environment found but one or more of the following files are missing:\n"
          for file in fileList:
             errMsg = errMsg + file +" "
      else:
          errMsg = "Fatal Error: Unable to find userinterface configuration files"
      print errMsg
      sys.exit(1)
  info.prefix= prefix
  """
  Read version value from 'glite_wmsui_cmd_err'
  """
  try:
  #if not version:
     f=open( confPrefix + os.sep +"glite_wmsui_cmd_err.conf"  ,'r' )
     line=f.readline().strip()
     while line:
       line=line.strip()
       try:
         tag , ver = line.split("=")
         if tag.strip()=="UI_VERSION":
            wmsui_utils.info.version = ver
            break
       except:
         pass
       line=f.readline()
     f.close()
     if wmsui_utils.info.version =="":
        raise AttributeError
  except:
     print "Fatal Error: Unable find Version attribute in Ui  configuration file: \n" + confPrefix + os.sep +"glite_wmsui_cmd_err.conf"
     sys.exit(1)
  ad = AdWrapper(1)
  info.confFile = confPrefix + os.sep +fileList[0]
  if not os.path.isfile (info.confFile ):
      errMsg = "Fatal Error: Unable to find UI  default configuration file:\n " + info.confFile
      print errMsg
      sys.exit(1)
  if ad.fromFile ( info.confFile ):
	err, apiMsg = ad.get_error()
	if err:
		errMsg = "Fatal Error: Unable to parse UI default configuration file:\n " + info.confFile+".\n" + apiMsg
		print errMsg
		sys.exit(1)
  info.confAd = ad
  return prefix