|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
# ----------------------------------------------------------------------------- |
|
4
|
|
|
# Copyright (c) 2015 Yann Lanthony |
|
5
|
|
|
# Copyright (c) 2017-2018 Spyder Project Contributors |
|
6
|
|
|
# |
|
7
|
|
|
# Licensed under the terms of the MIT License |
|
8
|
|
|
# (See LICENSE.txt for details) |
|
9
|
|
|
# ----------------------------------------------------------------------------- |
|
10
|
|
|
"""qtsass command line interface.""" |
|
11
|
|
|
|
|
12
|
|
|
# Standard library imports |
|
13
|
|
|
from __future__ import absolute_import, print_function |
|
14
|
|
|
import argparse |
|
15
|
|
|
import os |
|
16
|
|
|
import time |
|
17
|
|
|
import logging |
|
18
|
|
|
|
|
19
|
|
|
# Third party imports |
|
20
|
|
|
from watchdog.observers import Observer |
|
21
|
|
|
|
|
22
|
|
|
# Local imports |
|
23
|
|
|
from qtsass.api import compile_and_save |
|
24
|
|
|
from qtsass.events import SourceModificationEventHandler |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
28
|
|
|
_log = logging.getLogger(__name__) |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def main_parser(): |
|
32
|
|
|
"""Create qtsass's cli parser.""" |
|
33
|
|
|
|
|
34
|
|
|
parser = argparse.ArgumentParser( |
|
35
|
|
|
prog='QtSASS', |
|
36
|
|
|
description='Compile a Qt compliant CSS file from a SASS stylesheet.', |
|
37
|
|
|
) |
|
38
|
|
|
parser.add_argument('input', type=str, help='The SASS stylesheet file.') |
|
39
|
|
|
parser.add_argument( |
|
40
|
|
|
'-o', |
|
41
|
|
|
'--output', |
|
42
|
|
|
type=str, |
|
43
|
|
|
help='The path of the generated Qt compliant CSS file.' |
|
44
|
|
|
) |
|
45
|
|
|
parser.add_argument( |
|
46
|
|
|
'-w', |
|
47
|
|
|
'--watch', |
|
48
|
|
|
action='store_true', |
|
49
|
|
|
help='If set, recompile when the source file changes.' |
|
50
|
|
|
) |
|
51
|
|
|
return parser |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
def main(): |
|
55
|
|
|
"""qtsass's cli entry point.""" |
|
56
|
|
|
|
|
57
|
|
|
args = main_parser().parse_args() |
|
58
|
|
|
compile_and_save(args.input, args.output) |
|
59
|
|
|
|
|
60
|
|
|
if args.watch: |
|
61
|
|
|
watched_dir = os.path.abspath(os.path.dirname(args.input)) |
|
62
|
|
|
event_handler = SourceModificationEventHandler( |
|
63
|
|
|
args.input, |
|
64
|
|
|
args.output, |
|
65
|
|
|
watched_dir, |
|
66
|
|
|
compile_and_save |
|
67
|
|
|
) |
|
68
|
|
|
_log.info('qtsass is watching {}...'.format(args.input)) |
|
|
|
|
|
|
69
|
|
|
observer = Observer() |
|
70
|
|
|
observer.schedule(event_handler, watched_dir, recursive=False) |
|
71
|
|
|
observer.start() |
|
72
|
|
|
try: |
|
73
|
|
|
while True: |
|
74
|
|
|
time.sleep(1) |
|
75
|
|
|
except KeyboardInterrupt: |
|
76
|
|
|
observer.stop() |
|
77
|
|
|
observer.join() |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if __name__ == '__main__': |
|
81
|
|
|
main() |
|
82
|
|
|
|
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.