Completed
Push — master ( b31afe...1fc8cc )
by Chris
20:13
created

call_and_write_log   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 17
dl 0
loc 49
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
# Copyright 2018 by Christopher C. Little.
5
# This file is part of Abydos.
6
#
7
# Abydos is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Abydos is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Abydos. If not, see <http://www.gnu.org/licenses/>.
19
20
"""call_and_write_log.py
21
22
This helper script takes one argument, a call to pylint, pycodestyle,
23
or flake8. It captures stdout and writes it to a log file.
24
25
The reason for this script to exist is as a workaround for tox
26
not supporting writing to files, even though I want it to do that
27
to maintain logs & create badges.
28
"""
29
import os, sys
30
31
from subprocess import call
32
33
const_ret = None
34
if len(sys.argv) > 2:
35
    try:
36
        const_ret = int(sys.argv[2])
37
    except ValueError:
38
        pass
39
40
retval = 1
41
if len(sys.argv) > 1:
42
    args = sys.argv[1].split()
43
    if args[0] not in {'pylint', 'pycodestyle', 'flake8'}:
44
        sys.exit(const_ret if const_ret is not None else retval)
45
    with open(args[0]+'.log', 'w') as output:
46
        retval = call(args, stdout=output)
47
    #os.system(' '.join(args) + ' > ' + args[0]+'.log')
48
    sys.exit(const_ret if const_ret is not None else retval)
49
50