コード例 #1
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariables(module = None, submodule = None):
    varlist = []
    if submodule:
        module = submodule
    if xa.exists(module):
        module = xa.find(module)
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
    else:
        for module in sorted(xa.modules()):
            module = xa.find(module)
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    return varlist
コード例 #2
0
def getVariables(module=None, submodule=None):
    varlist = []
    if submodule:
        module = submodule
    if xa.exists(module):
        module = xa.find(module)
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
    else:
        for module in sorted(xa.modules()):
            module = xa.find(module)
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    return varlist
コード例 #3
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createVariable(module, variable, defaultvalue=0, description=''):
    """
        Create a server variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar
        defaultvalue:   default value
        description:    text description of the cvar
        
        return:         (bool) true (false if module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name?
        if variable:
            # Setup the variable
            module.variables[variable] = es.ServerVar(variable, defaultvalue, description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            
            # Return our new variable instance
            return module.variables[variable]
    
    # Fallback, variable creation failed
    return False
コード例 #4
0
def getVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable in module.variables:
            return module.variables[variable]
    return False
コード例 #5
0
def deleteVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable and getVariable(module, variable):
            es.set(variable, '', '')
            del module.variables[variable]
コード例 #6
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def deleteVariable(module, variable):
    """
        Delete a variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to delete
        
        return:         (bool) true (false if variable/module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name and does the variable exist?
        if variable and getVariable(module, variable):
            # Reset the variable
            es.set(variable, '', '')
            
            # Remove the variable from our module
            del module.variables[variable]
            
            return True
    return False
コード例 #7
0
def createVariable(module, variable, defaultvalue=0, description=''):
    """
        Create a server variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar
        defaultvalue:   default value
        description:    text description of the cvar
        
        return:         (bool) true (false if module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name?
        if variable:
            # Setup the variable
            module.variables[variable] = es.ServerVar(variable, defaultvalue,
                                                      description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description

            # Return our new variable instance
            return module.variables[variable]

    # Fallback, variable creation failed
    return False
コード例 #8
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable in module.variables:
            return module.variables[variable]
    return False
コード例 #9
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def deleteVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable and getVariable(module, variable):
            es.set(variable, '', '')
            del module.variables[variable]
コード例 #10
0
def deleteVariable(module, variable):
    """
        Delete a variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to delete
        
        return:         (bool) true (false if variable/module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name and does the variable exist?
        if variable and getVariable(module, variable):
            # Reset the variable
            es.set(variable, '', '')

            # Remove the variable from our module
            del module.variables[variable]

            return True
    return False
コード例 #11
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariables(module, submodule = None):
    """
        Retrieve a list of the variables registered to a module
        
        module:         module name (usually automatically provided)
        submodule:      used to specify another module to retrieve variables from
        
        return:         list of ServerVar instances
        
        Because of how this is used you usually call:
          <xa instance>.settings.getVariables()
        to retrieve your own module's variables. And:
          <xa instance>.settings.getVariables("othermodule")
        to retrieve another modules variables.
    
    """
    # Return variable
    varlist = []
    
    # Do we want to get the list of another module?
    if submodule:
        module = submodule
    
    # Does our module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Fill our variable list
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
        
    else:
        # No, we just return a variable list of all modules
        for module in sorted(xa.modules()):
            # Find the module instance
            module = xa.find(module)
            
            # Fill our variable list
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    
    # Return our variable list
    return varlist
コード例 #12
0
def getVariables(module, submodule=None):
    """
        Retrieve a list of the variables registered to a module
        
        module:         module name (usually automatically provided)
        submodule:      used to specify another module to retrieve variables from
        
        return:         list of ServerVar instances
        
        Because of how this is used you usually call:
          <xa instance>.settings.getVariables()
        to retrieve your own module's variables. And:
          <xa instance>.settings.getVariables("othermodule")
        to retrieve another modules variables.
    
    """
    # Return variable
    varlist = []

    # Do we want to get the list of another module?
    if submodule:
        module = submodule

    # Does our module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Fill our variable list
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])

    else:
        # No, we just return a variable list of all modules
        for module in sorted(xa.modules()):
            # Find the module instance
            module = xa.find(module)

            # Fill our variable list
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])

    # Return our variable list
    return varlist
コード例 #13
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createVariable(module, variable, defaultvalue=0, description=""):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable:
            module.variables[variable] = es.ServerVar(variable, defaultvalue, description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            return module.variables[variable]
    return False
コード例 #14
0
def writeConfiguration(module):
    """
        Uses Cfglib to write module configuration to disk
        
        module:         module name (usually automatically provided)
        
        return:         nothing
        
    """
    # Write our configuration to disk using cfglib
    config = cfglib.AddonCFG('%s/cfg/xamodules.cfg' % xa.gamedir())
    config.text('******************************')
    config.text('  XA Module Configuration', True)
    config.text('  Timestamp: %s' %
                time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()))
    config.text('******************************')

    # Loop through all modules
    for module in sorted(xa.modules()):
        # Find the module instance
        module = xa.find(module)

        # Does the module have variables?
        if module.variables:
            # Add the module to the AddonCFG instance
            config.text('')
            config.text('******************************')
            config.text('  Module: %s' %
                        (module.name if module.name else module))
            config.text('******************************')

            # Loop through all variables of the module
            for variable in sorted(module.variables):
                # Get the variable instance
                variable = module.variables[variable]

                # Is this a valid variable name?
                if variable.getName().replace('_', '').isalnum():
                    # Add our variable to the AddonCFG instance
                    config.cvar(variable.getName(), variable._def,
                                variable._descr)

            # Loop through all commands of the module
            for command in sorted(module.commands):
                config.text('')
                config.text(module.commands[command].usage)
                config.text(module.commands[command].description)
                config.text("Insert commands below the lines")
                config.text('-' * 77)
                config.command(command)
                config.text('-' * 77)

    # Finally write the file to disk
    config.write()
