-
Notifications
You must be signed in to change notification settings - Fork 15
/
pyastviewer
executable file
·72 lines (54 loc) · 2.74 KB
/
pyastviewer
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
#!/usr/bin/env python
"""
Program that shows the program on the right and its abstract syntax tree (ast) on the left.
"""
from __future__ import print_function
import os
#os.environ.setdefault('QT_API', 'pyside')
#os.environ.setdefault('QT_API', 'pyqt5')
import sys, argparse, logging
from astviewer.qtpy import QtCore, QtWidgets
from astviewer.misc import logging_basic_config, handleException
from astviewer.misc import PROGRAM_NAME, PROGRAM_VERSION, PYTHON_VERSION, QT_API_NAME, QT_API
from astviewer.main import view
logger = logging.getLogger(__name__)
sys.excepthook = handleException
def main():
""" Main program to test stand alone
"""
parser = argparse.ArgumentParser(description='Python abstract syntax tree viewer')
parser.add_argument(dest='file_name', help='Python input file', nargs='?')
parser.add_argument('-m', '--mode', dest='mode', default = 'exec',
choices = ('exec', 'eval', 'single'),
help = """The mode argument specifies what kind of code must be compiled;
it can be 'exec' if source consists of a sequence of statements,
'eval' if it consists of a single expression, or 'single' if it
consists of a single interactive statement (in the latter case,
expression statements that evaluate to something other than None
will be printed). """)
parser.add_argument('-l', '--log-level', dest='log_level', default = 'warn',
choices = ('debug', 'info', 'warn', 'error', 'critical'),
help = "Log level. Only log messages with a level higher or equal than this "
"will be printed. Default: 'warn'")
parser.add_argument('--reset', dest='reset', action="store_true",
help = """If given, the persistent settings, such as window position and size,
will be reset to their default values.""")
parser.add_argument('-v', '--version', action = 'store_true',
help="Prints the program version.")
args = parser.parse_args()
logging_basic_config(args.log_level.upper())
if args.version:
print('{} {}'.format(PROGRAM_NAME, PROGRAM_VERSION))
sys.exit(0)
logger.info('Started {} {}'.format(PROGRAM_NAME, PROGRAM_VERSION))
logger.info('Using Python {} and {} (api={})'.format(PYTHON_VERSION, QT_API_NAME, QT_API))
try:
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
except Exception as ex:
logger.debug("AA_UseHighDpiPixmaps not available in PyQt4: {}".format(ex))
_app = QtWidgets.QApplication([])
exit_code = view(file_name = args.file_name, mode = args.mode, reset = args.reset)
logging.info('Done {}'.format(PROGRAM_NAME))
sys.exit(exit_code)
if __name__ == '__main__':
main()