当前位置: 首页>>代码示例>>Python>>正文


Python Modificator.loadCredentials方法代码示例

本文整理汇总了Python中DIRAC.ConfigurationSystem.private.Modificator.Modificator.loadCredentials方法的典型用法代码示例。如果您正苦于以下问题:Python Modificator.loadCredentials方法的具体用法?Python Modificator.loadCredentials怎么用?Python Modificator.loadCredentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.ConfigurationSystem.private.Modificator.Modificator的用法示例。


在下文中一共展示了Modificator.loadCredentials方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CSShellCmd

# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import loadCredentials [as 别名]
class CSShellCmd(cmd.Cmd):

  def __init__(self):
    cmd.Cmd.__init__(self)
    self.serverURL   = ""
    self.serverName  = ""
    self.modificator = None
    self.connected   = False
    self.dirty       = False
    self.root        = "/"

    self.do_connect("")

  def update_prompt(self):
    if self.connected:
      self.prompt = "[" + colorize(self.serverName, "green") + ":" + self.root + " ]% "
    else:
      self.prompt = "[" + colorize("disconnected", "red") + ":" + self.root + " ]% "

  def do_connect(self, line):
    """connect
    Connect to the CS
    Usage: connect <URL> (Connect to the CS at the specified URL)
           connect       (Connect to the default CS URL of your config)
    """
    if line == "":
      self.serverURL  = gConfigurationData.getMasterServer()
      self.serverName = gConfigurationData.getName()
    else:
      self.serverURL  = self.serverName = line

    if self.serverURL == None:
      print "Unable to connect to the default server. Maybe you don't have a proxy ?"
      return self.do_disconnect("")

    print "Trying to connect to " + self.serverURL + "...",

    self.modificator = Modificator(RPCClient(self.serverURL))
    rv               = self.modificator.loadFromRemote()
    rv2              = self.modificator.loadCredentials()

    if rv['OK'] == False or rv2['OK'] == False:
      print "failed: ",
      if rv['OK'] == False: print rv['Message']
      else:                 print rv2['Message']
      self.connected = False
      self.update_prompt()
    else:
开发者ID:IgorPelevanyuk,项目名称:DIRAC,代码行数:50,代码来源:dirac-configuration-shell.py

示例2: CSCLI

# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import loadCredentials [as 别名]
class CSCLI( cmd.Cmd ):

  def __init__( self ):
    cmd.Cmd.__init__( self )
    self.connected = False
    self.masterURL = "unset"
    self.writeEnabled = False
    self.modifiedData = False
    self.rpcClient = None
    self.do_connect()
    if self.connected:
      self.modificator = Modificator ( self.rpcClient )
    else:
      self.modificator = Modificator()
    self.identSpace = 20
    self.backupFilename = "dataChanges"
    self._initSignals()
    #User friendly hack
    self.do_exit = self.do_quit
    # store history
    histfilename = os.path.basename(sys.argv[0])
    historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
    if not os.path.exists( os.path.dirname(historyFile) ):
      os.makedirs( os.path.dirname(historyFile) )
    if os.path.isfile( historyFile ):
      readline.read_history_file( historyFile )
    readline.set_history_length(1000)
    atexit.register( readline.write_history_file, historyFile )


  def start( self ):
    if self.connected:
      self.modificator.loadFromRemote()
      retVal = self.modificator.loadCredentials()
      if not retVal[ 'OK' ]:
        print "There was an error gathering your credentials"
        print retVal[ 'Message' ]
        self._setStatus( False )
    try:
      self.cmdloop()
    except KeyboardInterrupt:
      gLogger.warn( "Received a keyboard interrupt." )
      self.do_quit( "" )

  def _initSignals( self ):
    """
    Registers signal handlers
    """
    for sigNum in ( signal.SIGINT, signal.SIGQUIT, signal.SIGKILL, signal.SIGTERM ):
      try:
        signal.signal( sigNum, self.do_quit )
      except:
        pass

  def _setConnected( self, connected, writeEnabled ):
    self.connected = connected
    self.modifiedData = False
    self.writeEnabled = writeEnabled
    if connected:
      if writeEnabled:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
      else:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
    else:
      self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )


  def _printPair( self, key, value, separator = ":" ):
    valueList = value.split( "\n" )
    print "%s%s%s %s" % ( key, " " * ( self.identSpace - len( key ) ), separator, valueList[0].strip() )
    for valueLine in valueList[ 1:-1 ]:
      print "%s  %s" % ( " " * self.identSpace, valueLine.strip() )

  def do_quit( self, dummy ):
    """
    Exits the application without sending changes to server

    Usage: quit
    """
    if self.modifiedData:
      print "Changes are about to be written to file for later use."
      self.do_writeToFile( self.backupFilename )
      print "Changes written to %s.cfg" % self.backupFilename
    sys.exit( 0 )

  def do_EOF( self, args ):
    """
    Accepts ctrl^D to quit CLI
    """
    print ""
    self.do_quit( args )

  def do_help( self, args ):
    """
    Shows help information

    Usage: help <command>

    If no command is specified all commands are shown

#.........这里部分代码省略.........
开发者ID:Kiyoshi-Hayasaka,项目名称:DIRAC,代码行数:103,代码来源:CSCLI.py

示例3: CSCLI

# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import loadCredentials [as 别名]
class CSCLI( CLI ):

  def __init__( self ):
    CLI.__init__( self )
    self.connected = False
    self.masterURL = "unset"
    self.writeEnabled = False
    self.modifiedData = False
    self.rpcClient = None
    self.do_connect()
    if self.connected:
      self.modificator = Modificator ( self.rpcClient )
    else:
      self.modificator = Modificator()
    self.indentSpace = 20
    self.backupFilename = "dataChanges"
    # store history
    histfilename = os.path.basename(sys.argv[0])
    historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
    if not os.path.exists( os.path.dirname(historyFile) ):
      os.makedirs( os.path.dirname(historyFile) )
    if os.path.isfile( historyFile ):
      readline.read_history_file( historyFile )
    readline.set_history_length(1000)
    atexit.register( readline.write_history_file, historyFile )


  def start( self ):
    if self.connected:
      self.modificator.loadFromRemote()
      retVal = self.modificator.loadCredentials()
      if not retVal[ 'OK' ]:
        print "There was an error gathering your credentials"
        print retVal[ 'Message' ]
        self._setStatus( False )
    try:
      self.cmdloop()
    except KeyboardInterrupt:
      gLogger.warn( "Received a keyboard interrupt." )
      self.do_quit( "" )

  def _setConnected( self, connected, writeEnabled ):
    self.connected = connected
    self.modifiedData = False
    self.writeEnabled = writeEnabled
    if connected:
      if writeEnabled:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
      else:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
    else:
      self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )

  def do_quit( self, dummy ):
    """
    Exits the application without sending changes to server

    Usage: quit
    """
    print
    if self.modifiedData:
      print "Changes are about to be written to file for later use."
      self.do_writeToFile( self.backupFilename )
      print "Changes written to %s.cfg" % self.backupFilename
    sys.exit( 0 )


#  def retrieveData( self ):
#    if not self.connected:
#      return False
#    response = self.rpcClient.dumpCompressed()
#    if response[ 'Status' ] == 'OK':
#      self.cDataHolder.loadFromCompressedSource( response[ 'Value' ] )
#      gLogger.info( "Data retrieved from server." )
#      return True
#    else:
#      gLogger.error( "Can't retrieve updated data from server." )
#      return False

  def _setStatus( self, connected = True ):
    if not connected:
      self.masterURL = "unset"
      self._setConnected( False, False )
    else:
      retVal = self.rpcClient.writeEnabled()
      if retVal[ 'OK' ]:
        if retVal[ 'Value' ] == True:
          self._setConnected( True, True )
        else:
          self._setConnected( True, False )
      else:
        print "Server returned an error: %s" % retVal[ 'Message' ]
        self._setConnected( True, False )

  def _tryConnection( self ):
    print "Trying connection to %s" % self.masterURL
    try:
      self.rpcClient = RPCClient( self.masterURL )
      self._setStatus()
    except Exception, x:
#.........这里部分代码省略.........
开发者ID:JanEbbing,项目名称:DIRAC,代码行数:103,代码来源:CSCLI.py

示例4: CSShellCLI

# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import loadCredentials [as 别名]
class CSShellCLI(CLI):
    def __init__(self):
        CLI.__init__(self)
        self.serverURL = ""
        self.serverName = ""
        self.modificator = None
        self.connected = False
        self.dirty = False
        self.root = "/"

        self.do_connect("")

    def update_prompt(self):
        if self.connected:
            self.prompt = "[" + colorize(self.serverName, "green") + ":" + self.root + " ]% "
        else:
            self.prompt = "[" + colorize("disconnected", "red") + ":" + self.root + " ]% "

    def do_connect(self, line):
        """connect
    Connect to the CS
    Usage: connect <URL> (Connect to the CS at the specified URL)
           connect       (Connect to the default CS URL of your config)
    """
        if line == "":
            self.serverURL = gConfigurationData.getMasterServer()
            self.serverName = gConfigurationData.getName()
        else:
            self.serverURL = self.serverName = line

        if self.serverURL == None:
            print "Unable to connect to the default server. Maybe you don't have a proxy ?"
            return self.do_disconnect("")

        print "Trying to connect to " + self.serverURL + "...",

        self.modificator = Modificator(RPCClient(self.serverURL))
        rv = self.modificator.loadFromRemote()
        rv2 = self.modificator.loadCredentials()

        if rv["OK"] == False or rv2["OK"] == False:
            print "failed: ",
            if rv["OK"] == False:
                print rv["Message"]
            else:
                print rv2["Message"]
            self.connected = False
            self.update_prompt()
        else:
            self.connected = True
            self.update_prompt()
            print "done."

    def do_disconnect(self, _line):
        """Disconnect from CS"""
        if self.connected and self.dirty:
            res = raw_input("Do you want to commit your changes into the CS ? [y/N] ")
            if res.lower() in ["y", "yes"]:
                self.do_commit("")

        self.serverURL = self.serverName = ""
        self.modificator = None
        self.connected = False
        self.update_prompt()

    def do_ls(self, line):
        """ls
    List the sections and options of CS of the current root"""
        if self.connected:
            secs = self.modificator.getSections(self.root)
            opts = self.modificator.getOptions(self.root)
            if line.startswith("-") and "l" in line:
                for i in secs:
                    print colorize(i, "blue") + "  "
                for i in opts:
                    print i + " "
            else:
                for i in secs:
                    print colorize(i, "blue") + "  ",
                for i in opts:
                    print i + " ",
                print ""

    def do_cd(self, line):
        """cd
    Go one directory deeper in the CS"""
        # Check if invariant holds
        if self.connected:
            assert self.root == "/" or not self.root.endswith("/")
            assert self.root.startswith("/")
            secs = self.modificator.getSections(self.root)
            if line == "..":
                self.root = os.path.dirname(self.root)
                self.update_prompt()
            else:
                if os.path.normpath(line) in secs:
                    if self.root == "/":
                        self.root = self.root + os.path.normpath(line)
                    else:
                        self.root = self.root + "/" + os.path.normpath(line)
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例5: CSCLI

# 需要导入模块: from DIRAC.ConfigurationSystem.private.Modificator import Modificator [as 别名]
# 或者: from DIRAC.ConfigurationSystem.private.Modificator.Modificator import loadCredentials [as 别名]
class CSCLI( CLI ):

  def __init__( self ):
    CLI.__init__( self )
    self.connected = False
    self.masterURL = "unset"
    self.writeEnabled = False
    self.modifiedData = False
    self.rpcClient = None
    self.do_connect()
    if self.connected:
      self.modificator = Modificator ( self.rpcClient )
    else:
      self.modificator = Modificator()
    self.indentSpace = 20
    self.backupFilename = "dataChanges"
    # store history
    histfilename = os.path.basename(sys.argv[0])
    historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
    mkDir(os.path.dirname(historyFile))
    if os.path.isfile( historyFile ):
      readline.read_history_file( historyFile )
    readline.set_history_length(1000)
    atexit.register( readline.write_history_file, historyFile )


  def start( self ):
    if self.connected:
      self.modificator.loadFromRemote()
      retVal = self.modificator.loadCredentials()
      if not retVal[ 'OK' ]:
        print "There was an error gathering your credentials"
        print retVal[ 'Message' ]
        self._setStatus( False )
    try:
      self.cmdloop()
    except KeyboardInterrupt:
      gLogger.warn( "Received a keyboard interrupt." )
      self.do_quit( "" )

  def _setConnected( self, connected, writeEnabled ):
    self.connected = connected
    self.modifiedData = False
    self.writeEnabled = writeEnabled
    if connected:
      if writeEnabled:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected", "green" ) )
      else:
        self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Connected (RO)", "yellow" ) )
    else:
      self.prompt = "(%s)-%s> " % ( self.masterURL, colorize( "Disconnected", "red" ) )

  def do_quit( self, dummy ):
    """
    Exits the application without sending changes to server

    Usage: quit
    """
    print
    if self.modifiedData:
      print "Changes are about to be written to file for later use."
      self.do_writeToFile( self.backupFilename )
      print "Changes written to %s.cfg" % self.backupFilename
    sys.exit( 0 )


#  def retrieveData( self ):
#    if not self.connected:
#      return False
#    response = self.rpcClient.dumpCompressed()
#    if response[ 'Status' ] == 'OK':
#      self.cDataHolder.loadFromCompressedSource( response[ 'Value' ] )
#      gLogger.info( "Data retrieved from server." )
#      return True
#    else:
#      gLogger.error( "Can't retrieve updated data from server." )
#      return False

  def _setStatus( self, connected = True ):
    if not connected:
      self.masterURL = "unset"
      self._setConnected( False, False )
    else:
      retVal = self.rpcClient.writeEnabled()
      if retVal[ 'OK' ]:
        if retVal[ 'Value' ] == True:
          self._setConnected( True, True )
        else:
          self._setConnected( True, False )
      else:
        print "Server returned an error: %s" % retVal[ 'Message' ]
        self._setConnected( True, False )

  def _tryConnection( self ):
    print "Trying connection to %s" % self.masterURL
    try:
      self.rpcClient = RPCClient( self.masterURL )
      self._setStatus()
    except Exception as x:
      gLogger.error( "Couldn't connect to master CS server", "%s (%s)" % ( self.masterURL, str( x ) ) )
#.........这里部分代码省略.........
开发者ID:ahaupt,项目名称:DIRAC,代码行数:103,代码来源:CSCLI.py


注:本文中的DIRAC.ConfigurationSystem.private.Modificator.Modificator.loadCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。