Esempio n. 1
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