Skip to content

Commit

Permalink
Issue pyinstaller#692: Merge pull request pyinstaller#149 from mement…
Browse files Browse the repository at this point in the history
…um/develop. Fix merge conflicts.
  • Loading branch information
matysek committed Dec 29, 2014
2 parents d0b4e22 + b937832 commit 74a159f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
38 changes: 36 additions & 2 deletions PyInstaller/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,12 @@ def __init__(self, *args, **kwargs):
a version resource from an executable and then edit the output to
create your own. (The syntax of version resources is so arcane
that I wouldn't attempt to write one from scratch).
uac_admin
Windows only. Setting to True creates a Manifest with will request
elevation upon application restart
uac_uiaccess
Windows only. Setting to True allows an elevated application to
work with Remote Desktop
"""
Target.__init__(self)

Expand All @@ -1105,6 +1111,10 @@ def __init__(self, *args, **kwargs):
# to the exe, but copied beside it.
self.append_pkg = kwargs.get('append_pkg', True)

# On Windows allows the exe to request admin privileges.
self.uac_admin = kwargs.get('uac_admin', config.get('ui_admin'))
self.uac_uiaccess = kwargs.get('uac_uiaccess', config.get('ui_access'))

if config['hasUPX']:
self.upx = kwargs.get('upx', False)
else:
Expand Down Expand Up @@ -1139,12 +1149,14 @@ def __init__(self, *args, **kwargs):
self.toc.extend(arg.dependencies)
else:
self.toc.extend(arg)

if is_win:
filename = os.path.join(WORKPATH, specnm + ".exe.manifest")
self.manifest = winmanifest.create_manifest(filename, self.manifest,
self.console)
self.console, self.uac_admin, self.uac_uiaccess)
self.toc.append((os.path.basename(self.name) + ".manifest", filename,
'BINARY'))

self.pkg = PKG(self.toc, cdict=kwargs.get('cdict', None),
exclude_binaries=self.exclude_binaries,
strip_binaries=self.strip, upx_binaries=self.upx,
Expand Down Expand Up @@ -1208,8 +1220,20 @@ def assemble(self):
exe = self._bootloader_file('run')
if is_win or is_cygwin:
exe = exe + '.exe'

if not os.path.exists(exe):
raise SystemExit(_MISSING_BOOTLOADER_ERRORMSG)

if is_win and not self.exclude_binaries:
# Windows and onefile mode - embed manifest into exe.
logger.info('Onefile Mode - Embedding Manifest into EXE file')
tmpnm = tempfile.mktemp()
shutil.copy2(exe, tmpnm)
os.chmod(tmpnm, 0755)
self.manifest.update_resources(tmpnm, [1]) # 1 for executable
trash.append(tmpnm)
exe = tmpnm

if config['hasRsrcUpdate'] and (self.icon or self.versrsrc or
self.resources):
tmpnm = tempfile.mktemp()
Expand Down Expand Up @@ -1933,7 +1957,14 @@ def __add_options(parser):
parser.add_option('--clean', dest='clean_build', action='store_true', default=False,
help='Clean PyInstaller cache and remove temporary files '
'before building.')

parser.add_option('--uac_admin',
action="store_true", default=False,
help='Windows only. Setting to True creates a Manifest '
'with will request elevation upon application restart')
parser.add_option('--uac_uiaccess',
action="store_true", default=False,
help='Windows only. Setting to True allows an elevated application to '
'work with Remote Desktop')

def main(pyi_config, specfile, noconfirm, ascii=False, **kw):
# Set of global variables that can be used while processing .spec file.
Expand Down Expand Up @@ -1963,4 +1994,7 @@ def main(pyi_config, specfile, noconfirm, ascii=False, **kw):
if config['hasUPX']:
setupUPXFlags()

config['ui_admin'] = kw.get('ui_admin', False)
config['ui_access'] = kw.get('ui_uiaccess', False)

build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
6 changes: 5 additions & 1 deletion PyInstaller/utils/winmanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def UpdateManifestResourcesFromXMLFile(dstpath, srcpath, names=None,
languages or [0, "*"])


def create_manifest(filename, manifest, console):
def create_manifest(filename, manifest, console, uac_admin=False, uac_uiaccess=False):
"""
Create assembly manifest.
"""
Expand Down Expand Up @@ -1003,6 +1003,10 @@ def create_manifest(filename, manifest, console):
version=(6, 0, 0, 0),
publicKeyToken="6595b64144ccf1df")
)
if uac_admin:
manifest.requestedExecutionLevel = 'requireAdministrator'
if uac_uiaccess:
manifest.uiAccess = True
manifest.writeprettyxml(filename)
return manifest

Expand Down
5 changes: 5 additions & 0 deletions doc/source/pyi-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ OPTIONS
--log-level=LOGLEVEL Amount of detail in build-time console messages
(default: INFO, choose one of DEBUG, INFO, WARN,
ERROR, CRITICAL)
--uac_admin Windows only. Setting to True creates a Manifest with will request
elevation upon application restart
--uac_uiaccess
Windows only. Setting to True allows an elevated application to
work with Remote Desktop


SEE ALSO
Expand Down

0 comments on commit 74a159f

Please sign in to comment.