[go: up one dir, main page]

Menu

[dfe9bc]: / startup / startup.py  Maximize  Restore  History

Download this file

64 lines (48 with data), 1.9 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
# ******************************************************
# * Copyright © 2017-2023 - Jordan Irwin (AntumDeluge) *
# ******************************************************
# * This software is licensed under the MIT license. *
# * See: LICENSE.txt for details. *
# ******************************************************
## App initialization checks.
#
# @module startup.startup
import os
from libdbr import config
from libdbr import fileio
from libdbr import logger
from libdbr import paths
from libdebreate import appinfo
__logger = logger.Logger(__name__)
initialized = False
## Sets log file.
def initLogging():
__logger.startLogging(paths.join(paths.getUserDataRoot(), "debreate/logs"))
__logger.info("logging to file '{}'".format(__logger.getLogFile()))
## Sets configuration file.
#
# @return
# `True` if new config file must be created.
def initConfig():
first_run = True
conf_root = paths.getUserConfigRoot()
file_cfg_legacy = paths.join(conf_root, "debreate", "config")
file_cfg = paths.join(paths.join(conf_root, "debreate.conf"))
if os.path.isfile(file_cfg_legacy) and not os.path.exists(file_cfg):
__logger.debug("moving old config '{}' to '{}'".format(file_cfg_legacy, file_cfg))
fileio.moveFile(file_cfg_legacy, file_cfg)
# clean up old directory
dir_cfg_legacy = os.path.dirname(file_cfg_legacy)
if len(os.listdir(dir_cfg_legacy)) == 0:
fileio.deleteDir(dir_cfg_legacy)
if os.path.isfile(file_cfg):
__logger.info("loading config from '{}'".format(file_cfg))
first_run = False
# initialize configuration file
cfg_user = config.add("user", file_cfg)
global initialized
initialized = True
if appinfo.isPortable():
__logger.info("running in portable mode")
cfg_user.setValue("portable", True)
return first_run