b.win32utils : module documentation

Part of bzrlib

Win32-specific helper functions

Only one dependency: ctypes should be installed.

Function debug_memory_win32api Use trace.note() to dump the running memory info.
Function get_console_size Return size of current console.
Function get_appdata_location Return Application Data location.
Function get_local_appdata_location Return Local Application Data location.
Function get_home_location Return user's home location.
Function get_user_name Return user name as login name.
Function get_host_name Return host machine name.
Function get_appdata_location_unicode Undocumented
Function get_home_location_unicode Undocumented
Function get_user_name_unicode Undocumented
Function get_host_name_unicode Undocumented
Function glob_one Same as glob.glob().
Function glob_expand Replacement for glob expansion by the shell.
Function get_app_path Look up in Windows registry for full path to application executable.
Function set_file_attr_hidden Set file attributes to hidden if possible
Function get_unicode_argv Undocumented
Function _get_sh_special_folder_path Call SHGetSpecialFolderPathW if available, or return None.
Function _ensure_unicode Undocumented
Function _ensure_with_dir Undocumented
Function _undo_ensure_with_dir Undocumented
Function _command_line_to_argv Convert a Unicode command line into a list of argv arguments.
Function _pywin32_is_local_pid_dead True if pid doesn't correspond to live process on this machine
Function _ctypes_is_local_pid_dead True if pid doesn't correspond to live process on this machine
def debug_memory_win32api(message='', short=True):
Use trace.note() to dump the running memory info.
def get_console_size(defaultx=80, defaulty=25):
Return size of current console.

This function try to determine actual size of current working console window and return tuple (sizex, sizey) if success, or default size (defaultx, defaulty) otherwise.

def _get_sh_special_folder_path(csidl):
Call SHGetSpecialFolderPathW if available, or return None.

Result is always unicode (or None).

def get_appdata_location():
Return Application Data location. Return None if we cannot obtain location.

Windows defines two 'Application Data' folders per user - a 'roaming' one that moves with the user as they logon to different machines, and a 'local' one that stays local to the machine. This returns the 'roaming' directory, and thus is suitable for storing user-preferences, etc.

Returned value can be unicode or plain string. To convert plain string to unicode use s.decode(osutils.get_user_encoding()) (XXX - but see bug 262874, which asserts the correct encoding is 'mbcs')

def get_local_appdata_location():
Return Local Application Data location. Return the same as get_appdata_location() if we cannot obtain location.

Windows defines two 'Application Data' folders per user - a 'roaming' one that moves with the user as they logon to different machines, and a 'local' one that stays local to the machine. This returns the 'local' directory, and thus is suitable for caches, temp files and other things which don't need to move with the user.

Returned value can be unicode or plain string. To convert plain string to unicode use s.decode(osutils.get_user_encoding()) (XXX - but see bug 262874, which asserts the correct encoding is 'mbcs')

def get_home_location():
Return user's home location. Assume on win32 it's the <My Documents> folder. If location cannot be obtained return system drive root, i.e. C: Returned value can be unicode or plain string. To convert plain string to unicode use s.decode(osutils.get_user_encoding())
def get_user_name():
Return user name as login name. If name cannot be obtained return None.

Returned value can be unicode or plain string. To convert plain string to unicode use s.decode(osutils.get_user_encoding())

def get_host_name():
Return host machine name. If name cannot be obtained return None.
ReturnsA unicode string representing the host name. On win98, this may be a plain string as win32 api doesn't support unicode.
def _ensure_unicode(s):
Undocumented
def get_appdata_location_unicode():
Undocumented
def get_home_location_unicode():
Undocumented
def get_user_name_unicode():
Undocumented
def get_host_name_unicode():
Undocumented
def _ensure_with_dir(path):
Undocumented
def _undo_ensure_with_dir(path, corrected):
Undocumented
def glob_one(possible_glob):
Same as glob.glob().

work around bugs in glob.glob() - Python bug #1001604 ("glob doesn't return unicode with ...") - failing expansion for / with non-iso-8859-* chars

def glob_expand(file_list):
Replacement for glob expansion by the shell.

Win32's cmd.exe does not do glob expansion (eg *.py), so we do our own here.

Introduced in bzrlib 0.18.

Parametersfile_listA list of filenames which may include shell globs.
ReturnsAn expanded list of filenames.
def get_app_path(appname):
Look up in Windows registry for full path to application executable. Typically, applications create subkey with their basename in HKLMSOFTWAREMicrosoftWindowsCurrentVersionApp Paths
Parametersappnamename of application (if no filename extension is specified, .exe used)
Returnsfull path to aplication executable from registry, or appname itself if nothing found.
def set_file_attr_hidden(path):
Set file attributes to hidden if possible
def _command_line_to_argv(command_line, argv, single_quotes_allowed=False):
Convert a Unicode command line into a list of argv arguments.

It performs wildcard expansion to make wildcards act closer to how they work in posix shells, versus how they work by default on Windows. Quoted arguments are left untouched.

Parameterscommand_lineThe unicode string to split into an arg list.
single_quotes_allowedWhether single quotes are accepted as quoting characters like double quotes. False by default.
ReturnsA list of unicode strings.
def get_unicode_argv():
Undocumented
def _pywin32_is_local_pid_dead(pid):
True if pid doesn't correspond to live process on this machine
def _ctypes_is_local_pid_dead(pid):
True if pid doesn't correspond to live process on this machine
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.