Beispiel #1
0
 def __convert(self):
   gLogger.info("START of DATA CONVERTION")
   upc = UserProfileClient( "Default", getRPCClient )
   profile_name = USER_PROFILE_NAME + ".History"
   gLogger.info("1) Init of history var")
   result = upc.storeVar(profile_name,list())
   if not result["OK"]:
     gLogger.info("Initialization of history records has failed")
     return S_OK()
   gLogger.info("Done")
   gLogger.info("2) Get old data")
   result = self.__getData()
   if not result["result"]:
     gLogger.info("getData returns no result")
     return S_OK()
   gLogger.info("Done")
   gLogger.info("3) Is bookmark exists")
   data = result["result"]["layouts"]
   if not data.has_key("Bookmarks"):
     gLogger.info("No old Bookmarks found")    
     return S_OK()
   data = data["Bookmarks"]
   gLogger.info("Done")
   gLogger.info("4) Is layouts exists")
   if not data.has_key("layouts"):
     gLogger.info("No layouts to convert")
     return S_OK()
   layouts = data["layouts"]
   gLogger.info("Done")
   gLogger.info("5) Layouts is dict")
   try:
     layouts = dict(layouts)
   except:
     gLogger.info("Layouts '%s' is not dictionary" % layouts)
     return S_OK()
   gLogger.info("Done")
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   gLogger.info("6) Deleting old data")
   old = self.__delData("Bookmarks")
   gLogger.info("Should be empty: %s" % old)
   gLogger.info("Done")
   gLogger.info("8) Saving old data to new")
   for i in layouts:
     gLogger.info("Name: '%s'" % i)
     gLogger.info("Data: '%s'" % layouts[i])
     result = upc.storeVar(i,layouts[i])
     gLogger.info(result)
   if data.has_key("defaultLayout"):
     name = data["defaultLayout"]
     result = self.__setHistory(name)
     if not result["OK"]:
       gLogger.error(result["Message"])
   gLogger.info("GOOD END of DATA CONVERTION")
   return S_OK()
Beispiel #2
0
 def __getBookmarks(self,name=""):
   if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
     return {"success":"false","error":"The name \"" + name + "\" is reserved, operation failed"}
   upc = UserProfileClient( "Summary", getRPCClient )
   result = upc.retrieveVar( "Bookmarks" )
   gLogger.info("\033[0;31m UserProfile getBookmarks response: \033[0m",result)
   if result["OK"]:
     result = result["Value"]
     if name != "":
       result["defaultLayout"] = name
       save = upc.storeVar( "Bookmarks", result )
       gLogger.info("\033[0;31m saving new default layout \033[0m",name)
       if not save["OK"]:
         return {"success":"false","error":save["Message"]}
     elif name == "" and not result.has_key("defaultLayout"):
       result["defaultLayout"] = ""
     if result.has_key("layouts"):
       layouts = ""
       for i in result["layouts"]:
         layouts = layouts + str(i) + ";"
       result["layoutNames"] = layouts
     c.result = {"success":"true","result":result}
   else:
     if result['Message'].find("No data for") != -1:
       c.result = {"success":"true","result":{}}
     else:
       c.result = {"success":"false","error":result["Message"]}
   return c.result
Beispiel #3
0
 def __delBookmarks(self,name):
   if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
     return {"success":"false","error":"The name \"" + name + "\" is reserved, please choose another name. Operation failed"}
   upc = UserProfileClient( "Summary", getRPCClient )
   result = upc.retrieveVar( "Bookmarks" )
   if result["OK"]:
     data = result["Value"]
   else:
     data = {}
   gLogger.info("\033[0;31m data: \033[0m",data)
   if data.has_key("layouts"):
     if name in data["layouts"]:
       del data["layouts"][name]
     else:
       return {"success":"false","error":"Can't delete not existing layout: \"" + name + "\""}
   else:
     return {"success":"false","error":"Can't read existing layouts, operation failed"}
   if len(data["layouts"]) > 0:
     data["defaultLayout"] = data["layouts"].keys()[0]
   else:
     data["defaultLayout"] = ""
   gLogger.info("\033[0;31m data: \033[0m",data)
   result = upc.storeVar( "Bookmarks", data )
   gLogger.info("\033[0;31m result: \033[0m",result)
   if result["OK"]:
     return self.__getBookmarks()
   else:
     return {"success":"false","error":result["Message"]}
