Python winreg.ExpandEnvironmentStrings() Examples

The following are 4 code examples of winreg.ExpandEnvironmentStrings(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module winreg , or try the search function .
Example #1
Source File: common.py    From marsnake with GNU General Public License v3.0 5 votes vote down vote up
def expandvars(var):
	"""Expand environment variables.

	Return the argument with environment variables expanded. Substrings of the
	form $name or ${name} or %name% are replaced by the value of environment
	variable name."""
	if is_python2x() and isinstance(var, str):
		final = var.decode('utf-8')
	else:
		final = var

	if 'posix' == os.name:
		final = os.path.expandvars(final)
	elif 'nt' == os.name:
		if sys.version_info[0] == 2:
			import _winreg
		else:
			import winreg as _winreg
		if final.startswith('${'):
			final = re.sub(r'\$\{(.*?)\}(?=$|\\)',
						   lambda x: '%%%s%%' % x.group(1),
						   final)
		elif final.startswith('$'):
			final = re.sub(r'\$(.*?)(?=$|\\)',
						   lambda x: '%%%s%%' % x.group(1),
						   final)
		final = _winreg.ExpandEnvironmentStrings(final)
	return final 
Example #2
Source File: win_add2path.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    paths, envpath = modify()
    if len(paths) > 1:
        print("Path(s) added:")
        print('\n'.join(paths[1:]))
    else:
        print("No path was added")
    print("\nPATH is now:\n%s\n" % envpath)
    print("Expanded:")
    print(winreg.ExpandEnvironmentStrings(envpath)) 
Example #3
Source File: win_add2path.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def main():
    paths, envpath = modify()
    if len(paths) > 1:
        print("Path(s) added:")
        print('\n'.join(paths[1:]))
    else:
        print("No path was added")
    print("\nPATH is now:\n%s\n" % envpath)
    print("Expanded:")
    print(winreg.ExpandEnvironmentStrings(envpath)) 
Example #4
Source File: win_add2path.py    From android_universal with MIT License 5 votes vote down vote up
def main():
    paths, envpath = modify()
    if len(paths) > 1:
        print("Path(s) added:")
        print('\n'.join(paths[1:]))
    else:
        print("No path was added")
    print("\nPATH is now:\n%s\n" % envpath)
    print("Expanded:")
    print(winreg.ExpandEnvironmentStrings(envpath))