mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-28 14:50:14 +03:00
Fix xdg-users-dirs getting for shortcuts
This commit is contained in:
parent
2f3fb8810e
commit
62f3c5dd96
@ -51,12 +51,8 @@ def write_shortcut(shortcut, username=None):
|
||||
if not dest_abspath.startswith('/') and not dest_abspath.startswith('%'):
|
||||
dest_abspath = '%HOME%/' + dest_abspath
|
||||
|
||||
logging.debug(slogm('Try to expand path for shortcut: {} for {}'.format(dest_abspath, username)))
|
||||
dest_abspath = expand_windows_var(dest_abspath, username).replace('\\', '/') + '.desktop'
|
||||
# If the resulting path is not absolute then operate in home
|
||||
# directory
|
||||
if not dest_abspath.startswith('/'):
|
||||
if username:
|
||||
dest_abspath = get_homedir(username) + dest_abspath
|
||||
|
||||
# Check that we're working for user, not on global system level
|
||||
if username:
|
||||
@ -67,11 +63,18 @@ def write_shortcut(shortcut, username=None):
|
||||
if not homedir_exists(username):
|
||||
logging.warning(slogm('No home directory exists for user {}: will not create link {}'.format(username, dest_abspath)))
|
||||
return None
|
||||
else:
|
||||
logging.warning(slogm('User\'s shortcut not placed to home directory for {}: bad path {}'.format(username, dest_abspath)))
|
||||
return None
|
||||
|
||||
if '%' in dest_abspath:
|
||||
logging.debug(slogm('Fail for writing shortcut to file with \'%\': {}'.format(dest_abspath)))
|
||||
return None
|
||||
|
||||
if not dest_abspath.startswith('/'):
|
||||
logging.debug(slogm('Fail for writing shortcut to not absolute path \'%\': {}'.format(dest_abspath)))
|
||||
return None
|
||||
|
||||
logging.debug(slogm('Writing shortcut file to {}'.format(dest_abspath)))
|
||||
shortcut.write_desktop(dest_abspath)
|
||||
|
||||
|
@ -30,8 +30,7 @@ import pysss_nss_idmap
|
||||
|
||||
from storage import cache_factory
|
||||
from .xdg import (
|
||||
get_user_dir
|
||||
, xdg_get_desktop_user
|
||||
xdg_get_desktop
|
||||
)
|
||||
from .util import get_homedir
|
||||
from .logging import slogm
|
||||
@ -181,7 +180,7 @@ def expand_windows_var(text, username=None):
|
||||
variables['SystemRoot'] = '/'
|
||||
variables['StartMenuDir'] = '/usr/share/applications'
|
||||
variables['SystemDrive'] = '/'
|
||||
variables['DesktopDir'] = xdg_get_desktop_user(username)
|
||||
variables['DesktopDir'] = xdg_get_desktop(username, variables['HOME'])
|
||||
|
||||
if username:
|
||||
variables['HOME'] = get_homedir(username)
|
||||
|
@ -17,38 +17,20 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from configparser import RawConfigParser, DEFAULTSECT
|
||||
import os
|
||||
from xdg.BaseDirectory import xdg_config_home
|
||||
|
||||
from .util import get_homedir
|
||||
from .logging import slogm
|
||||
|
||||
from .users import with_privileges
|
||||
def xdg_get_desktop(username, homedir = None):
|
||||
if username:
|
||||
homedir = get_homedir(username)
|
||||
if not homedir:
|
||||
logging.warning(
|
||||
slogm('Error for get XDG_DESKTOP_DIR for unknown user with unknown homedir'))
|
||||
raise "Error for get XDG_DESKTOP_DIR for unknown user with unknown homedir"
|
||||
|
||||
|
||||
def get_user_dir(dir_name, default=None):
|
||||
'''
|
||||
Get path to XDG's user directory
|
||||
'''
|
||||
config = RawConfigParser(allow_no_value=True)
|
||||
userdirs_path = os.path.join(xdg_config_home, 'user-dirs.dirs')
|
||||
try:
|
||||
with open(userdirs_path, 'r') as f:
|
||||
config.read_string('[DEFAULT]\n' + f.read())
|
||||
return config.get(DEFAULTSECT, 'XDG_DESKTOP_DIR')
|
||||
except Exception as exc:
|
||||
return default
|
||||
|
||||
def xdg_get_desktop_user(username):
|
||||
if not username:
|
||||
name = 'root'
|
||||
desktop_full_path = with_privileges(name, xdg_get_desktop)
|
||||
return '/etc/skel/{}'.format(desktop_full_path.rpartition('/')[2])
|
||||
|
||||
return xdg_get_desktop()
|
||||
|
||||
def xdg_get_desktop():
|
||||
stream = os.popen('source /etc/locale.conf; xdg-user-dir DESKTOP')
|
||||
stream = os.popen('export HOME={}; xdg-user-dir DESKTOP'.format(homedir))
|
||||
output = stream.read()[:-1]
|
||||
print(output)
|
||||
return output
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user