Example #1
0
def getAliasList(module, filename, modfolder = False):
    # Return variable
    lines = {}
    
    # Is the filename relative to the modfolder?
    if modfolder:
        filename = ('%s/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    else:
        filename = ('%s/cfg/xa/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    
    # Does the file exist?
    if os.path.exists(filename):
        # Try reading the file into the dict
        try:
            file = open(filename, 'rU')
            for line in file:
                if line and (line[0:2] != '//') and (line != '\n'):
                    line = line.replace('\r', '').replace('\n', '').replace('\t', ' ').replace('  ', ' ').replace('"', '\'')[1:].split('\' ', 1)
                    if line and len(line) >= 2:
                        lines[line[0].replace('\'', '')] = line[1]
        finally:
            file.close()
    
    # Return the line dict
    return lines
Example #2
0
def getList(module, filename, modfolder=False):
    # Return variable
    lines = []

    # Is the filename relative to the modfolder?
    if modfolder:
        filename = ('%s/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    else:
        filename = ('%s/cfg/xa/%s' % (xa.gamedir(), filename)).replace(
            '\\', '/')

    # Does the file exist?
    if os.path.exists(filename):
        # Try reading the file into the list
        try:
            file = open(filename, 'rU')
            for line in file:
                if line and (line[0:2] != '//') and (line != '\n'):
                    line = line.replace('\r', '').replace('\n', '').replace(
                        '\t', ' ').replace('  ', ' ')
                    lines.append(line)
        finally:
            file.close()

    # Return the line list
    return lines
Example #3
0
def getKeyList(module, filename, modfolder = False):
    if modfolder == False:
        filename = ("%s/cfg/xa/%s" % (xa.gamedir(), filename)).replace("\\", "/")
    else:
        filename = ("%s/%s" % (xa.gamedir(), filename)).replace("\\", "/")
    if os.path.exists(filename):
        kv = keyvalues.KeyValues()
        kv.load(filename)
        return kv
    return False
Example #4
0
def getAliasList(module, filename, modfolder = False):
    if modfolder == False:
        filename = ("%s/cfg/xa/%s" % (xa.gamedir(), filename)).replace("\\", "/")
    else:
        filename = ("%s/%s" % (xa.gamedir(), filename)).replace("\\", "/")
    if os.path.exists(filename):
        lines = {}
        try:
            file = open(filename, "rU")
            for line in file:
                if line and (line[0:2] != '//') and (line != '\n'):
                    line = line.replace("\r", "").replace("\n", "").replace("\t", " ").replace("  ", " ")[1:].split("\" ", 1)
                    lines[line[0].replace("\"", "")] = line[1]
        finally:
            file.close()
        return lines
    return False
Example #5
0
def getKeyList(module, filename, modfolder = False):
    # Is the filename relative to the modfolder?
    if modfolder:
        filename = ('%s/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    else:
        filename = ('%s/cfg/xa/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    
    # Does the file exist?
    if os.path.exists(filename):
        # Load the file into a new KeyValues object
        try:
            kv = keyvalues.KeyValues()
            kv.load(filename)
        except:
            kv = None
        
        # Return ou new KeyValues object
        return kv
Example #6
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()
Example #7
0
def executeConfiguration(module):
    """
        Uses Cfglib to execute a modules cfg file
        
        module:         module name (usually automatically provided)
        
        return:         nothing

    """
    # Execute our configuration using cfglib
    config = cfglib.AddonCFG('%s/cfg/xamodules.cfg' % xa.gamedir())
    config.execute()
Example #8
0
def executeConfiguration(module):
    """
        Uses Cfglib to execute a modules cfg file
        
        module:         module name (usually automatically provided)
        
        return:         nothing

    """
    # Execute our configuration using cfglib
    config = cfglib.AddonCFG('%s/cfg/xamodules.cfg' % xa.gamedir())
    config.execute()
Example #9
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()
Example #10
0
def getList(module, filename, modfolder = False):
    # Return variable
    lines = []
    
    # Is the filename relative to the modfolder?
    if modfolder:
        filename = ('%s/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    else:
        filename = ('%s/cfg/xa/%s' % (xa.gamedir(), filename)).replace('\\', '/')
    
    # Does the file exist?
    if os.path.exists(filename):
        # Try reading the file into the list
        try:
            file = open(filename, 'rU')
            for line in file:
                if line and (line[0:2] != '//') and (line != '\n'):
                    line = line.replace('\r', '').replace('\n', '').replace('\t', ' ').replace('  ', ' ')
                    lines.append(line)
        finally:
            file.close()
    
    # Return the line list
    return lines
Example #11
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()
Example #12
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()
Example #13
0
def executeConfiguration(module=None):
    config = cfglib.AddonCFG("%s/cfg/xamodules.cfg" % xa.gamedir())
    config.execute()
Example #14
0
def executeConfiguration(module = None):
    config = cfglib.AddonCFG("%s/cfg/xamodules.cfg" % xa.gamedir())
    config.execute()