-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathglobs.py
97 lines (85 loc) · 3.77 KB
/
globs.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#####
#
# Module name: globs.py
# Purpose: Global object repository for use by dupReport program
#
#####
import os
# Define version info
version=[3,0,10] # Program Version
status='Release'
dbVersion=[3,0,1] # Required DB version
rcVersion=[3,1,0] # Required RC version
copyright='Copyright (c) 2017-2022 Stephen Fried for Handy Guy Software.'
# Define global variables
dbName='dupReport.db' # Default database name
logName='dupReport.log' # Default log file name
rcName='dupReport.rc' # Default configuration file name
db = None # Global database object
dateFormat = None # Global date format - can be overridden per backup set
timeFormat = None # Global time format - can be overridden per backup set
report = None # Global report object
ofileList = None # List of output files
optionManager = None # Global Option Manager
emailManager = None # Global email server management
opts = None # Global program options
progPath = None # Path to script files
appriseObj = None # dupApprise instance
# Text & format fields for report email
emailText=[] # List of email text components
emailFormat=[] # Corresponding list of emial components print formats
# Global variables referencing objects in other modules
log = None # Log file handling
inServer = None # Inbound email server
outServer = None # Outbound email server
# Define logging levels
SEV_EMERGENCY = 0
SEV_ALERT = 1
SEV_CRITICAL = 2
SEV_ERROR = 3
SEV_WARNING = 4
SEV_NOTICE = 5
SEV_INFO = 6
SEV_DEBUG = 7
sevlevels = [
('EMERGENCY', SEV_EMERGENCY),
('ALERT', SEV_ALERT),
('CRITICAL', SEV_CRITICAL),
('ERROR', SEV_ERROR),
('WARNING', SEV_WARNING),
('NOTICE', SEV_NOTICE),
('INFO', SEV_INFO),
('DEBUG', SEV_DEBUG)
]
# Mask sensitive data in log files
# Replace incoming string with string of '*' the same length of the original
def maskData(inData, force = False):
if inData is None: # Empty input or global options haven't been processed yet. Return unmasked input.
return inData
elif force: # Mask regardless of what parameter says. Useful if masking before options are processed.
return "*" * len(inData)
elif opts is None:
return inData
elif 'masksensitive' in opts and opts['masksensitive'] is True:
return "*" * len(inData) # Mask data.
else:
return inData # Return unmasked input
# Close everything and exit cleanly
def closeEverythingAndExit(errcode):
log.write(SEV_NOTICE, function='Globs', action='closeEverythingAndExit', msg='Closing everything...')
if emailManager != None:
if len(emailManager.incoming) != 0:
for server in emailManager.incoming:
log.write(SEV_NOTICE, function='Globs', action='closeEverythingAndExit', msg='Closing inbound email server: {}'.format(emailManager.incoming[server].name))
emailManager.incoming[server].close()
if len(emailManager.incoming) != 0:
for i in range(len(emailManager.outgoing)):
log.write(SEV_NOTICE, function='Globs', action='closeEverythingAndExit', msg='Closing outbound email server: {}'.format(emailManager.outgoing[i].name))
emailManager.outgoing[i].close()
if db is not None:
log.write(SEV_NOTICE, function='Globs', action='closeEverythingAndExit', msg='Closing database file.')
db.dbClose()
if log is not None:
log.write(SEV_NOTICE, function='Globs', action='closeEverythingAndExit', msg='Closing log file.')
log.closeLog()
os._exit(errcode)