-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
38 lines (27 loc) · 935 Bytes
/
utils.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
from __future__ import (absolute_import, division,
print_function, unicode_literals)
import collections
import csv
import os
from settings import settings
SCRIPT_LOCATION = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
CONF_CSV_QUOTING_MAP = {
"minimal": csv.QUOTE_MINIMAL,
"all": csv.QUOTE_ALL,
"nonnumeric": csv.QUOTE_NONNUMERIC,
"none": csv.QUOTE_NONE
}
def get_csv_quoting_conf():
s = settings['csv']['quoting']
return CONF_CSV_QUOTING_MAP[s]
def smart_true(v):
return v.lower() in ('true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly')
def get_csv_conf():
return {
'sep': settings['csv']['separator'],
'quoting': get_csv_quoting_conf(),
'quotechar': settings['csv']['quotechar'],
'doublequote': smart_true(settings['csv']['doublequote']),
'escapechar': settings['csv']['escapechar'],
}