Newer
Older
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 os
import platform
import logging
import sys
def isWindows():
returnValue = False
windowsName = "Windows"
platformName = platform.system()
if platformName == windowsName:
returnValue = True
# osName = os.name
# supportedWindowsNames = ["nt"]
# if osName in supportedWindowsNames:
# returnValue = True
return returnValue
def isLinux():
returnValue = False
linuxName = "Linux"
platformName = platform.system()
if platformName == linuxName:
returnValue = True
return returnValue
def isPosix():
osName = os.name
supportedPosixNames = ["posix"]
returnValue = False
if osName in supportedPosixNames:
returnValue = True
return returnValue
def isSupported():
supportedWindowsReleases = ["7"]
osRelease = platform.release()
supportValue = False
#check windows
if isWindows():
supportValue = True
# if osRelease in supportedWindowsReleases:
# supportValue = True
#check linux
if isLinux():
supportValue = True
return supportValue
def checkFolderExistance(folderPath):
"""
abort if folder does not exist
:return:
"""
#check folder path for existance. exits if it does not exist
if not os.path.exists(folderPath):
logging.error("Folder '%s' does not exist. Abort." % str(folderPath))
sys.exit(1)
def checkLogFileWritable(filepath, filename):
#error if logfile cannot be written
try:
fullPath = os.path.join(filepath, filename)
logFile = open(fullPath, "a")
except:
print "Unable to create the logfile """ + str(fullPath)
print """Please specify a new target by setting the following arguments:
--logfileName
--logfilePath
"""
sys.exit(1)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def initLogging(filenameFullPath, verbose):
#@see https://docs.python.org/2/howto/logging-cookbook.html
# def initLogging(self, logfilePath, verbose):
#
# logfilePathFull = os.path.join(logfilePath, "cleaner.log")
#more detailed logging if verbose-option has been set
loggingLevel = logging.INFO
if verbose:
loggingLevel = logging.DEBUG
#log everything to file
logging.basicConfig(level=loggingLevel,
format='[%(asctime)s] [PID %(process)d] [%(filename)s] [%(module)s:%(funcName)s:%(lineno)d] [%(name)s] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d_%H:%M:%S',
filename=filenameFullPath,
filemode="a")
# fileHandler = logging.FileHandler(filename=logfilePathFull,
# mode="a")
# fileHandlerFormat = logging.Formatter(datefmt='%Y-%m-%d_%H:%M:%S',
# fmt='[%(asctime)s] [PID %(process)d] [%(filename)s] [%(module)s:%(funcName)s] [%(name)s] [%(levelname)s] %(message)s')
# fileHandler.setFormatter(fileHandlerFormat)
# fileHandler.setLevel(loggingLevel)
# logger.addHandler(fileHandler)
#log info to stdout, display messages with different format than the file output
console = logging.StreamHandler()
console.setLevel(logging.WARNING)
formatter = logging.Formatter("%(asctime)s > %(message)s")
console.setFormatter(formatter)
logging.getLogger("").addHandler(console)