source: branches/active/character_customization/game/parpg/common/utils.py @ 753

Revision 753, 2.4 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • disabled options button as functionality was previously defined in fife's Setting object. Rather than reimplement in settings.py, I think it would be wiser to implement in the gui package or similar.
  • continued further integration of settings.py in rest of project
  • Property svn:eol-style set to native
  • Property svn:executable set to *
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
17from textwrap import dedent
18
19def addPaths (*paths):
20    """Adds a list of paths to sys.path. Paths are expected to use forward
21       slashes, for example '../../engine/extensions'. Slashes are converted
22       to the OS-specific equivalent.
23       @type paths: ???
24       @param paths: Paths to files?
25       @return: None"""
26    for p in paths:
27        if not p in sys.path:
28            sys.path.append(os.path.sep.join(p.split('/')))
29
30def parseBool(value):
31    """Parses a string to get a boolean value"""
32    if (value.isdigit()):
33        return bool(int(value))
34    elif (value.isalpha):
35        return value.lower()[0] == "t"
36    return False
37
38def locateFiles(pattern, root=os.curdir):
39    """Locate all files matching supplied filename pattern in and below
40    supplied root directory."""
41    for path, _, files in os.walk(os.path.abspath(root)):
42        for filename in fnmatch.filter(files, pattern):
43            yield os.path.join(path, filename)
44
45def loadSettings(settings_file = "./settings.xml"):
46    from fife.extensions.fife_settings import Setting
47    return Setting(app_name = "PARPG",
48                   settings_file = settings_file, 
49                   settings_gui_xml = "")
50
51def dedent_chomp(string):
52    """Remove common leading whitespace and chomp each non-blank line."""
53    dedented_string = dedent(string).strip()
54    lines = dedented_string.splitlines()
55    formatted_lines = []
56    for index in range(len(lines)):
57        line = lines[index]
58        if index == len(lines) - 1:
59            # Don't do anything to the last line.
60            pass
61        elif not line or line.isspace():
62            line = '\n\n'
63        else:
64            line = ''.join([line, ' '])
65        formatted_lines.append(line)
66    result = ''.join(formatted_lines)
67    return result
Note: See TracBrowser for help on using the repository browser.