mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-01-25 02:04:18 +03:00
Shortcuts fixes and improvements
- It was found that shortcut files must be executable in order to work correctly - Added some checks for URL links. This should allow to create links pointing to network shares.
This commit is contained in:
parent
eb9a801b32
commit
59ccecd457
@ -15,7 +15,10 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from pathlib import Path
|
||||
import stat
|
||||
import logging
|
||||
from enum import Enum
|
||||
|
||||
from xml.etree import ElementTree
|
||||
from xdg.DesktopEntry import DesktopEntry
|
||||
@ -24,18 +27,45 @@ import json
|
||||
from util.windows import transform_windows_path
|
||||
from util.xml import get_xml_root
|
||||
|
||||
class TargetType(Enum):
|
||||
FILESYSTEM = 'FILESYSTEM'
|
||||
URL = 'URL'
|
||||
|
||||
def get_ttype(targetstr):
|
||||
'''
|
||||
Validation function for targetType property
|
||||
|
||||
:targetstr: String representing link type.
|
||||
|
||||
:returns: Object of type TargetType.
|
||||
'''
|
||||
ttype = TargetType.FILESYSTEM
|
||||
|
||||
if targetstr == 'URL':
|
||||
ttype = TargetType.URL
|
||||
|
||||
return ttype
|
||||
|
||||
def read_shortcuts(shortcuts_file):
|
||||
'''
|
||||
Read shortcut objects from GPTs XML file
|
||||
|
||||
:shortcuts_file: Location of Shortcuts.xml
|
||||
'''
|
||||
shortcuts = list()
|
||||
|
||||
for link in get_xml_root(shortcuts_file):
|
||||
props = link.find('Properties')
|
||||
# Location of the link itself
|
||||
dest = props.get('shortcutPath')
|
||||
# Location where link should follow
|
||||
path = transform_windows_path(props.get('targetPath'))
|
||||
# Arguments to executable file
|
||||
arguments = props.get('arguments')
|
||||
sc = shortcut(dest, path, arguments, link.get('name'))
|
||||
# URL or FILESYSTEM
|
||||
target_type = get_ttype(props.get('targetType'))
|
||||
|
||||
sc = shortcut(dest, path, arguments, link.get('name'), target_type)
|
||||
sc.set_changed(link.get('changed'))
|
||||
sc.set_clsid(link.get('clsid'))
|
||||
sc.set_guid(link.get('uid'))
|
||||
@ -59,13 +89,21 @@ def json2sc(json_str):
|
||||
return sc
|
||||
|
||||
class shortcut:
|
||||
def __init__(self, dest, path, arguments, name=None):
|
||||
def __init__(self, dest, path, arguments, name=None, ttype='FILESYSTEM'):
|
||||
'''
|
||||
:param dest: Path to resulting file on file system
|
||||
:param path: Path where the link should point to
|
||||
:param arguments: Arguemnts to eecutable file
|
||||
:param name: Name of the application
|
||||
:param type: Link type - FILESYSTEM or URL
|
||||
'''
|
||||
self.dest = dest
|
||||
self.path = path
|
||||
self.arguments = arguments
|
||||
self.name = name
|
||||
self.changed = ''
|
||||
self.is_in_user_context = self.set_usercontext()
|
||||
self.type = ttype
|
||||
|
||||
def __str__(self):
|
||||
result = self.to_json()
|
||||
@ -83,6 +121,14 @@ class shortcut:
|
||||
def set_guid(self, uid):
|
||||
self.guid = uid
|
||||
|
||||
def set_type(self, ttype):
|
||||
'''
|
||||
Set type of the hyperlink - FILESYSTEM or URL
|
||||
|
||||
:ttype: - object of class TargetType
|
||||
'''
|
||||
self.type = ttype
|
||||
|
||||
def set_usercontext(self, usercontext=False):
|
||||
'''
|
||||
Perform action in user context or not
|
||||
@ -122,17 +168,30 @@ class shortcut:
|
||||
'''
|
||||
self.desktop_file = DesktopEntry()
|
||||
self.desktop_file.addGroup('Desktop Entry')
|
||||
self.desktop_file.set('Type', 'Application')
|
||||
|
||||
if self.type == TargetType.URL
|
||||
self.desktop_file.set('Type', 'Link')
|
||||
else:
|
||||
self.desktop_file.set('Type', 'Application')
|
||||
|
||||
self.desktop_file.set('Version', '1.0')
|
||||
self.desktop_file.set('Terminal', 'false')
|
||||
self.desktop_file.set('Exec', '{} {}'.format(self.path, self.arguments))
|
||||
self.desktop_file.set('Name', self.name)
|
||||
|
||||
if self.type == TargetType.URL:
|
||||
self.desktop_file.set('URL', self.path)
|
||||
else:
|
||||
self.desktop_file.set('Terminal', 'false')
|
||||
self.desktop_file.set('Exec', '{} {}'.format(self.path, self.arguments))
|
||||
|
||||
return self.desktop_file
|
||||
|
||||
def write_desktop(self, dest):
|
||||
'''
|
||||
Write .desktop file to disk using path 'dest'
|
||||
Write .desktop file to disk using path 'dest'. Please note that
|
||||
.desktop files must have executable bit set in order to work in
|
||||
GUI.
|
||||
'''
|
||||
self.desktop().write(dest)
|
||||
sc = Path(dest)
|
||||
sc.chmod(sc.stat().st_mode | stat.S_IEXEC)
|
||||
|
||||
|
8
gpoa/test/files/share.desktop
Executable file
8
gpoa/test/files/share.desktop
Executable file
@ -0,0 +1,8 @@
|
||||
[Desktop Entry]
|
||||
Type=Link
|
||||
Version=1.0
|
||||
Name=Docs
|
||||
GenericName=Link to CIFS disk
|
||||
Comment=Link to Samba share
|
||||
URL=smb://10.0.0.0/
|
||||
|
Loading…
x
Reference in New Issue
Block a user