Beispiel #4
0
 def __delHistory(self,name=False):
   gLogger.info("__delHistory(%s) function" % name)
   upc = UserProfileClient( "Default", getRPCClient )
   profile_name = USER_PROFILE_NAME + ".History"
   gLogger.info("upc.retrieveVar(%s)" % profile_name)
   result = upc.retrieveVar(profile_name)
   gLogger.debug(result)
   if not result["OK"]:
     return S_ERROR( result["Message"] )
   data = result["Value"]
   try:
     data = list(data)
   except:
     return S_ERROR( "Failed to convert '%s' to list" % data )
   if name:
     if data.count(name) > 0:
       while data.count(name) > 0:
         data.remove(name)
   else:
     data = list()
   while len(data) > 50:
     data.popleft()
   gLogger.info("upc.storeVar(%s,%s)" % (profile_name,data))
   result = upc.storeVar(profile_name,data)
   gLogger.debug(result)
   if not result["OK"]:
     return S_ERROR( result["Message"] )
   return S_OK( result["Value"] )
Beispiel #5
0
 def __setHistory(self,name=False):
   gLogger.info("__setHistory(%s) function" % name)
   if not name:
     return S_ERROR( "Name of the layout to save in history is absent" )
   upc = UserProfileClient( "Default", getRPCClient )
   profile_name = USER_PROFILE_NAME + ".History"
   gLogger.info("upc.retrieveVar(%s)" % profile_name)
   result = upc.retrieveVar(profile_name)
   gLogger.debug(result)
   if not result["OK"]:
     result = dict()
     result["Value"] = dict()
   data = result["Value"]
   try:
     data = list(data)
   except:
     data = list()
   data.append(name)
   while len(data) > 50:
     data.popleft()
   gLogger.info("upc.storeVar(%s,%s)" % (profile_name,data))      
   result = upc.storeVar(profile_name,data)
   gLogger.debug(result)
   if not result["OK"]:
     return S_ERROR( result["Message"] )
   return S_OK( result["Value"] )
Beispiel #6
0
 def __getBookmarks(self, name=""):
     if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
         return {
             "success": "false",
             "error":
             "The name \"" + name + "\" is reserved, operation failed"
         }
     upc = UserProfileClient("Summary", getRPCClient)
     result = upc.retrieveVar("Bookmarks")
     gLogger.info("\033[0;31m UserProfile getBookmarks response: \033[0m",
                  result)
     if result["OK"]:
         result = result["Value"]
         if name != "":
             result["defaultLayout"] = name
             save = upc.storeVar("Bookmarks", result)
             gLogger.info("\033[0;31m saving new default layout \033[0m",
                          name)
             if not save["OK"]:
                 return {"success": "false", "error": save["Message"]}
         elif name == "" and not result.has_key("defaultLayout"):
             result["defaultLayout"] = ""
         if result.has_key("layouts"):
             layouts = ""
             for i in result["layouts"]:
                 layouts = layouts + str(i) + ";"
             result["layoutNames"] = layouts
         c.result = {"success": "true", "result": result}
     else:
         if result['Message'].find("No data for") != -1:
             c.result = {"success": "true", "result": {}}
         else:
             c.result = {"success": "false", "error": result["Message"]}
     return c.result
Beispiel #7
0
 def __setBookmarks(self,name):
   if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
     return {"success":"false","error":"The name \"" + name + "\" is reserved, operation failed"}
   if not request.params.has_key("columns") and len(request.params["columns"]) <= 0:
     return {"success":"false","error":"Parameter 'Columns' is absent"}
   if not request.params.has_key("refresh") and len(request.params["refresh"]) <= 0:
     return {"success":"false","error":"Parameter 'Refresh' is absent"}
   upc = UserProfileClient( "Summary", getRPCClient )
   result = upc.retrieveVar( "Bookmarks" )
   if result["OK"]:
     data = result["Value"]
   else:
     data = {}
   data["defaultLayout"] = name
   if not data.has_key("layouts"):
     data["layouts"] =  {}
   data["layouts"][name] = {}
   if request.params.has_key("plots") and len(request.params["plots"]) > 0:
     data["layouts"][name]["url"] = str(request.params["plots"])
   else:
     data["layouts"][name]["url"] = ""
   data["layouts"][name]["columns"] = str(request.params["columns"])
   data["layouts"][name]["refresh"] = str(request.params["refresh"])
   gLogger.info("\033[0;31m Data to save: \033[0m",data)
   result = upc.storeVar( "Bookmarks", data )
   gLogger.info("\033[0;31m UserProfile response: \033[0m",result)
   if result["OK"]:
     return self.__getBookmarks()
   else:
     return {"success":"false","error":result["Message"]}
