Skip to content

Commit

Permalink
Added Desktop Entry file creation for Linux shortcuts to qt installer…
Browse files Browse the repository at this point in the history
… wrapper.
  • Loading branch information
BuvinJ committed Jan 16, 2019
1 parent f4200e8 commit 7cfcdd1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 31 deletions.
12 changes: 9 additions & 3 deletions distbuilder/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def qtIfwPackageScript( self ) :
return QtIfwPackageScript( self.__ifwPkgName(),
fileName=self.ifwScriptName,
exeName=self.binaryName,
exeVersion=self.__versionStr(),
script=self.ifwScriptPath,
srcPath=self.ifwScriptPath )

Expand Down Expand Up @@ -126,8 +127,10 @@ def __init__( self, configFactory,
self.isDesktopTarget = isDesktopTarget
self.isTestingObfuscation = False
self.isTestingExe = False
self.exeTestArgs = []
self.isTestingInstall = False
self.isVerboseInstall = False
self.isElevatedTest = False

def __printHeader( self ):
try:
Expand Down Expand Up @@ -167,7 +170,9 @@ def run( self ):
self.onPyInstConfig( pyInstConfig )
_, binPath = buildExecutable( pyInstConfig=pyInstConfig,
opyConfig=opyConfig )
if self.isTestingExe : run( binPath, isDebug=True )
if self.isTestingExe :
run( binPath, self.exeTestArgs,
isElevated=self.isElevatedTest, isDebug=True )

ifwConfig = self.configFactory.qtIfwConfig()
self.onQtIfwConfig( ifwConfig )
Expand All @@ -176,8 +181,9 @@ def run( self ):
setupPath = moveToDesktop( setupPath )
if self.isTestingInstall :
run( setupPath,
QT_IFW_VERBOSE_SWITCH
if self.isVerboseInstall else None )
(QT_IFW_VERBOSE_SWITCH
if self.isVerboseInstall else None),
isElevated=self.isElevatedTest )

self.__printFooter()

Expand Down
93 changes: 71 additions & 22 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
, "libwinpthread-1.dll"
]

DESKTOP_WIN_SHORTCUT = 0
STARTMENU_WIN_SHORTCUT = 1
STARTMENU_WIN_SHORTCUT = 0
DESKTOP_WIN_SHORTCUT = 1
THIS_USER_STARTUP_WIN_SHORTCUT = 2
ALL_USERS_STARTUP_WIN_SHORTCUT = 3

APPS_X11_SHORTCUT = 0
DESKTOP_X11_SHORTCUT = 1

# -----------------------------------------------------------------------------
class QtIfwConfig:
"""
Expand Down Expand Up @@ -274,20 +277,25 @@ class QtIfwPackageScript:
);
""" )

