source: branches/active/character_customization/game/utilities/dialogueChecker.py @ 736

Revision 736, 2.3 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • renamed scripts package to parpg
  • renamed parpg module to application
  • removed packaging and other related files (kept locally for reference, will reintroduce similar scripts to resolve bug #275
  • updated all import statements to respect changes above
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3#   This program is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7
8#   This program is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12
13#   You should have received a copy of the GNU General Public License
14#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16import os
17import sys
18import getopt
19import logging
20
21import sys
22sys.path = ['../parpg'] + sys.path
23
24
25from dialoguevalidator import DialogueValidator, DialogueFormatException
26
27log = logging.getLogger("dialoguevalidator")
28log.setLevel(logging.DEBUG)
29
30def usage():
31    """ Prints the help message. """
32    print "Usage: %s [options]" % sys.argv[0]
33    print "Options:"
34    print "   --help, -h         This help message"
35    print "   --file FILE, -f    Yaml file to validate (default dialogue.yaml)"
36    print "   --root ROOT, -r    Root path to which all files are checked"
37
38def main(argv):
39    """ Main function, parses the command line arguments
40    and launches the dialogue validator. """
41
42    try:
43        opts, args = getopt.getopt(argv, "hf:r:", 
44        ["help","file", "root"])
45    except getopt.GetoptError:
46        usage()
47        sys.exit(2)
48
49    yaml_file = "dialogue.yaml"
50    topdir = "."
51
52    ch = logging.StreamHandler()
53    ch.setLevel(logging.INFO)
54
55    for opt, arg in opts:       
56        if opt in ("-f","--file"):
57            yaml_file = arg
58        elif opt in ("-r","--root"):
59            topdir = arg
60        else:
61            usage()
62            sys.exit()
63
64    formatter = logging.Formatter("%(levelname)s: %(message)s")
65    ch.setFormatter(formatter)
66    log.addHandler(ch)
67
68    log.info("Going to validate file %s" % (yaml_file))
69    log.info("Searching for files relative to %s" % (topdir))
70    val = DialogueValidator()
71    try:
72        val.validateDialogueFromFile(yaml_file, topdir)
73        log.info("Done");
74    except DialogueFormatException as dfe:
75        log.info("Error found in file !")
76        log.info("Error was: %s" % (dfe))
77
78
79if __name__ == '__main__':
80    main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.