Ejemplo n.º 1
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'useWine':
            if value == 'yes':
                self.useWine = True
        elif key == 'stopWhenSeeding':
            if value == 'yes':
                self.stopWhenSeeding = True
        elif key == 'dht':
            if value == 'yes':
                self.useDHT = True
        else:
            client.parseSetting(self, key, value)
Ejemplo n.º 2
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'testTime':
            if self.testTime is not None:
                parseError( "Test time already set to {0}".format( self.testTime ) )
            if not isPositiveInt( value, True ):
                parseError( "The number of seconds to wait must be a non-zero positive integer" )
            self.testTime = value
        else:
            client.parseSetting(self, key, value)
Ejemplo n.º 3
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'useSSL':
            self.useSSL = (value != "no")
        elif key == 'port':
            if self.port:
                parseError( "Port already set: {0}".format( self.port ) )
            if not isPositiveInt( value, True ) or int(value) > 65535:
                parseError( "Port should be a non-zero integer < 65536" )
            self.port = int(value)
        else:
            client.parseSetting(self, key, value)
Ejemplo n.º 4
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'port':
            if self.port:
                parseError( "Port already set: {0}".format( self.port ) )
            if not isPositiveInt( value ) or int(value) < 1024 or int(value) > 65535:
                parseError( "Port must be a positive integer greater than 1023 and smaller than 65536, not {0}".format( value ) )
            self.port = int(value)
        elif key == 'changeTracker' or key == 'changetracker':
            if not isValidName( value ):
                parseError( "{0} is not a valid name for a file object.".format( value ) )
            self.changeTrackers.append( value )
        elif key == 'changeClientTracker':
            if not isValidName( value ):
                parseError( "{0} is not a valid name for a client object.".format( value ) )
            self.changeClientTrackers.append( value )
        else:
            client.parseSetting(self, key, value)
Ejemplo n.º 5
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        # TODO: Parse your settings. Example:
        #
        #   if key == 'postFixParams':
        #       if self.postFixParams:
        #           parseError( 'Seriously. How many parameters do you need? Go clean up your stuff!' )
        #       self.postFixParams = value
        #   elif key == 'protocolVersion':
        #       if not isPositiveInt( value, False ):
        #           parseError( 'Can you even count? Because {0} is definitely not a valid protocol number.'.format( value ) )
        #       self.protocolVersion = value
        #   else:
        #       client.parseSetting( self, key, value )
        #
        # Do not forget that last case!
        #
        # The following implementation assumes you have no parameters specific to your client:
        client.parseSetting(self, key, value)
Ejemplo n.º 6
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'listenAddress':
            if self.listenAddress:
                parseError( "listenAddress is already set: {0}".format( self.listenAddress ) )
            if containsSpace(value):
                parseError( "listenAddress may not contain any whitespace" )
            self.listenAddress = value
        elif key == 'listenPort':
            if self.listenPort:
                parseError( "listenPort is already set: {0}".format( self.listenPort ) )
            if not isPositiveInt( value, True ):
                parseError( "listenPort must be a positive integer" )
            self.listenPort = int(value)
        elif key == 'tracker':
            if self.tracker:
                parseError( "tracker is already set: {0}".format( self.tracker ) )
            if containsSpace(value):
                parseError( "tracker may not contain any whitespace" )
            self.tracker = value
        elif key == 'wait':
            if self.wait:
                parseError( "wait is already set: {0}".format( self.wait ) )
            if not isPositiveInt( value, True ):
                parseError( "wait must be a positive integer" )
            self.wait = int(value)
        elif key == 'chunkSize':
            if self.chunkSize:
                parseError( "chunck size is already set: {0}".format( self.chunkSize ) )
            if not isPositiveInt( value, True ):
                parseError( "chunck size must be a positive integer" )
            if int(value) % 1024 != 0:
                parseError( "chunk sizes not divisible by 1024 are not supported" )                
            self.chunkSize = int(value)
        else:
            client.parseSetting(self, key, value)