Menu

[r2]: / trunk / loader.py  Maximize  Restore  History

Download this file

92 lines (73 with data), 3.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
""" @file
Application entry class. It also will be startup class when freezing.
The database is used to:
1, Store final scan result
2, Store scaned file list for incremental build.
Copyright 2012 Lu, Ken (bluewish.ken.lu@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
import logging
import traceback
from optparse import OptionParser
def get_app_path():
""" Get dir path of this file. """
if hasattr(sys, "frozen"):
app_path = os.path.abspath(os.path.dirname(sys.executable))
else:
app_path = os.path.abspath(os.path.dirname(__file__))
return app_path
def setup():
""" Setup the running environment. """
# search the clang.dll
app_root_path = get_app_path()
if not os.path.exists(os.path.join(app_root_path, "libs", "libclang.dll")):
print "fail to find libclang.dll in %s" % os.path.join(app_root_path, "libs")
return False
# add clang.dll into system path
os.environ['path'] = os.environ['path'] + ";" + os.path.join(app_root_path, "libs")
logging.basicConfig(level=logging.NOTSET, format='%(asctime)-20s %(name)-10s %(levelname)-8s%(message)s')
return True
if __name__ == "__main__":
if not setup():
sys.exit(-1)
parser = OptionParser("usage: %prog [options] {configure filename}")
parser.add_option("-r", "--rule-file", dest="rule_file",
help="Specify the rule file", default=None)
parser.disable_interspersed_args()
(opts, args) = parser.parse_args()
if len(args) == 0:
parser.error("Please specify the configure file.")
conf_file = args[0]
if not os.path.exists(conf_file):
parser.error("fail to find the configure file %s" % conf_file)
rule_file = None
if opts.rule_file != None and not os.path.exists(opts.rule_file):
parser.error("fail to find given rule file %s" % opts.rule_file)
else:
rule_file = opts.rule_file
# if did not specify the rule file use internal default rule file
if rule_file == None:
rule_file = os.path.join(get_app_path(), "rule_default.txt")
if not os.path.exists(rule_file):
parser.error("fail to find default rule file, please specify rule file via --rule-file")
logging.getLogger().warning("Use default rule file %s since no specify the rule file via --rule-file" % rule_file)
# the dll path has been added into system path,
# we can import csc and cppadapter now
import csc
import cppadapter
try:
csc_obj = csc.CodingStyleChecker(rule_file, conf_file, cppadapter.CodingStyleCheckerAdapterCpp)
csc_obj.execute()
except Exception as ex:
logging.getLogger().error("".join(traceback.format_exception(*sys.exc_info())))
print ex
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.