forked from mathiasertl/django-ca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
61 lines (41 loc) · 1.52 KB
/
common.py
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
#!/usr/bin/env python3
#
# This file is part of django-ca (https://github.com/mathiasertl/django-ca).
#
# django-ca is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# django-ca is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with django-ca. If not,
# see <http://www.gnu.org/licenses/>.
"""Common functions for various top-level utility scripts."""
import os
import sys
import django
try:
from termcolor import colored
except ImportError:
def colored(msg, *args, **kwargs):
return msg
ROOTDIR = os.path.dirname(os.path.realpath(__file__))
CADIR = os.path.join(ROOTDIR, 'ca')
if CADIR not in sys.path:
sys.path.insert(0, CADIR)
def setup_django(settings_module="ca.test_settings"):
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
django.setup()
def error(msg, **kwargs):
print(colored(msg, 'red'), **kwargs)
def warn(msg, **kwargs):
print(colored(msg, 'yellow'), **kwargs)
def ok(msg=' OK.', **kwargs):
print(colored(msg, 'green'), **kwargs)
def bold(msg):
return colored(msg, attrs=['bold'])
def abort(msg):
print(msg)
sys.exit(1)