@ -1371,6 +1371,89 @@ get_version_info(wchar_t * version_text, size_t size)
}
}
}
}
static void
show_help_text ( wchar_t * * argv )
{
wchar_t version_text [ MAX_PATH ] ;
# if defined(_M_X64)
BOOL canDo64bit = TRUE ;
# else
/* If we are a 32bit process on a 64bit Windows, first hit the 64bit keys. */
BOOL canDo64bit = FALSE ;
IsWow64Process ( GetCurrentProcess ( ) , & canDo64bit ) ;
# endif
get_version_info ( version_text , MAX_PATH ) ;
fwprintf ( stdout , L " \
Python Launcher for Windows Version % ls \ n \ n " , version_text);
fwprintf ( stdout , L " \
usage : \ n \
% ls [ launcher - args ] [ python - args ] script [ script - args ] \ n \ n " , argv[0]);
fputws ( L " \
Launcher arguments : \ n \ n \
- 2 : Launch the latest Python 2. x version \ n \
- 3 : Launch the latest Python 3. x version \ n \
- X . Y : Launch the specified Python version \ n " , stdout);
if ( canDo64bit ) {
fputws ( L " \
The above all default to 64 bit if a matching 64 bit python is present . \ n \
- X . Y - 32 : Launch the specified 32 bit Python version \ n \
- X - 32 : Launch the latest 32 bit Python X version \ n \
- X . Y - 64 : Launch the specified 64 bit Python version \ n \
- X - 64 : Launch the latest 64 bit Python X version " , stdout);
}
fputws ( L " \n -0 --list : List the available pythons " , stdout ) ;
fputws ( L " \n -0p --list-paths : List with paths " , stdout ) ;
fputws ( L " \n \n The following help text is from Python: \n \n " , stdout ) ;
fflush ( stdout ) ;
}
static BOOL
show_python_list ( wchar_t * * argv )
{
/*
* Display options - 0
*/
INSTALLED_PYTHON * result = NULL ;
INSTALLED_PYTHON * ip = installed_pythons ; /* List of installed pythons */
INSTALLED_PYTHON * defpy = locate_python ( L " " , FALSE ) ;
size_t i = 0 ;
wchar_t * p = argv [ 1 ] ;
wchar_t * fmt = L " \n -%ls-%d " ; /* print VER-BITS */
wchar_t * defind = L " * " ; /* Default indicator */
/*
* Output informational messages to stderr to keep output
* clean for use in pipes , etc .
*/
fwprintf ( stderr ,
L " Installed Pythons found by %s Launcher for Windows " , argv [ 0 ] ) ;
if ( ! _wcsicmp ( p , L " -0p " ) | | ! _wcsicmp ( p , L " --list-paths " ) ) /* Show path? */
fmt = L " \n -%ls-%d \t %ls " ; /* print VER-BITS path */
if ( num_installed_pythons = = 0 ) /* We have somehow got here without searching for pythons */
locate_all_pythons ( ) ; /* Find them, Populates installed_pythons */
if ( num_installed_pythons = = 0 ) /* No pythons found */
fwprintf ( stderr , L " \n No Installed Pythons Found! " ) ;
else
{
for ( i = 0 ; i < num_installed_pythons ; i + + , ip + + ) {
fwprintf ( stdout , fmt , ip - > version , ip - > bits , ip - > executable ) ;
/* If there is a default indicate it */
if ( ( defpy ! = NULL ) & & ! _wcsicmp ( ip - > executable , defpy - > executable ) )
fwprintf ( stderr , defind ) ;
}
}
if ( ( defpy = = NULL ) & & ( num_installed_pythons > 0 ) )
/* We have pythons but none is the default */
fwprintf ( stderr , L " \n \n Can't find a Default Python. \n \n " ) ;
else
fwprintf ( stderr , L " \n \n " ) ; /* End with a blank line */
return ( FALSE ) ; /* If this has been called we cannot continue */
}
static int
static int
process ( int argc , wchar_t * * argv )
process ( int argc , wchar_t * * argv )
{
{
@ -1380,12 +1463,12 @@ process(int argc, wchar_t ** argv)
wchar_t * p ;
wchar_t * p ;
int rc = 0 ;
int rc = 0 ;
size_t plen ;
size_t plen ;
size_t slen ;
INSTALLED_PYTHON * ip ;
INSTALLED_PYTHON * ip ;
BOOL valid ;
BOOL valid ;
DWORD size , attrs ;
DWORD size , attrs ;
HRESULT hr ;
HRESULT hr ;
wchar_t message [ MSGSIZE ] ;
wchar_t message [ MSGSIZE ] ;
wchar_t version_text [ MAX_PATH ] ;
void * version_data ;
void * version_data ;
VS_FIXEDFILEINFO * file_info ;
VS_FIXEDFILEINFO * file_info ;
UINT block_size ;
UINT block_size ;
@ -1516,12 +1599,22 @@ process(int argc, wchar_t ** argv)
else {
else {
p = argv [ 1 ] ;
p = argv [ 1 ] ;
plen = wcslen ( p ) ;
plen = wcslen ( p ) ;
valid = ( * p = = L ' - ' ) & & validate_version ( & p [ 1 ] ) ;
if ( argc = = 2 ) {
slen = wcslen ( L " -0 " ) ;
if ( ! wcsncmp ( p , L " -0 " , slen ) ) /* Starts with -0 */
valid = show_python_list ( argv ) ; /* Check for -0 FIRST */
}
valid = valid & & ( * p = = L ' - ' ) & & validate_version ( & p [ 1 ] ) ;
if ( valid ) {
if ( valid ) {
ip = locate_python ( & p [ 1 ] , FALSE ) ;
ip = locate_python ( & p [ 1 ] , FALSE ) ;
if ( ip = = NULL )
if ( ip = = NULL )
{
fwprintf ( stdout , \
L " Python %ls not found! \n " , & p [ 1 ] ) ;
valid = show_python_list ( argv ) ;
error ( RC_NO_PYTHON , L " Requested Python version (%ls) not \
error ( RC_NO_PYTHON , L " Requested Python version (%ls) not \
installed " , &p[1]);
installed , use - 0 for available pythons " , &p[1]);
}
executable = ip - > executable ;
executable = ip - > executable ;
command + = wcslen ( p ) ;
command + = wcslen ( p ) ;
command = skip_whitespace ( command ) ;
command = skip_whitespace ( command ) ;
@ -1540,49 +1633,28 @@ installed", &p[1]);
# endif
# endif
if ( ! valid ) {
if ( ! valid ) {
/* Look for an active virtualenv */
executable = find_python_by_venv ( ) ;
/* If we didn't find one, look for the default Python */
if ( executable = = NULL ) {
ip = locate_python ( L " " , FALSE ) ;
if ( ip = = NULL )
error ( RC_NO_PYTHON , L " Can't find a default Python. " ) ;
executable = ip - > executable ;
}
if ( ( argc = = 2 ) & & ( ! _wcsicmp ( p , L " -h " ) | | ! _wcsicmp ( p , L " --help " ) ) ) {
# if defined(_M_X64)
BOOL canDo64bit = TRUE ;
# else
/* If we are a 32bit process on a 64bit Windows, first hit the 64bit keys. */
BOOL canDo64bit = FALSE ;
IsWow64Process ( GetCurrentProcess ( ) , & canDo64bit ) ;
# endif
get_version_info ( version_text , MAX_PATH ) ;
fwprintf ( stdout , L " \
Python Launcher for Windows Version % ls \ n \ n " , version_text);
fwprintf ( stdout , L " \
usage : \ n \
% ls [ launcher - args ] [ python - args ] script [ script - args ] \ n \ n " , argv[0]);
fputws ( L " \
Launcher arguments : \ n \ n \
- 2 : Launch the latest Python 2. x version \ n \
- 3 : Launch the latest Python 3. x version \ n \
- X . Y : Launch the specified Python version \ n " , stdout);
if ( canDo64bit ) {
fputws ( L " \
The above all default to 64 bit if a matching 64 bit python is present . \ n \
- X . Y - 32 : Launch the specified 32 bit Python version \ n \
- X - 32 : Launch the latest 32 bit Python X version \ n \
- X . Y - 64 : Launch the specified 64 bit Python version \ n \
- X - 64 : Launch the latest 64 bit Python X version " , stdout);
if ( ( argc = = 2 ) & & ( ! _wcsicmp ( p , L " -h " ) | | ! _wcsicmp ( p , L " --help " ) ) )
show_help_text ( argv ) ;
if ( ( argc = = 2 ) & & ( ! _wcsicmp ( p , L " -0 " ) | | ! _wcsicmp ( p , L " -0p " ) ) )
executable = NULL ; /* Info call only */
else
{
/* Look for an active virtualenv */
executable = find_python_by_venv ( ) ;
/* If we didn't find one, look for the default Python */
if ( executable = = NULL ) {
ip = locate_python ( L " " , FALSE ) ;
if ( ip = = NULL )
error ( RC_NO_PYTHON , L " Can't find a default Python. " ) ;
executable = ip - > executable ;
}
}
fputws ( L " \n \n The following help text is from Python: \n \n " , stdout ) ;
fflush ( stdout ) ;
}
}
}
}
invoke_child ( executable , NULL , command ) ;
if ( executable ! = NULL )
invoke_child ( executable , NULL , command ) ;
else
rc = RC_NO_PYTHON ;
return rc ;
return rc ;
}
}