1 | #!/usr/bin/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 | |
---|
16 | import os |
---|
17 | import sys |
---|
18 | import getopt |
---|
19 | import logging |
---|
20 | |
---|
21 | import sys |
---|
22 | sys.path = ['../scripts'] + sys.path |
---|
23 | |
---|
24 | |
---|
25 | from dialoguevalidator import DialogueValidator, DialogueFormatException |
---|
26 | |
---|
27 | log = logging.getLogger("dialoguevalidator") |
---|
28 | log.setLevel(logging.DEBUG) |
---|
29 | |
---|
30 | def 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 | |
---|
38 | def 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 | |
---|
79 | if __name__ == '__main__': |
---|
80 | main(sys.argv[1:]) |
---|