Move path creation into configpaths module
This commit is contained in:
parent
124e501f26
commit
8306f076b3
|
@ -1,50 +0,0 @@
|
||||||
# -*- coding:utf-8 -*-
|
|
||||||
## src/common/check_paths.py
|
|
||||||
##
|
|
||||||
## Copyright (C) 2005-2006 Travis Shirk <travis AT pobox.com>
|
|
||||||
## Nikos Kouremenos <kourem AT gmail.com>
|
|
||||||
## Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
||||||
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
||||||
## Copyright (C) 2007 Tomasz Melcer <liori AT exroot.org>
|
|
||||||
## Copyright (C) 2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
||||||
##
|
|
||||||
## This file is part of Gajim.
|
|
||||||
##
|
|
||||||
## Gajim is free software; you can redistribute it and/or modify
|
|
||||||
## it under the terms of the GNU General Public License as published
|
|
||||||
## by the Free Software Foundation; version 3 only.
|
|
||||||
##
|
|
||||||
## Gajim is distributed in the hope that it will be useful,
|
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
## GNU General Public License for more details.
|
|
||||||
##
|
|
||||||
## You should have received a copy of the GNU General Public License
|
|
||||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from gajim.common import configpaths
|
|
||||||
from gajim.common.const import PathType
|
|
||||||
|
|
||||||
|
|
||||||
def check_and_possibly_create_paths():
|
|
||||||
for path in configpaths.get_paths(PathType.FOLDER):
|
|
||||||
if not os.path.exists(path):
|
|
||||||
create_path(path)
|
|
||||||
elif os.path.isfile(path):
|
|
||||||
print(_('%s is a file but it should be a directory') % path)
|
|
||||||
print(_('Gajim will now exit'))
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
def create_path(directory):
|
|
||||||
head, tail = os.path.split(directory)
|
|
||||||
if not os.path.exists(head):
|
|
||||||
create_path(head)
|
|
||||||
if os.path.exists(directory):
|
|
||||||
return
|
|
||||||
print(('creating %s directory') % directory)
|
|
||||||
os.mkdir(directory, 0o700)
|
|
|
@ -24,7 +24,9 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from gajim.common.const import PathType, PathLocation
|
from gajim.common.const import PathType, PathLocation
|
||||||
|
|
||||||
|
@ -57,6 +59,28 @@ def init():
|
||||||
_paths.init()
|
_paths.init()
|
||||||
|
|
||||||
|
|
||||||
|
def create_paths():
|
||||||
|
for path in get_paths(PathType.FOLDER):
|
||||||
|
if not isinstance(path, Path):
|
||||||
|
path = Path(path)
|
||||||
|
|
||||||
|
if path.is_file():
|
||||||
|
print(_('%s is a file but it should be a directory') % path)
|
||||||
|
print(_('Gajim will now exit'))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if not path.exists():
|
||||||
|
for parent_path in reversed(path.parents):
|
||||||
|
# Create all parent folders
|
||||||
|
# dont use mkdir(parent=True), as it ignores `mode`
|
||||||
|
# when creating the parents
|
||||||
|
if not parent_path.exists():
|
||||||
|
print(('creating %s directory') % parent_path)
|
||||||
|
parent_path.mkdir(mode=0o700)
|
||||||
|
print(('creating %s directory') % path)
|
||||||
|
path.mkdir(mode=0o700)
|
||||||
|
|
||||||
|
|
||||||
class ConfigPaths:
|
class ConfigPaths:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._paths = {}
|
self._paths = {}
|
||||||
|
|
|
@ -156,12 +156,11 @@ class GajimApplication(Gtk.Application):
|
||||||
|
|
||||||
# Create and initialize Application Paths & Databases
|
# Create and initialize Application Paths & Databases
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import check_paths
|
configpaths.create_paths()
|
||||||
from gajim.common import exceptions
|
from gajim.common import exceptions
|
||||||
from gajim.common import logger
|
from gajim.common import logger
|
||||||
from gajim.common import caps_cache
|
from gajim.common import caps_cache
|
||||||
try:
|
try:
|
||||||
check_paths.check_and_possibly_create_paths()
|
|
||||||
app.logger = logger.Logger()
|
app.logger = logger.Logger()
|
||||||
caps_cache.initialize(app.logger)
|
caps_cache.initialize(app.logger)
|
||||||
except exceptions.DatabaseMalformed as error:
|
except exceptions.DatabaseMalformed as error:
|
||||||
|
|
Loading…
Reference in New Issue