__X11_ADD_DESKTOP_ENTRY_TMPLT = (
# an example for use down the line...
__LINUX_GET_DISTRIBUTION = (
"""
component.addOperation( "CreateDesktopEntry",
"/usr/share/applications/[APP_NAME].desktop",
"Version=1.0\nType=Application\nTerminal=false\nExec=@TargetDir@/[EXE_NAME]\nName=[APP_NAME]\nIcon=@TargetDir@[APP_ICON_PNG]\nName[en_US]=[APP_NAME]"
);
var IS_UBUNTU = (systemInfo.productType === "ubuntu");
var IS_OPENSUSE = (systemInfo.productType === "opensuse");
""" )

__X11_COPY_DESKTOP_ENTRY_TO_DESKTOP_TMPLT = (
__X11_ADD_DESKTOP_ENTRY_TMPLT = (
"""
component.addElevatedOperation( "Copy",
"/usr/share/applications/[APP_NAME].desktop",
"@HomeDir@/Desktop/[APP_NAME].desktop"
);
component.addOperation( "CreateDesktopEntry",
"[SHORTCUT_PATH]",
"Type=Application\\n"
+ "Terminal=[IS_TERMINAL]\\n"
+ "Exec=bash -c 'cd \\\"[WORKING_DIR]\\\" && \\\"[EXE_PATH]\\\"'\\n"
+ "Name=[LABEL]\\n"
+ "Name[en_US]=[LABEL]\\n"
+ "Version=[VERSION]\\n"
+ "Icon=[PNG_PATH]\\n"
);
""" )

__WIN_SHORTCUT_LOCATIONS = {
Expand All @@ -297,6 +305,12 @@ class QtIfwPackageScript:
, ALL_USERS_STARTUP_WIN_SHORTCUT: "@AllUsersMenuProgramsPath@/Startup"
}

# these may not be correct on all distros?
__X11_SHORTCUT_LOCATIONS = {
DESKTOP_X11_SHORTCUT : "@HomeDir@/Desktop"
, APPS_X11_SHORTCUT : "/usr/share/applications"
}

@staticmethod
def __winAddShortcut( location, exeName,
label="@ProductName@",
Expand All @@ -312,24 +326,47 @@ def __winAddShortcut( location, exeName,
s = s.replace( "[ICON_PATH]", exePath )
s = s.replace( "[ICON_ID]", str(iconId) )
return s

@staticmethod
def __linuxAddDesktopEntry( location, exeName, version,
label="@ProductName@",
directory="@TargetDir@",
pngPath="",
isGui=True ):
exePath = "%s/%s" % (directory, util._normExeName( exeName ))
locDir = QtIfwPackageScript.__X11_SHORTCUT_LOCATIONS[location]
shortcutPath = "%s/%s.desktop" % (locDir, label.replace(" ","_"))
s = QtIfwPackageScript.__X11_ADD_DESKTOP_ENTRY_TMPLT
s = s.replace( "[EXE_PATH]", exePath )
s = s.replace( "[SHORTCUT_PATH]", shortcutPath )
s = s.replace( "[LABEL]", label )
s = s.replace( "[VERSION]", version )
s = s.replace( "[PNG_PATH]", pngPath )
s = s.replace( "[IS_TERMINAL]", "false" if isGui else "true" )
s = s.replace( "[WORKING_DIR]", directory )
return s

def __init__( self, pkgName, fileName=DEFAULT_QT_IFW_SCRIPT_NAME,
exeName=None, script=None, srcPath=None ) :
exeName=None, exeVersion="0.0.0.0",
script=None, srcPath=None ) :
self.pkgName = pkgName
self.fileName = fileName
if srcPath :
with open( srcPath, 'rb' ) as f: self.script = f.read()
else : self.script = script

self.exeName = exeName
self.exeVersion = exeVersion

self.isAppShortcut = True
self.isDesktopShortcut = False

self.componentConstructorBody = None
self.isAutoComponentConstructor = True

self.componentCreateOperationsBody = None
self.isAutoComponentCreateOperations = True
self.exeName = exeName
self.isWinStartMenuShortcut = True
self.isWinDesktopShortcut = False

self.isAutoComponentCreateOperations = True

def __str__( self ) :
if not self.script: self._generate()
return self.script
Expand All @@ -356,16 +393,28 @@ def __genComponentCreateOperationsBody( self ):
self.componentCreateOperationsBody = ""
if IS_WINDOWS:
winOps=""
if self.exeName and self.isWinStartMenuShortcut :
if self.exeName and self.isAppShortcut :
winOps += QtIfwPackageScript.__winAddShortcut(
STARTMENU_WIN_SHORTCUT, self.exeName )
if self.exeName and self.isWinDesktopShortcut:
if self.exeName and self.isDesktopShortcut:
winOps += QtIfwPackageScript.__winAddShortcut(
DESKTOP_WIN_SHORTCUT, self.exeName )
if winOps!="" :
self.componentCreateOperationsBody += (
' if( systemInfo.productType === "windows" ){\n' +
'%s\n }' % (winOps,) )
' if( systemInfo.kernelType === "winnt" ){\n' +
'%s\n }' % (winOps,) )
elif IS_LINUX:
x11Ops = ""
if self.exeName and self.isAppShortcut :
x11Ops += QtIfwPackageScript.__linuxAddDesktopEntry(
APPS_X11_SHORTCUT, self.exeName, self.exeVersion )
if self.exeName and self.isDesktopShortcut:
x11Ops += QtIfwPackageScript.__linuxAddDesktopEntry(
DESKTOP_X11_SHORTCUT, self.exeName, self.exeVersion )
if x11Ops!="" :
self.componentCreateOperationsBody += (
' if( systemInfo.kernelType === "linux" ){\n' +
'%s\n }' % (x11Ops,) )
if self.componentCreateOperationsBody == "" :
self.componentCreateOperationsBody = None

Expand Down
16 changes: 10 additions & 6 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,23 +791,27 @@ automating the generation common script directives.
Constructor:

QtIfwPackageScript( pkgName, fileName="installscript.qs",
exeName=None, script=None, srcPath=None )
exeName=None, exeVersion="0.0.0.0",
script=None, srcPath=None )
Attributes & default values:

pkgName = pkgName
pkgName = <required>
fileName = "installscript.qs"

script = None
script = None <or loaded via srcPath>

exeName = None
exeVersion = "0.0.0.0"

isAppShortcut = True
isDesktopShortcut = False

componentConstructorBody = None
isAutoComponentConstructor = True

componentCreateOperationsBody = None
isAutoComponentCreateOperations = True
exeName = exeName
isWinStartMenuShortcut = True
isWinDesktopShortcut = False
-------------------------------------------------------
### PipConfig
Expand Down

0 comments on commit 7cfcdd1

Please sign in to comment.