Skip to content

Commit

Permalink
macOS core functionality working. Minor revisions and updates to low …
Browse files Browse the repository at this point in the history
…level functions and PyToBinInstaller Process.
  • Loading branch information
BuvinJ committed Jan 20, 2019
1 parent a853cd5 commit 6670344
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 59 deletions.
1 change: 1 addition & 0 deletions distbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
, runPy \
, toZipFile \
, moveToDesktop \
, moveToHomeDir \
, isImportableModule \
, isImportableFromModule \
, modulePath \
Expand Down
2 changes: 1 addition & 1 deletion distbuilder/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1.0"
__version__ = "0.3.2.0"
6 changes: 5 additions & 1 deletion distbuilder/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ class PyToBinInstallerProcess:
def __init__( self, configFactory,
name="Python To Binary Installer Process",
isObfuscating=False,
isDesktopTarget=False ) :
isDesktopTarget=False,
isHomeDirTarget=False ) :
self.name = name
self.configFactory = configFactory
self.isObfuscating = isObfuscating
self.isDesktopTarget = isDesktopTarget
self.isHomeDirTarget = isHomeDirTarget
self.isTestingObfuscation = False
self.isTestingExe = False
self.exeTestArgs = []
Expand Down Expand Up @@ -183,6 +185,8 @@ def run( self ):
setupPath = buildInstaller( ifwConfig, isPkgSrcRemoved=True )
if self.isDesktopTarget :
setupPath = moveToDesktop( setupPath )
elif self.isHomeDirTarget :
setupPath = moveToHomeDir( setupPath )
if self.isTestingInstall :
run( setupPath,
(QT_IFW_VERBOSE_SWITCH
Expand Down
5 changes: 4 additions & 1 deletion distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
QT_IFW_DIR_ENV_VAR = "QT_IFW_DIR"
QT_BIN_DIR_ENV_VAR = "QT_BIN_DIR"

__MACOS_SETUP_EXT = ".app"

__BIN_SUB_DIR = "bin"
__QT_INSTALL_CREATOR_EXE_NAME = util._normExeName( "binarycreator" )

Expand Down Expand Up @@ -572,7 +574,8 @@ def __build( qtIfwConfig ) :
setupExePath = joinPath( THIS_DIR,
util._normExeName( qtIfwConfig.setupExeName ) )
cmd = '%s %s "%s"' % ( qtUtilityPath, str(qtIfwConfig), setupExePath )
util._system( cmd )
util._system( cmd )
if IS_MACOS : setupExePath = "%s%s" % (setupExePath, __MACOS_SETUP_EXT)
if exists( setupExePath ) : print( "Created %s!" % (setupExePath,) )
else: raise Exception( "FAILED to create %s" % (setupExePath,) )
return setupExePath
Expand Down
116 changes: 64 additions & 52 deletions distbuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import traceback
from distutils.sysconfig import get_python_lib
import inspect # @UnusedImport
from fileinput import filename

# -----------------------------------------------------------------------------
IS_WINDOWS = platform.system() == "Windows"
IS_LINUX = platform.system() == "Linux"
IS_MACOS = platform.system() == "Darwin"
__plat = platform.system()
IS_WINDOWS = __plat == "Windows"
IS_LINUX = __plat == "Linux"
IS_MACOS = __plat == "Darwin"

PY_EXT = ".py"
PY_DIR = dirPath( PYTHON_PATH )
Expand All @@ -42,6 +44,8 @@
__NOT_SUPPORTED_MSG = ( "Sorry this operation is not supported " +
"this for this platform!" )

__LAUNCH_MAC_APP_CMD = "open"

__CSIDL_DESKTOP_DIRECTORY = 16

# -----------------------------------------------------------------------------
Expand All @@ -56,9 +60,14 @@ def tempDirPath(): return gettempdir()
# -----------------------------------------------------------------------------
def run( binPath, args=[],
wrkDir=None, isElevated=False, isDebug=False ):
# TODO: finish isElevated logic (for windows, in debug mode...)
binDir, fileName = splitPath( binPath )
# TODO: finish isElevated logic (for windows, in debug mode...)
binDir, fileName = splitPath( binPath )
if wrkDir is None : wrkDir = binDir
isMacApp = IS_MACOS and splitExt(fileName)[1]==".app"
if isMacApp:
try : args.append( fileName )
except: args=[ fileName ]
binPath = fileName = __LAUNCH_MAC_APP_CMD
if isDebug :
cmdList = [binPath]
if isinstance(args,list): cmdList.extend( args )
Expand All @@ -77,7 +86,7 @@ def run( binPath, args=[],
if isinstance(args,list): args = list2cmdline(args)
elif args is None: args=""
elevate = "" if not isElevated or IS_WINDOWS else "sudo"
pwdCmd = "" if IS_WINDOWS else "./"
pwdCmd = "" if IS_WINDOWS or isMacApp else "./"
cmd = ('%s %s%s %s' % (elevate, pwdCmd, fileName, args)).strip()
_system( cmd, wrkDir )

Expand All @@ -97,6 +106,20 @@ def _system( cmd, wrkDir=None ):
print('')
if wrkDir is not None: chdir( initWrkDir )

# -----------------------------------------------------------------------------
def moveToDesktop( path ): return _moveToDir( path, _userDesktopDirPath() )

def moveToHomeDir( path ): return _moveToDir( path, _userHomeDirPath() )

def _moveToDir( srcPath, destDirPath ):
destPath = joinPath( destDirPath,
basename( normpath(srcPath) ) )
if isFile( destPath ): removeFile( destPath )
elif isDir( destPath ): removeDir( destPath )
move( srcPath, destDirPath )
print( 'Moved "%s" to "%s"' % (srcPath, destPath) )
return destPath

# -----------------------------------------------------------------------------
def isImportableModule( moduleName ):
try: __importByStr( moduleName )
Expand Down Expand Up @@ -137,17 +160,7 @@ def toZipFile( sourceDir, zipDest=None, removeScr=True ):
removeDir( sourceDir )
print( 'Removed directory: "%s"' % (sourceDir,) )
return filePath

def moveToDesktop( path ):
desktopDir = _userDesktopDirPath()
destPath = joinPath( desktopDir,
basename( normpath(path) ) )
if isFile( destPath ): removeFile( destPath )
elif isDir( destPath ): removeDir( destPath )
move( path, desktopDir )
print( 'Moved "%s" to "%s"' % (path, destPath) )
return destPath


# -----------------------------------------------------------------------------
def printErr( msg, isFatal=False ):
try: stderr.write( str(msg) + "\n" )
Expand All @@ -167,6 +180,11 @@ def printExc( e, isDetailed=False, isFatal=False ):
if isFatal: exit(1)

# -----------------------------------------------------------------------------
def _normExeName( exeName ):
base, ext = splitExt( basename( exeName ) )
if IS_WINDOWS: return base + (".exe" if ext=="" else ext)
return base

def _pythonPath( relativePath ):
return normpath( joinPath( PY_DIR, relativePath ) )

Expand All @@ -183,14 +201,39 @@ def _optLocalBinPath( relativePath ):
return normpath( joinPath( OPT_LOCAL_BIN_DIR, relativePath ) )

def _userHiddenLocalBinDirPath( relativePath ) :
return normpath( joinPath( "%s/.local/bin" % (_userDirPath(),),
return normpath( joinPath( "%s/.local/bin" % (_userHomeDirPath(),),
relativePath ) )


def _userHomeDirPath(): return expanduser('~') # works in Windows too!

def _userDesktopDirPath():
if IS_WINDOWS :
return __getFolderPathByCSIDL( __CSIDL_DESKTOP_DIRECTORY )
elif IS_LINUX or IS_MACOS :
return normpath( joinPath( _userHomeDirPath(), DESKTOP_DIR_NAME ) )
raise Exception( __NOT_SUPPORTED_MSG )

def __getFolderPathByCSIDL( csidl ):
import ctypes.wintypes
SHGFP_TYPE_CURRENT = 0 # Get current, not default value
buf = ctypes.create_unicode_buffer( ctypes.wintypes.MAX_PATH )
ctypes.windll.shell32.SHGetFolderPathW(
None, csidl, None, SHGFP_TYPE_CURRENT, buf )
return buf.value

def __importByStr( moduleName, memberName=None ):
try:
if memberName is None : exec( __IMPORT_TMPLT % (moduleName,) )
else: exec( __FROM_IMPORT_TMPLT % (moduleName, memberName) )
except Exception as e: printExc( e )

# -----------------------------------------------------------------------------
def _toSrcDestPair( pathPair, destDir=None ):
''' "Protected" function for internal library uses only '''
''' UGLY "Protected" function for internal library uses only '''

# this is private implementation detail
isPyInstallerArg = (destDir is None)

isPyInstallerArg = (destDir is None) # private implementation detail
src = dest = None
if( isinstance(pathPair, str) or
isinstance(pathPair, unicode) ):
Expand Down Expand Up @@ -222,34 +265,3 @@ def _toSrcDestPair( pathPair, destDir=None ):
return (src, dest)

# -----------------------------------------------------------------------------

def _userDirPath(): return expanduser('~')

def _userDesktopDirPath():
if IS_WINDOWS :
return __getFolderPathByCSIDL( __CSIDL_DESKTOP_DIRECTORY )
elif IS_LINUX :
return normpath( joinPath( _userDirPath(), DESKTOP_DIR_NAME ) )
raise Exception( __NOT_SUPPORTED_MSG )

def __getFolderPathByCSIDL( csidl ):
import ctypes.wintypes
SHGFP_TYPE_CURRENT = 0 # Get current, not default value
buf = ctypes.create_unicode_buffer( ctypes.wintypes.MAX_PATH )
ctypes.windll.shell32.SHGetFolderPathW(
None, csidl, None, SHGFP_TYPE_CURRENT, buf )
return buf.value

def __importByStr( moduleName, memberName=None ):
try:
if memberName is None : exec( __IMPORT_TMPLT % (moduleName,) )
else: exec( __FROM_IMPORT_TMPLT % (moduleName, memberName) )
except Exception as e: printExc( e )

def _normExeName( exeName ):
base, ext = splitExt( basename( exeName ) )
if IS_WINDOWS:
if ext=="": ext="exe"
return base + "." + ext
return base

25 changes: 21 additions & 4 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ Constructor:

PyToBinInstallerProcess( configFactory,
name="Python To Binary Installer Process",
isObfuscating=False, isMovedToDesktop=False )

isObfuscating=False,
isDesktopTarget=False,
isHomeDirTarget=False )
Attributes & default values:

configFactory = <required>

name = "Python To Binary Installer Process"

isObfuscating = False

isDesktopTarget = False
isHomeDirTarget = False

isTestingObfuscation = False
isTestingExe = False
isTestingInstall = False
Expand Down Expand Up @@ -546,8 +553,18 @@ Moves a file or directory to the desktop.
(Note: it *moves* the path specified, it does
not leave a copy of the source). This
*Replaces* any existing copy found at the
destination path (i.e. on the desktop).
destination path.

moveToHomeDir( path )

**Returns**: the new path to the file or directory.

Moves a file or directory to the current user's home directory.
(Note: it *moves* the path specified, it does
not leave a copy of the source). This
*Replaces* any existing copy found at the
destination path.

*TODO: Add git commit/push...*

## Low-Level Utilities
Expand Down Expand Up @@ -848,7 +865,7 @@ Attributes & default values:
pngIconResPath = None

isAppShortcut = True
isDesktopShortcut = False
topShortcut = False

componentConstructorBody = None
isAutoComponentConstructor = True
Expand Down

0 comments on commit 6670344

Please sign in to comment.