-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
78 lines (58 loc) · 1.91 KB
/
utilities.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import faker
import json
import logging
import logging.handlers
import os
import shortuuid
####################################################
# Logging
####################################################
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)15s - %(levelname)s - %(message)s')
console_handle = logging.StreamHandler()
console_handle.setFormatter(formatter)
logger.addHandler(console_handle)
LOG_FILENAME = "muchamuck.log"
file_handle = logging.handlers.RotatingFileHandler(
LOG_FILENAME, maxBytes=5 * 1024 * 1024, backupCount=5)
file_handle = logging.FileHandler('muchamuck.log')
file_handle.setFormatter(formatter)
logger.addHandler(file_handle)
#logger.info('log message')
####################################################
# System Paths
####################################################
def get_output_root_path():
output_root_path = os.environ['MUCKAMUCK_OUTPUT_DIRECTORY']
return output_root_path
def get_output_json_path():
output_json_path = os.path.join(get_output_root_path(), "json")
return output_json_path
####################################################
# Misc
####################################################
fake = faker.Factory.create()
"""Initialize a faker generator.
This provides all the fake data using in the create dummy functions
"""
def generate_UUID():
"""Generats Shortish UUID.
Returns:
uuid string
"""
return shortuuid.ShortUUID().random()
def jsonifyer(someDict):
"""Provides standardization of pretty json
Args:
someDict (dict): Any JSON compatible dictionary
Returns:
JSON string
"""
return json.dumps(someDict, sort_keys=True, indent=4, separators=(',', ': '))
def make_dir(directory):
"""Nicely make directories.
Checks to see if directory exits before creating
"""
if not os.path.exists(directory):
os.makedirs(directory)