Beispiel #8
0
 def __delAllBookmarks(self):
   upc = UserProfileClient( "Summary", getRPCClient )
   data = {}
   result = upc.storeVar( "Bookmarks", data )
   if result["OK"]:
     return self.__getBookmarks()
   else:
     return {"success":"false","error":result["Message"]}
Beispiel #9
0
 def __delAllBookmarks(self):
     upc = UserProfileClient("Summary", getRPCClient)
     data = {}
     result = upc.storeVar("Bookmarks", data)
     if result["OK"]:
         return self.__getBookmarks()
     else:
         return {"success": "false", "error": result["Message"]}
Beispiel #10
0
    def registerRequest(self, dn, email):
        """
    Save hash made of email address to a profile REG_PROFILE_NAME
    Return S_OK, S_ERROR
    """

        upc = UserProfileClient(REG_PROFILE_NAME, getRPCClient)
        return upc.storeVar(dn, email)
Beispiel #11
0
  def registerRequest( self , dn , email ):

    """
    Save hash made of email address to a profile REG_PROFILE_NAME
    Return S_OK, S_ERROR
    """

    upc = UserProfileClient( REG_PROFILE_NAME , getRPCClient )
    return upc.storeVar( dn , email )
 def __saveLayout(self):
     gLogger.info("Running saveLayout()")
     msg = "saveLayout() for %s@%s" % (getUsername(), getSelectedGroup())
     result = self.__params2string(SAVE_LAYOUT_ARGS)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     args = result["Value"]
     name = args["name"]
     user = args["user"]
     group = args["group"]
     permissions = args["permissions"]
     result = self.__parsePermissions(name, permissions)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     permissions = result["Value"]
     data = dict()
     for key, value in request.params.items():
         try:
             if len(value) > 0:
                 data[key] = str(value)
         except:
             pass
     if not len(data) > 0:
         err = "Data to store has zero length"
         gLogger.error("Result %s: %s" % (msg, err))
         return {"success": "false", "error": err}
     for i in LOAD_LAYOUT_ARGS:  # Add vital params to layout if they are absent
         if not data.has_key(i):
             data[i] = args[i]
     upc = UserProfileClient(USER_PROFILE_NAME, getRPCClient)
     result = upc.storeVar(name, data, permissions)
     gLogger.debug(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return {"success": "false", "error": result["Message"]}
     result = self.__setHistory(args, "Save")
     history = dict()
     if not result["OK"]:
         history["Save"] = result["Message"]
     else:
         history["Save"] = result["Value"]
     gLogger.info("Result %s: %s AND %s" % (msg, data, history))
     return {"success": "true", "result": data, "history": history}
Beispiel #13
0
 def __saveLayout( self ):
   gLogger.info( "Running saveLayout()" )
   msg = "saveLayout() for %s@%s" % ( getUsername() , getSelectedGroup() )
   result = self.__params2string( SAVE_LAYOUT_ARGS )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   args = result[ "Value" ]
   name = args[ "name" ]
   user = args[ "user" ]
   group = args[ "group" ]
   permissions = args[ "permissions" ]
   result = self.__parsePermissions( name , permissions )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   permissions = result[ "Value" ]
   data = dict()
   for key , value in request.params.items():
     try:
       if len( value ) > 0:
         data[ key ] = str( value )
     except:
       pass
   if not len( data ) > 0:
     err = "Data to store has zero length"
     gLogger.error( "Result %s: %s" % ( msg , err ) )      
     return { "success" : "false" , "error" : err }
   for i in LOAD_LAYOUT_ARGS : # Add vital params to layout if they are absent
     if not data.has_key( i ):
       data[ i ] = args[ i ]
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   result = upc.storeVar( name , data , permissions )
   gLogger.debug( result )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return { "success" : "false" , "error" : result[ "Message" ] }
   result = self.__setHistory( args , "Save" )
   history = dict()
   if not result[ "OK" ]:
     history[ "Save" ] = result[ "Message" ]
   else:
     history[ "Save" ] = result[ "Value" ]
   gLogger.info( "Result %s: %s AND %s" % ( msg , data , history ) )
   return { "success" : "true" , "result" : data , "history" : history }
Beispiel #14
0
 def __setBookmarks(self, name):
     if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
         return {
             "success": "false",
             "error":
             "The name \"" + name + "\" is reserved, operation failed"
         }
     if not request.params.has_key("columns") and len(
             request.params["columns"]) <= 0:
         return {
             "success": "false",
             "error": "Parameter 'Columns' is absent"
         }
     if not request.params.has_key("refresh") and len(
             request.params["refresh"]) <= 0:
         return {
             "success": "false",
             "error": "Parameter 'Refresh' is absent"
         }
     upc = UserProfileClient("Summary", getRPCClient)
     result = upc.retrieveVar("Bookmarks")
     if result["OK"]:
         data = result["Value"]
     else:
         data = {}
     data["defaultLayout"] = name
     if not data.has_key("layouts"):
         data["layouts"] = {}
     data["layouts"][name] = {}
     if request.params.has_key("plots") and len(
             request.params["plots"]) > 0:
         data["layouts"][name]["url"] = str(request.params["plots"])
     else:
         data["layouts"][name]["url"] = ""
     data["layouts"][name]["columns"] = str(request.params["columns"])
     data["layouts"][name]["refresh"] = str(request.params["refresh"])
     gLogger.info("\033[0;31m Data to save: \033[0m", data)
     result = upc.storeVar("Bookmarks", data)
     gLogger.info("\033[0;31m UserProfile response: \033[0m", result)
     if result["OK"]:
         return self.__getBookmarks()
     else:
         return {"success": "false", "error": result["Message"]}
Beispiel #15
0
 def __deleteHistory( self , name , state ):
   """
   Deleting item from Load and Save history list
   Return resulting list
   "name" is a string
   "state" can be either "Save" or "Load"
   """
   gLogger.info( "Running deleteHistory( %s )" % name )
   msg = "deleteHistory() for %s@%s" % ( getUsername() , getSelectedGroup() )
   opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
   history_length = gConfig.getOptions( opt , 5 )
   upc = UserProfileClient( "Default" , getRPCClient )
   group = str( getSelectedGroup() )
   profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
   result = upc.retrieveVar( profile_name )
   gLogger.info( result )
   if not result[ "OK" ]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return S_ERROR( result[ "Message" ] )
     gLogger.info( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return S_OK( list() ) # Nothing to delete, return an empty list
   else:
     result = result[ "Value" ]
   if not isinstance( result , list ):
     err = "List expected at: %s" % profile_name
     gLogger.error( "Result %s: %s" % ( msg , err ) )
     return S_ERROR( err )
   history = list()
   for i in result:
     if i.has_key( "name" ) and not i["name"] == name:
       history.append( i )
   if( len( history ) > history_length ):
     history = result[ history_length ]
   gLogger.error( "History: %s" % history )
   result = upc.storeVar( profile_name , history )
   gLogger.info( result )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return S_ERROR( result[ "Message" ] )
   gLogger.info( "Result %s: %s" % ( msg , history ) )
   return S_OK( history )
 def __deleteHistory(self, name, state):
     """
 Deleting item from Load and Save history list
 Return resulting list
 "name" is a string
 "state" can be either "Save" or "Load"
 """
     gLogger.info("Running deleteHistory( %s )" % name)
     msg = "deleteHistory() for %s@%s" % (getUsername(), getSelectedGroup())
     opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
     history_length = gConfig.getOptions(opt, 5)
     upc = UserProfileClient("Default", getRPCClient)
     group = str(getSelectedGroup())
     profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
     result = upc.retrieveVar(profile_name)
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         gLogger.info("Result %s: %s" % (msg, result["Message"]))
         return S_OK(list())  # Nothing to delete, return an empty list
     else:
         result = result["Value"]
     if not isinstance(result, list):
         err = "List expected at: %s" % profile_name
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     history = list()
     for i in result:
         if i.has_key("name") and not i["name"] == name:
             history.append(i)
     if (len(history) > history_length):
         history = result[history_length]
     gLogger.error("History: %s" % history)
     result = upc.storeVar(profile_name, history)
     gLogger.info(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     gLogger.info("Result %s: %s" % (msg, history))
     return S_OK(history)
Beispiel #17
0
 def __delBookmarks(self, name):
     if name == "columns" or name == "refresh" or name == "defaultLayout" or name == "layouts":
         return {
             "success":
             "false",
             "error":
             "The name \"" + name +
             "\" is reserved, please choose another name. Operation failed"
         }
     upc = UserProfileClient("Summary", getRPCClient)
     result = upc.retrieveVar("Bookmarks")
     if result["OK"]:
         data = result["Value"]
     else:
         data = {}
     gLogger.info("\033[0;31m data: \033[0m", data)
     if data.has_key("layouts"):
         if name in data["layouts"]:
             del data["layouts"][name]
         else:
             return {
                 "success": "false",
                 "error":
                 "Can't delete not existing layout: \"" + name + "\""
             }
     else:
         return {
             "success": "false",
             "error": "Can't read existing layouts, operation failed"
         }
     if len(data["layouts"]) > 0:
         data["defaultLayout"] = data["layouts"].keys()[0]
     else:
         data["defaultLayout"] = ""
     gLogger.info("\033[0;31m data: \033[0m", data)
     result = upc.storeVar("Bookmarks", data)
     gLogger.info("\033[0;31m result: \033[0m", result)
     if result["OK"]:
         return self.__getBookmarks()
     else:
         return {"success": "false", "error": result["Message"]}
Beispiel #18
0
 def __setHistory( self , item , state ):
   """
   Insert item to  Load or Save history list in first position and checking for
   duplications.
   Return resulting list
   "item" is a dict
   "state" should be either "Save" or "Load" but can be any other value
   """
   gLogger.info( "Running setHistory( %s , %s )" % ( item , state ) )
   msg = "setHistory() for %s@%s" % ( getUsername() , getSelectedGroup() )
   opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
   history_length = gConfig.getOptions( opt , 5 )
   upc = UserProfileClient( "Default" , getRPCClient )
   group = str( getSelectedGroup() )
   profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
   result = upc.retrieveVar( profile_name )
   gLogger.info( result )
   if not result[ "OK" ]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return S_ERROR( result[ "Message" ] )
     history = list()
   else:
     history = result[ "Value" ]
   if not isinstance( history , list ):
     err = "List expected at: %s" % profile_name
     gLogger.error( "Result %s: %s" % ( msg , err ) )
     return S_ERROR( err )
   if( len( history ) > history_length ):
     history = result[ history_length ]
   history.insert( 0 , item )
   history = uniqueElements( history )
   gLogger.error( "History: %s" % history )
   result = upc.storeVar( profile_name , history )
   gLogger.info( result )
   if not result[ "OK" ]:
     gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
     return S_ERROR( result[ "Message" ] )
   gLogger.info( "Result %s: %s" % ( msg , history ) )
   return S_OK( history )
 def __setHistory(self, item, state):
     """
 Insert item to  Load or Save history list in first position and checking for
 duplications.
 Return resulting list
 "item" is a dict
 "state" should be either "Save" or "Load" but can be any other value
 """
     gLogger.info("Running setHistory( %s , %s )" % (item, state))
     msg = "setHistory() for %s@%s" % (getUsername(), getSelectedGroup())
     opt = "/Website/" + USER_PROFILE_NAME + "/ShowHistory"
     history_length = gConfig.getOptions(opt, 5)
     upc = UserProfileClient("Default", getRPCClient)
     group = str(getSelectedGroup())
     profile_name = USER_PROFILE_NAME + ".History." + state + "." + group
     result = upc.retrieveVar(profile_name)
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         history = list()
     else:
         history = result["Value"]
     if not isinstance(history, list):
         err = "List expected at: %s" % profile_name
         gLogger.error("Result %s: %s" % (msg, err))
         return S_ERROR(err)
     if (len(history) > history_length):
         history = result[history_length]
     history.insert(0, item)
     history = uniqueElements(history)
     gLogger.error("History: %s" % history)
     result = upc.storeVar(profile_name, history)
     gLogger.info(result)
     if not result["OK"]:
         gLogger.error("Result %s: %s" % (msg, result["Message"]))
         return S_ERROR(result["Message"])
     gLogger.info("Result %s: %s" % (msg, history))
     return S_OK(history)
Beispiel #20
0
 def __setData(self,name=False):
   gLogger.info("__setData(%s) function" % name)
   if not name:
     return {"success":"false","error":"Name of the layout is absent"}
   data = {}
   for i in request.params:
     try:
       if len(request.params[i]) > 0:
         data[i] = str(request.params[i])
     except:
       pass
   gLogger.info("Data to save: %s" % data)
   upc = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   gLogger.info("upc.storeVar(%s,%s)" % (name,data))
   result = upc.storeVar(name,data)
   gLogger.debug(result)
   if not result["OK"]:
     return {"success":"false","error":result["Message"]}
   result = self.__setHistory(name)
   if not result["OK"]:
     gLogger.error(result["Message"])
   return self.__getData()
Beispiel #21
0
 def __addBookmark(self, path, title):
     """adds a bookmark"""
     self.getWidget().waitCursor()
     upc = UserProfileClient("Bookkeeping", RPCClient)
     result = upc.retrieveVar("Bookmarks")
     if result["OK"]:
         data = result["Value"]
     else:
         data = {}
     if title in data:
         QMessageBox.critical(
             self.getWidget(), "Error", "The bookmark with the title \"" +
             title + "\" is already exists", QMessageBox.Ok)
         return S_ERROR("The bookmark with the title \"" + title +
                        "\" is already exists")
     else:
         data[title] = path
     result = upc.storeVar("Bookmarks", data)
     self.getWidget().arrowCursor()
     if result["OK"]:
         return self.__getBookmarks()
     else:
         return S_ERROR(result["Message"])
Beispiel #22
0
 def __delBookmark(self, title):
     """deletes a bookmark"""
     self.getWidget().waitCursor()
     upc = UserProfileClient("Bookkeeping", RPCClient)
     result = upc.retrieveVar("Bookmarks")
     if result["OK"]:
         data = result["Value"]
     else:
         data = {}
     if title in data:
         del data[title]
     else:
         QMessageBox.critical(
             self.getWidget(), "Error",
             "Can't delete not existing bookmark: \"" + title + "\"",
             QMessageBox.Ok)
         return S_ERROR("Can't delete not existing bookmark: \"" + title +
                        "\"")
     result = upc.storeVar("Bookmarks", data)
     self.getWidget().arrowCursor()
     if result["OK"]:
         return self.__getBookmarks()
     else:
         return S_ERROR(result["Message"])
Beispiel #23
0
 def __convert(self):
   gLogger.info("Running convert()")
   msg = "convert() for %s@%s" % ( getUsername() , getSelectedGroup() )
   upc = UserProfileClient( "Summary", getRPCClient )
   result = upc.retrieveAllVars()
   gLogger.info( result )
   if not result["OK"]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return S_ERROR( result[ "Message" ] )
     result = "No data found, nothing to convert"
     gLogger.info( "Result %s: %s" % ( msg , result ) )
     return S_OK( result )
   result = result[ "Value" ]
   if not result.has_key( "Bookmarks" ):
     result = "No old Bookmarks found"
     gLogger.info( "Result %s: %s" % ( msg , result ) )
     return S_OK( result )
   data = result[ "Bookmarks" ]
   try:
     layouts = dict( data )
   except:
     result = "Layouts '%s' is not dictionary, can't convert" % layouts
     gLogger.info( "Result %s: %s" % ( msg , result ) )
     return S_OK( result )
   err = list()
   done = list()
   gLogger.info( "Saving old data to new place" )
   upcnew = UserProfileClient( USER_PROFILE_NAME, getRPCClient )
   permissions = "USER"
   user = str( getUsername() )
   group = str( getSelectedGroup() )
   for i in layouts:
     data = dict()
     data[ "url" ] = layouts[ i ][ "url" ]
     data[ "columns" ] = layouts[ i ][ "columns" ]
     data[ "refresh" ] = layouts[ i ][ "refresh" ]
     result = upcnew.storeVar( i , data , permissions )
     gLogger.debug( result )
     if not result[ "OK" ]:
       err.append( result[ "Message" ] )
       continue
     done.append( result[ "Value" ] )
     result = upc.deleteVar( i )
     if not result["OK"]:
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       err.append( result["Message"] )
     continue
   gLogger.info( "Is something left?" )
   result = upc.retrieveAllVars()
   gLogger.info( result )
   if result[ "OK" ] and len( result[ "Value" ] ) > 0:
     text = "Some data has left at old place. Please remove them manually"
     gLogger.info( "Result %s: %s" % ( msg , text ) )
   if not result["OK"]:
     if result[ "Message" ].find( "No data" ) < 0 :
       gLogger.error( "Result %s: %s" % ( msg , result[ "Message" ] ) )
       return S_ERROR( result[ "Message" ] )
   gLogger.info( "Looks like old data are erased" )
   if len( err ) == 0 and len( done ) == 0:
     good = "Some magic has happens. Neither errors nor succesfull results"
     good = good + " Perhaps there is no old profile to convert"
     gLogger.info( "Result %s: %s" % ( msg , good ) )
     return S_OK( good )
   if len( err ) > 0 and len( done ) == 0:
     error = "No succesfull results, only errors:\n"
     tmp = "\n".join( err )
     error = error + tmp
     gLogger.error( "Result %s: %s" % ( msg , error ) )
     return S_ERROR( error )
   if len( err ) > 0 and len( done ) > 0:
     good = "Conversion has finished partially sucessfull"
     if len( err ) > 0:
       good = good + ". There are some errors though\n"
     else:
       good = good + ". There is an error though\n"
     error = "\n".join( err )
     good = good + error
     gLogger.info( "Result %s: %s" % ( msg , good ) )
     return S_OK( good )
   if len( err ) == 0 and len( done ) > 0:
     good = "Conversion has finished sucessfully"
     gLogger.info( "Result %s: %s" % ( msg , good ) )
     return S_OK( good )
 def __convert(self):
     gLogger.info("Running convert()")
     msg = "convert() for %s@%s" % (getUsername(), getSelectedGroup())
     upc = UserProfileClient("Summary", getRPCClient)
     result = upc.retrieveAllVars()
     gLogger.info(result)
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
         result = "No data found, nothing to convert"
         gLogger.info("Result %s: %s" % (msg, result))
         return S_OK(result)
     result = result["Value"]
     if not result.has_key("Bookmarks"):
         result = "No old Bookmarks found"
         gLogger.info("Result %s: %s" % (msg, result))
         return S_OK(result)
     data = result["Bookmarks"]
     try:
         layouts = dict(data)
     except:
         result = "Layouts '%s' is not dictionary, can't convert" % layouts
         gLogger.info("Result %s: %s" % (msg, result))
         return S_OK(result)
     err = list()
     done = list()
     gLogger.info("Saving old data to new place")
     upcnew = UserProfileClient(USER_PROFILE_NAME, getRPCClient)
     permissions = "USER"
     user = str(getUsername())
     group = str(getSelectedGroup())
     for i in layouts:
         data = dict()
         data["url"] = layouts[i]["url"]
         data["columns"] = layouts[i]["columns"]
         data["refresh"] = layouts[i]["refresh"]
         result = upcnew.storeVar(i, data, permissions)
         gLogger.debug(result)
         if not result["OK"]:
             err.append(result["Message"])
             continue
         done.append(result["Value"])
         result = upc.deleteVar(i)
         if not result["OK"]:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             err.append(result["Message"])
         continue
     gLogger.info("Is something left?")
     result = upc.retrieveAllVars()
     gLogger.info(result)
     if result["OK"] and len(result["Value"]) > 0:
         text = "Some data has left at old place. Please remove them manually"
         gLogger.info("Result %s: %s" % (msg, text))
     if not result["OK"]:
         if result["Message"].find("No data") < 0:
             gLogger.error("Result %s: %s" % (msg, result["Message"]))
             return S_ERROR(result["Message"])
     gLogger.info("Looks like old data are erased")
     if len(err) == 0 and len(done) == 0:
         good = "Some magic has happens. Neither errors nor succesfull results"
         good = good + " Perhaps there is no old profile to convert"
         gLogger.info("Result %s: %s" % (msg, good))
         return S_OK(good)
     if len(err) > 0 and len(done) == 0:
         error = "No succesfull results, only errors:\n"
         tmp = "\n".join(err)
         error = error + tmp
         gLogger.error("Result %s: %s" % (msg, error))
         return S_ERROR(error)
     if len(err) > 0 and len(done) > 0:
         good = "Conversion has finished partially sucessfull"
         if len(err) > 0:
             good = good + ". There are some errors though\n"
         else:
             good = good + ". There is an error though\n"
         error = "\n".join(err)
         good = good + error
         gLogger.info("Result %s: %s" % (msg, good))
         return S_OK(good)
     if len(err) == 0 and len(done) > 0:
         good = "Conversion has finished sucessfully"
         gLogger.info("Result %s: %s" % (msg, good))
         return S_OK(good)