-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutility.py
43 lines (33 loc) · 1.45 KB
/
utility.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
#!/usr/bin/python2
# ################################################################################################ #
# Utility Functions for Scripting #
# Author: Lazar Sumar #
# Date: 23/01/2015 #
# ################################################################################################ #
import sys
import time
class Logger(object):
def __init__(self):
self.referenceTime = None
self.isDbgEnabled = False
self.isInfoEnabled = True
self.isErrEnabled = True
def _FormatMessage(self, messages):
if self.referenceTime is not None:
outMessage = '# {0: >6.2f}s: '.format(time.clock() - self.referenceTime)
else:
outMessage = ''
outMessage += ' '.join([str(x) for x in messages])
return outMessage
def info(self, *message):
if self.isInfoEnabled:
print(self._FormatMessage(message))
def dbg(self, *message):
if self.isDbgEnabled:
print(self._FormatMessage(message))
def error(self, *message):
if self.isErrEnabled:
sys.stderr.write(self._FormatMessage(message))
sys.stderr.write("\n")
def toPosixPath(path):
return path.replace('\\', '/')