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

Revision 563, 1.6 KB checked in by beliar, 10 years ago (diff)

Ticket #200: Patch by Beliar.

  • Merging map_loading_change branch back into trunk

fixes[s:trac, t:200]

  • 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)
Note: See TracBrowser for help on using the repository browser.