コード例 #15
0
def createVariable(module, variable, defaultvalue=0, description=""):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable:
            module.variables[variable] = es.ServerVar(variable, defaultvalue,
                                                      description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            return module.variables[variable]
    return False
コード例 #16
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def writeConfiguration(module):
    """
        Uses Cfglib to write module configuration to disk
        
        module:         module name (usually automatically provided)
        
        return:         nothing
        
    """
    # Write our configuration to disk using cfglib
    config = cfglib.AddonCFG('%s/cfg/xamodules.cfg' % xa.gamedir())
    config.text('******************************')
    config.text('  XA Module Configuration', True)
    config.text('  Timestamp: %s' % time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()))
    config.text('******************************')
    
    # Loop through all modules
    for module in sorted(xa.modules()):
        # Find the module instance
        module = xa.find(module)
        
        # Does the module have variables?
        if module.variables:
            # Add the module to the AddonCFG instance
            config.text('')
            config.text('******************************')
            config.text('  Module: %s' % (module.name if module.name else module))
            config.text('******************************')
            
            # Loop through all variables of the module
            for variable in sorted(module.variables):
                # Get the variable instance
                variable = module.variables[variable]
                
                # Is this a valid variable name?
                if variable.getName().replace('_', '').isalnum():
                    # Add our variable to the AddonCFG instance
                    config.cvar(variable.getName(), variable._def, variable._descr)
            
            # Loop through all commands of the module
            for command in sorted(module.commands):
                config.text('')
                config.text(module.commands[command].usage)
                config.text(module.commands[command].description)
                config.text("Insert commands below the lines")
                config.text('-' * 77)
                config.command(command)
                config.text('-' * 77)
    
    # Finally write the file to disk
    config.write()
コード例 #17
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def writeConfiguration(module = None):
    config = cfglib.AddonCFG("%s/cfg/xamodules.cfg" % xa.gamedir())
    config.text('******************************')
    config.text('  XA Module Configuration', True)
    config.text('  Timestamp: %s' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))
    config.text('******************************')
    for module in sorted(xa.modules()):
        module = xa.find(module)
        if module.variables:
            config.text('')
            config.text('******************************')
            config.text('  Module: %s' % (module.name if module.name else module))
            config.text('******************************')
            for variable in sorted(module.variables):
                variable = module.variables[variable]
                if variable.getName().replace('_', '').isalnum():
                    config.cvar(variable.getName(), variable._def, variable._descr)
    config.write()
コード例 #18
0
def createCommandSpace(module, command, usage='', description=''):
    """
        Create a server command section in the cfg
        
        module:         module name (usually automatically provided)
        command:        the command
        usage:          usually a longer section of text describing usage
        description:    text description of the command
        
        return:         (bool) true (false if module does not exist)
    """
    # ensure the module exists
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Store the command instance into the module's command attribute
        module.commands[command] = Command(command, description, usage)
        return True
    return False
コード例 #19
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createCommandSpace(module, command, usage='', description=''):
    """
        Create a server command section in the cfg
        
        module:         module name (usually automatically provided)
        command:        the command
        usage:          usually a longer section of text describing usage
        description:    text description of the command
        
        return:         (bool) true (false if module does not exist)
    """
    # ensure the module exists
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Store the command instance into the module's command attribute 
        module.commands[command] = Command(command, description, usage)
        return True
    return False
コード例 #20
0
def writeConfiguration(module=None):
    config = cfglib.AddonCFG("%s/cfg/xamodules.cfg" % xa.gamedir())
    config.text('******************************')
    config.text('  XA Module Configuration', True)
    config.text('  Timestamp: %s' %
                time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))
    config.text('******************************')
    for module in sorted(xa.modules()):
        module = xa.find(module)
        if module.variables:
            config.text('')
            config.text('******************************')
            config.text('  Module: %s' %
                        (module.name if module.name else module))
            config.text('******************************')
            for variable in sorted(module.variables):
                variable = module.variables[variable]
                if variable.getName().replace('_', '').isalnum():
                    config.cvar(variable.getName(), variable._def,
                                variable._descr)
    config.write()
コード例 #21
0
def getVariable(module, variable):
    """
        Retrieve a ServerVar reference to variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to retrieve
        
        return:         ServerVar instance (False if no variable or module)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name and is the variable assigned to our module?
        if variable in module.variables:
            # Return our existing variable instance
            return module.variables[variable]

    # Fallback, couldn't find variable instance
    return False
コード例 #22
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariable(module, variable):
    """
        Retrieve a ServerVar reference to variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to retrieve
        
        return:         ServerVar instance (False if no variable or module)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name and is the variable assigned to our module?
        if variable in module.variables:
            # Return our existing variable instance
            return module.variables[variable]

    # Fallback, couldn't find variable instance
    return False