source: trunk/game/scripts/common/utils.py @ 627

Revision 627, 1.8 KB checked in by beliar, 9 years ago (diff)

Patch by Beliar.

  • Added SettingsVersion? to settings. This contains the version (currently a date of the last change) of the settings. The version will be checked with the version in settings-dist.xml and if the versions don't match the settings.xml file will be renamed to settings-old.xml. The version string has to be set manually when editing settings-dist.xml.
  • Property svn:eol-style set to native
Line 
1#   This program is free software: you can redistribute it and/or modify
2#   it under the terms of the GNU General Public License as published by
3#   the Free Software Foundation, either version 3 of the License, or
4#   (at your option) any later version.
5
6#   This program is distributed in the hope that it will be useful,
7#   but WITHOUT ANY WARRANTY; without even the implied warranty of
8#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9#   GNU General Public License for more details.
10
11#   You should have received a copy of the GNU General Public License
12#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
13
14# Miscellaneous game functions
15
16import os, sys, fnmatch
17
18def addPaths (*paths):
19    """Adds a list of paths to sys.path. Paths are expected to use forward
20       slashes, for example '../../engine/extensions'. Slashes are converted
21       to the OS-specific equivalent.
22       @type paths: ???
23       @param paths: Paths to files?
24       @return: None"""
25    for p in paths:
26        if not p in sys.path:
27            sys.path.append(os.path.sep.join(p.split('/')))
28
29def parseBool(value):
30    """Parses a string to get a boolean value"""
31    if (value.isdigit()):
32        return bool(int(value))
33    elif (value.isalpha):
34        return value.lower()[0] == "t"
35    return False
36
37def locateFiles(pattern, root=os.curdir):
38    """Locate all files matching supplied filename pattern in and below
39    supplied root directory."""
40    for path, _, files in os.walk(os.path.abspath(root)):
41        for filename in fnmatch.filter(files, pattern):
42            yield os.path.join(path, filename)
43
44def loadSettings(settings_file = "./settings.xml"):
45    from fife.extensions.fife_settings import Setting
46    return Setting(app_name = "PARPG",
47                   settings_file = settings_file, 
48                   settings_gui_xml = "") 
Note: See TracBrowser for help on using the repository browser.