-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
107 lines (85 loc) · 4.36 KB
/
run.py
File metadata and controls
107 lines (85 loc) · 4.36 KB
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
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
'''
Created on 21 mars 2014
@author: S0087931
'''
import logging
import logging.config
from logging.handlers import TimedRotatingFileHandler
from os.path import os, sys, normpath, normcase
from com.nestof.domocore import enumeration
from com.nestof.domocore import utils
from com.nestof.domocore.service.DatabaseService import DatabaseService
from com.nestof.domocore.service.MCZProtocolService import MCZProtocolService
from com.nestof.domocore.service.MCZService import MCZService
if __name__ == '__main__':
print("****************************************************************************")
print("** " + str(utils.getCurrentDateTime()) + " **")
print("****************************************************************************")
if sys.platform.startswith('linux') :
configFilename = 'domocore.cfg'
from com.nestof.domocore.service.TempService import Tmp102
from com.nestof.domocore.service.TempService import Degrade
try:
tempService = Tmp102()
except Exception as e:
tempService = Degrade()
from ConfigParser import ConfigParser
elif sys.platform.startswith('win') :
configFilename = 'domocoreDev.cfg'
from com.nestof.domocore.service.TempServiceDev import TempServiceDev
tempService = TempServiceDev()
from configparser import ConfigParser
else :
print("Unknown Operating System : " + sys.platform)
exit(1)
""" Loading config file """
_configFile = normcase(normpath(os.path.dirname(os.path.abspath(__file__)))) + os.sep + normcase(normpath("conf")) + os.sep + configFilename
if os.path.isfile(_configFile):
try:
with open(_configFile) as file:
pass
except IOError as e:
print ("Unable to open config file " + _configFile) # Does not exist OR no read permissions
exit(1)
else:
print("Config file " + _configFile + " not found")
exit(1)
config = ConfigParser()
config.read(_configFile)
"""Logger configuration """
loggingFilePath = normcase(normpath(config.get('LOGGER', 'logger.path'))) + os.sep
loggingFileName = config.get('LOGGER', 'logger.filename')
logging.basicConfig(filename=loggingFilePath + loggingFileName,\
format='[%(asctime)s][%(levelname)s][%(name)s-%(funcName)s-%(lineno)s] - %(message)s', level=logging.ERROR)
#timedRotatingFileHandler = TimedRotatingFileHandler(loggingFilePath + loggingFileName, 'midnight', interval=1, backupCount=0, encoding='UTF-8', delay=True)
#logging.basicConfig(handlers=[timedRotatingFileHandler], format='[%(asctime)s][%(levelname)s][%(name)s] - %(message)s', level=logging.DEBUG)
# logging.config.fileConfig(normcase(normpath("conf")) + os.sep + "logging.conf")
logger = logging.getLogger(__name__)
logger.info("** Démarrage **")
""" Database configuration """
databasePath = normcase(normpath(config.get('DATABASE', 'database.path'))) + os.sep
databaseFilename = config.get('DATABASE', 'database.filename')
try:
with open(databasePath + databaseFilename) as file:
pass
except IOError as e:
logger.error("Unable to open database " + databasePath + databaseFilename) # Does not exist OR no read permissions
exit(1)
""" Services """
databaseService = DatabaseService(databasePath + databaseFilename)
mczProtocolService = MCZProtocolService(databasePath + databaseFilename)
mczService = MCZService(databaseService, tempService, mczProtocolService, config)
""" Stove configuration """
configurationPoele = databaseService.getConfig()
if (configurationPoele == enumeration.ConfigurationPeole().automatique) :
logger.debug("Launch Automatique Mode...")
mczService.launchAuto()
elif (configurationPoele == enumeration.ConfigurationPeole().manuel) :
logger.debug("Launch Manual Mode...")
mczService.launchManu()
else:
logger.debug("Launch Stop Mode...")
mczService.launchStop()
logger.info("** Terminé **")
exit(0)