2020-02-11 15:23:09 +04:00
#
# GPOA - GPO Applier for Linux
#
# Copyright (C) 2019-2020 BaseALT Ltd.
#
# This program 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, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
2020-01-15 15:21:47 +04:00
import pathlib
2020-04-14 16:07:32 +04:00
import os
2020-01-15 15:21:47 +04:00
2020-08-20 15:09:40 +04:00
from . config import GPConfig
2020-09-11 14:26:25 +04:00
from . util import get_default_policy_name
2020-08-20 15:09:40 +04:00
2020-01-17 17:58:30 +04:00
2020-01-15 15:21:47 +04:00
def default_policy_path ( ) :
'''
Returns path pointing to Default Policy directory .
'''
2020-09-11 14:26:25 +04:00
local_policy_default = ' /usr/share/local-policy/ {} ' . format ( get_default_policy_name ( ) )
2020-08-20 15:09:40 +04:00
config = GPConfig ( )
2020-04-14 16:07:32 +04:00
result_path = pathlib . Path ( local_policy_default )
2020-08-20 15:09:40 +04:00
if os . path . exists ( config . get_local_policy_template ( ) ) :
result_path = pathlib . Path ( config . get_local_policy_template ( ) )
2020-04-14 16:07:32 +04:00
return pathlib . Path ( result_path )
2020-01-15 15:21:47 +04:00
2020-01-17 17:58:30 +04:00
2020-01-15 15:21:47 +04:00
def cache_dir ( ) :
'''
Returns path pointing to gpupdate ' s cache directory
'''
cachedir = pathlib . Path ( ' /var/cache/gpupdate ' )
if not cachedir . exists ( ) :
cachedir . mkdir ( parents = True , exist_ok = True )
return cachedir
2020-01-17 17:58:30 +04:00
2020-01-15 15:21:47 +04:00
def local_policy_cache ( ) :
'''
Returns path to directory where lies local policy settings cache
transformed into GPT .
'''
lpcache = pathlib . Path . joinpath ( cache_dir ( ) , ' local-policy ' )
if not lpcache . exists ( ) :
lpcache . mkdir ( parents = True , exist_ok = True )
return lpcache