Python sys.winver() Examples

The following are code examples for showing how to use sys.winver(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: ironpython2   Author: IronLanguages   File: dbgpyapp.py    Apache License 2.0 6 votes vote down vote up
def InitInstance(self):
		# Use a registry path of "Python\Pythonwin Debugger
		win32ui.SetAppName(win32ui.LoadString(win32ui.IDR_DEBUGGER))
		win32ui.SetRegistryKey("Python %s" % (sys.winver,))
		# We _need_ the Scintilla color editor.
		# (and we _always_ get it now :-)

		numMRU = win32ui.GetProfileVal("Settings","Recent File List Size", 10)
		win32ui.LoadStdProfileSettings(numMRU)

		self.LoadMainFrame()

		# Display the interactive window if the user wants it.
		from pywin.framework import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()
		# Load additional module the user may want.
		self.LoadUserModules()

#		win32ui.CreateDebuggerThread()
		win32ui.EnableControlContainer() 
Example 2
Project: ironpython2   Author: IronLanguages   File: regutil.py    Apache License 2.0 6 votes vote down vote up
def RegisterCoreDLL(coredllName = None):
	"""Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
	"""
	if coredllName is None:
		coredllName = win32api.GetModuleFileName(sys.dllhandle)
		# must exist!
	else:
		try:
			os.stat(coredllName)
		except os.error:
			print "Warning: Registering non-existant core DLL %s" % coredllName

	hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
	try:
		win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
	finally:
		win32api.RegCloseKey(hKey)
	# Lastly, setup the current version to point to me.
	win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver) 
Example 3
Project: ironpython2   Author: IronLanguages   File: dllsite.py    Apache License 2.0 6 votes vote down vote up
def test_bad_stuff():
    '''
    Cases where IP should not load an assembly for one
    reason or another.
    '''
    
    #ensure that users cannot override IP native modules
    import sys
    Assert(sys.winver != "HIJACKED")
    import re
    Assert(re.compile != "HIJACKED")

    #ensure corrupted DLLs cannot be loaded
    try:
        import fooCORRUPT
        raise Exception("Corrupted DLL was loaded")
    except ImportError, e:
        pass
    
    #nothing to do for unmanaged DLLs...if the interpreter has made it
    #this far, all is well:)
    
    
    #ensure *.exe's cannot take precedence over *.dlls 
Example 4
Project: open-recipe   Author: dspray95   File: dbgpyapp.py    The Unlicense 6 votes vote down vote up
def InitInstance(self):
		# Use a registry path of "Python\Pythonwin Debugger
		win32ui.SetAppName(win32ui.LoadString(win32ui.IDR_DEBUGGER))
		win32ui.SetRegistryKey("Python %s" % (sys.winver,))
		# We _need_ the Scintilla color editor.
		# (and we _always_ get it now :-)

		numMRU = win32ui.GetProfileVal("Settings","Recent File List Size", 10)
		win32ui.LoadStdProfileSettings(numMRU)

		self.LoadMainFrame()

		# Display the interactive window if the user wants it.
		from pywin.framework import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()
		# Load additional module the user may want.
		self.LoadUserModules()

#		win32ui.CreateDebuggerThread()
		win32ui.EnableControlContainer() 
Example 5
Project: open-recipe   Author: dspray95   File: regutil.py    The Unlicense 6 votes vote down vote up
def RegisterCoreDLL(coredllName = None):
	"""Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
	"""
	if coredllName is None:
		coredllName = win32api.GetModuleFileName(sys.dllhandle)
		# must exist!
	else:
		try:
			os.stat(coredllName)
		except os.error:
			print("Warning: Registering non-existant core DLL %s" % coredllName)

	hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
	try:
		win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
	finally:
		win32api.RegCloseKey(hKey)
	# Lastly, setup the current version to point to me.
	win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver) 
Example 6
Project: arkScript   Author: akbchris   File: dbgpyapp.py    MIT License 6 votes vote down vote up
def InitInstance(self):
		# Use a registry path of "Python\Pythonwin Debugger
		win32ui.SetAppName(win32ui.LoadString(win32ui.IDR_DEBUGGER))
		win32ui.SetRegistryKey("Python %s" % (sys.winver,))
		# We _need_ the Scintilla color editor.
		# (and we _always_ get it now :-)

		numMRU = win32ui.GetProfileVal("Settings","Recent File List Size", 10)
		win32ui.LoadStdProfileSettings(numMRU)

		self.LoadMainFrame()

		# Display the interactive window if the user wants it.
		from pywin.framework import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()
		# Load additional module the user may want.
		self.LoadUserModules()

#		win32ui.CreateDebuggerThread()
		win32ui.EnableControlContainer() 
Example 7
Project: arkScript   Author: akbchris   File: regutil.py    MIT License 6 votes vote down vote up
def RegisterCoreDLL(coredllName = None):
	"""Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
	"""
	if coredllName is None:
		coredllName = win32api.GetModuleFileName(sys.dllhandle)
		# must exist!
	else:
		try:
			os.stat(coredllName)
		except os.error:
			print("Warning: Registering non-existant core DLL %s" % coredllName)

	hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey())
	try:
		win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
	finally:
		win32api.RegCloseKey(hKey)
	# Lastly, setup the current version to point to me.
	win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver) 
Example 8
Project: IE_MBom   Author: mikewolfli   File: upx.py    The Unlicense 5 votes vote down vote up
def patch_python_dll_winver(self, dll_name, new_winver=None):
        # Override this to first check if the file is upx'd and skip if so
        if not self.dry_run:
            if not os.system('upx.exe "%s"' % dll_name):
                if self.verbose:
                    print("Skipping setting sys.winver for '%s' (UPX'd)" % \
                          dll_name)
            else:
                py2exe.patch_python_dll_winver(self, dll_name, new_winver)
                # We UPX this one file here rather than in copy_file so
                # the version adjustment can be successful
                if self.upx:
                    os.system('upx.exe %s "%s"' % (self.upx_options, os.path.normpath(dll_name))) 
Example 9
Project: ironpython2   Author: IronLanguages   File: scriptutils.py    Apache License 2.0 5 votes vote down vote up
def FindTabNanny():
	try:
		return __import__("tabnanny")
	except ImportError:
		pass
	# OK - not in the standard library - go looking.
	filename = "tabnanny.py"
	try:
		path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
	except win32api.error:
		print "WARNING - The Python registry does not have an 'InstallPath' setting"
		print "          The file '%s' can not be located" % (filename)
		return None
	fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
	try:
		os.stat(fname)
	except os.error:
		print "WARNING - The file '%s' can not be located in path '%s'" % (filename, path)
		return None

	tabnannyhome, tabnannybase = os.path.split(fname)
	tabnannybase = os.path.splitext(tabnannybase)[0]
	# Put tab nanny at the top of the path.
	sys.path.insert(0, tabnannyhome)
	try:
		return __import__(tabnannybase)
	finally:
		# remove the tab-nanny from the path
		del sys.path[0] 
Example 10
Project: ironpython2   Author: IronLanguages   File: intpyapp.py    Apache License 2.0 5 votes vote down vote up
def InitInstance(self):
		# Allow "/nodde" and "/newinstance to optimize this!
		if "/nodde" not in sys.argv and "/newinstance" not in sys.argv:
			if self.InitDDE():
				return 1 # A remote DDE client is doing it for us!
		else:
			self.ddeServer = None

		win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on!
		app.CApp.InitInstance(self)

		# Create the taskbar icon
		win32ui.CreateDebuggerThread()

		# Allow Pythonwin to host OCX controls.
		win32ui.EnableControlContainer()

		# Display the interactive window if the user wants it.
		import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()

		# Load additional module the user may want.
		self.LoadUserModules()

		# Load the ToolBar state near the end of the init process, as
		# there may be Toolbar IDs created by the user or other modules.
		# By now all these modules should be loaded, so all the toolbar IDs loaded.
		try:
			self.frame.LoadBarState("ToolbarDefault")
		except win32ui.error:
			# MFC sucks.  It does essentially "GetDlgItem(x)->Something", so if the
			# toolbar with ID x does not exist, MFC crashes!  Pythonwin has a trap for this
			# but I need to investigate more how to prevent it (AFAIK, ensuring all the
			# toolbars are created by now _should_ stop it!)
			pass

		# Finally process the command line arguments.
		self.ProcessArgs(sys.argv) 
Example 11
Project: ironpython2   Author: IronLanguages   File: cerapi.py    Apache License 2.0 5 votes vote down vote up
def DumpPythonRegistry():
    try:
        h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\PythonPath" % sys.winver)
    except win32api.error:
        print "The remote device does not appear to have Python installed"
        return 0
    path, typ = wincerapi.CeRegQueryValueEx(h, None)
    print "The remote PythonPath is '%s'" % (str(path), )
    h.Close()
    return 1 
Example 12
Project: ironpython2   Author: IronLanguages   File: setup_d.py    Apache License 2.0 5 votes vote down vote up
def _doregister(mod_name, dll_name):
    assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
    try:
        key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
    except _winreg.error:
        try:
            key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
        except _winreg.error:
            print "Could not find the existing '%s' module registered in the registry" % (mod_name,)
            usage_and_die(4)
    # Create the debug key.
    sub_key = _winreg.CreateKey(key, "Debug")
    _winreg.SetValue(sub_key, None, _winreg.REG_SZ, dll_name)
    print "Registered '%s' in the registry" % (dll_name,) 
Example 13
Project: ironpython2   Author: IronLanguages   File: register.py    Apache License 2.0 5 votes vote down vote up
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName 
Example 14
Project: ironpython2   Author: IronLanguages   File: modulediff.py    Apache License 2.0 5 votes vote down vote up
def gen_bug_report(mod_name, diffs, outdir):
    needs_to_be_implemented = collect_diffs(diffs, '-')
    needs_to_be_removed = collect_diffs(diffs, '+')
    
    if not needs_to_be_implemented and not needs_to_be_removed:
        return
    
    bug_report_name = outdir + "\\%s.log" % mod_name
    bug_report = open(bug_report_name, "w")
    bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver)))

    #--unfiltered list of attributes to be added
    if len(needs_to_be_implemented)>0:
        bug_report.write("-------------------------------------------------------\n")
        bug_report.write("""Complete list of module attributes IronPython is still 
missing implementations for:
""")
        for x in needs_to_be_implemented:
            bug_report.write("    " + x + '\n')
        bug_report.write("\n\n\n")
    
    #--unfiltered list of attributes to be removed
    if len(needs_to_be_removed)>0:
        bug_report.write("-------------------------------------------------------\n")
        bug_report.write("""Complete list of module attributes that should be removed 
from IronPython:
""")
        for x in needs_to_be_removed:
            bug_report.write("    " + x + '\n')
    
    bug_report.close()
    return bug_report_name 
Example 15
Project: open-recipe   Author: dspray95   File: scriptutils.py    The Unlicense 5 votes vote down vote up
def FindTabNanny():
	try:
		return __import__("tabnanny")
	except ImportError:
		pass
	# OK - not in the standard library - go looking.
	filename = "tabnanny.py"
	try:
		path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
	except win32api.error:
		print("WARNING - The Python registry does not have an 'InstallPath' setting")
		print("          The file '%s' can not be located" % (filename))
		return None
	fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
	try:
		os.stat(fname)
	except os.error:
		print("WARNING - The file '%s' can not be located in path '%s'" % (filename, path))
		return None

	tabnannyhome, tabnannybase = os.path.split(fname)
	tabnannybase = os.path.splitext(tabnannybase)[0]
	# Put tab nanny at the top of the path.
	sys.path.insert(0, tabnannyhome)
	try:
		return __import__(tabnannybase)
	finally:
		# remove the tab-nanny from the path
		del sys.path[0] 
Example 16
Project: open-recipe   Author: dspray95   File: intpyapp.py    The Unlicense 5 votes vote down vote up
def InitInstance(self):
		# Allow "/nodde" and "/new" to optimize this!
		if "/nodde" not in sys.argv and "/new" not in sys.argv:
			if self.InitDDE():
				return 1 # A remote DDE client is doing it for us!
		else:
			self.ddeServer = None

		win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on!
		app.CApp.InitInstance(self)

		# Create the taskbar icon
		win32ui.CreateDebuggerThread()

		# Allow Pythonwin to host OCX controls.
		win32ui.EnableControlContainer()

		# Display the interactive window if the user wants it.
		from . import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()

		# Load additional module the user may want.
		self.LoadUserModules()

		# Load the ToolBar state near the end of the init process, as
		# there may be Toolbar IDs created by the user or other modules.
		# By now all these modules should be loaded, so all the toolbar IDs loaded.
		try:
			self.frame.LoadBarState("ToolbarDefault")
		except win32ui.error:
			# MFC sucks.  It does essentially "GetDlgItem(x)->Something", so if the
			# toolbar with ID x does not exist, MFC crashes!  Pythonwin has a trap for this
			# but I need to investigate more how to prevent it (AFAIK, ensuring all the
			# toolbars are created by now _should_ stop it!)
			pass

		# Finally process the command line arguments.
		self.ProcessArgs(sys.argv) 
Example 17
Project: open-recipe   Author: dspray95   File: cerapi.py    The Unlicense 5 votes vote down vote up
def DumpPythonRegistry():
    try:
        h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\PythonPath" % sys.winver)
    except win32api.error:
        print("The remote device does not appear to have Python installed")
        return 0
    path, typ = wincerapi.CeRegQueryValueEx(h, None)
    print("The remote PythonPath is '%s'" % (str(path), ))
    h.Close()
    return 1 
Example 18
Project: open-recipe   Author: dspray95   File: setup_d.py    The Unlicense 5 votes vote down vote up
def _doregister(mod_name, dll_name):
    assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
    try:
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
    except winreg.error:
        try:
            key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
        except winreg.error:
            print("Could not find the existing '%s' module registered in the registry" % (mod_name,))
            usage_and_die(4)
    # Create the debug key.
    sub_key = winreg.CreateKey(key, "Debug")
    winreg.SetValue(sub_key, None, winreg.REG_SZ, dll_name)
    print("Registered '%s' in the registry" % (dll_name,)) 
Example 19
Project: open-recipe   Author: dspray95   File: register.py    The Unlicense 5 votes vote down vote up
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName 
Example 20
Project: lark   Author: lark-parser   File: python_parser.py    MIT License 5 votes vote down vote up
def _get_lib_path():
    if os.name == 'nt':
        if 'PyPy' in sys.version:
            return os.path.join(sys.prefix, 'lib-python', sys.winver)
        else:
            return os.path.join(sys.prefix, 'Lib')
    else:
        return [x for x in sys.path if x.endswith('%s.%s' % sys.version_info[:2])][0] 
Example 21
Project: arkScript   Author: akbchris   File: scriptutils.py    MIT License 5 votes vote down vote up
def FindTabNanny():
	try:
		return __import__("tabnanny")
	except ImportError:
		pass
	# OK - not in the standard library - go looking.
	filename = "tabnanny.py"
	try:
		path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
	except win32api.error:
		print("WARNING - The Python registry does not have an 'InstallPath' setting")
		print("          The file '%s' can not be located" % (filename))
		return None
	fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
	try:
		os.stat(fname)
	except os.error:
		print("WARNING - The file '%s' can not be located in path '%s'" % (filename, path))
		return None

	tabnannyhome, tabnannybase = os.path.split(fname)
	tabnannybase = os.path.splitext(tabnannybase)[0]
	# Put tab nanny at the top of the path.
	sys.path.insert(0, tabnannyhome)
	try:
		return __import__(tabnannybase)
	finally:
		# remove the tab-nanny from the path
		del sys.path[0] 
Example 22
Project: arkScript   Author: akbchris   File: intpyapp.py    MIT License 5 votes vote down vote up
def InitInstance(self):
		# Allow "/nodde" and "/new" to optimize this!
		if "/nodde" not in sys.argv and "/new" not in sys.argv:
			if self.InitDDE():
				return 1 # A remote DDE client is doing it for us!
		else:
			self.ddeServer = None

		win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on!
		app.CApp.InitInstance(self)

		# Create the taskbar icon
		win32ui.CreateDebuggerThread()

		# Allow Pythonwin to host OCX controls.
		win32ui.EnableControlContainer()

		# Display the interactive window if the user wants it.
		from . import interact
		interact.CreateInteractiveWindowUserPreference()

		# Load the modules we use internally.
		self.LoadSystemModules()

		# Load additional module the user may want.
		self.LoadUserModules()

		# Load the ToolBar state near the end of the init process, as
		# there may be Toolbar IDs created by the user or other modules.
		# By now all these modules should be loaded, so all the toolbar IDs loaded.
		try:
			self.frame.LoadBarState("ToolbarDefault")
		except win32ui.error:
			# MFC sucks.  It does essentially "GetDlgItem(x)->Something", so if the
			# toolbar with ID x does not exist, MFC crashes!  Pythonwin has a trap for this
			# but I need to investigate more how to prevent it (AFAIK, ensuring all the
			# toolbars are created by now _should_ stop it!)
			pass

		# Finally process the command line arguments.
		self.ProcessArgs(sys.argv) 
Example 23
Project: arkScript   Author: akbchris   File: cerapi.py    MIT License 5 votes vote down vote up
def DumpPythonRegistry():
    try:
        h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\PythonPath" % sys.winver)
    except win32api.error:
        print("The remote device does not appear to have Python installed")
        return 0
    path, typ = wincerapi.CeRegQueryValueEx(h, None)
    print("The remote PythonPath is '%s'" % (str(path), ))
    h.Close()
    return 1 
Example 24
Project: arkScript   Author: akbchris   File: setup_d.py    MIT License 5 votes vote down vote up
def _doregister(mod_name, dll_name):
    assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
    try:
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
    except winreg.error:
        try:
            key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
        except winreg.error:
            print("Could not find the existing '%s' module registered in the registry" % (mod_name,))
            usage_and_die(4)
    # Create the debug key.
    sub_key = winreg.CreateKey(key, "Debug")
    winreg.SetValue(sub_key, None, winreg.REG_SZ, dll_name)
    print("Registered '%s' in the registry" % (dll_name,)) 
Example 25
Project: arkScript   Author: akbchris   File: register.py    MIT License 5 votes vote down vote up
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName 
Example 26
Project: ConTroll_Remote_Access_Trojan   Author: Lithium95   File: impdirector.py    Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self.path = "WindowsRegistry"
        self.map = {}
        try:
            import win32api
            import win32con
        except ImportError:
            return

        subkey = r"Software\Python\PythonCore\%s\Modules" % sys.winver
        for root in (win32con.HKEY_CURRENT_USER, win32con.HKEY_LOCAL_MACHINE):
            try:
                hkey = win32api.RegOpenKeyEx(root, subkey, 0, win32con.KEY_READ)
            except Exception, e:
                logger.debug('RegistryImportDirector: %s' % e)
                continue

            numsubkeys, numvalues, lastmodified = win32api.RegQueryInfoKey(hkey)
            for i in range(numsubkeys):
                subkeyname = win32api.RegEnumKey(hkey, i)
                hskey = win32api.RegOpenKeyEx(hkey, subkeyname, 0, win32con.KEY_READ)
                val = win32api.RegQueryValueEx(hskey, '')
                desc = getDescr(val[0])
                #print " RegistryImportDirector got %s %s" % (val[0], desc)  #XXX
                self.map[subkeyname] = (val[0], desc)
                hskey.Close()
            hkey.Close()
            break 
Example 27
Project: ironpython2   Author: IronLanguages   File: __init__.py    Apache License 2.0 4 votes vote down vote up
def SetupEnvironment():
	HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
	KEY_QUERY_VALUE = 0x1
	# Open the root key once, as this is quite slow on NT.
	try:
		keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
		key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
	except (win32api.error, AttributeError):
		key = None
		
	try:
		found = 0
		if key is not None:
			try:
				__path__.append( win32api.RegQueryValue(key, "Extensions" ))
				found = 1
			except win32api.error:
				# Nothing registered
				pass
		if not found:
			try:
				__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
			except win32api.error:
				# Give up in disgust!
				pass
	
		# For the sake of developers, we also look up a "BuildPath" key
		# If extension modules add support, we can load their .pyd's from a completely
		# different directory (see the comments below)
		try:
			if key is not None:
				global __build_path__
				__build_path__ = win32api.RegQueryValue(key, "BuildPath")
				__path__.append(__build_path__)
		except win32api.error:
			# __build_path__ neednt be defined.
			pass
		global __gen_path__
		if key is not None:
			try:
				__gen_path__ = win32api.RegQueryValue(key, "GenPath")
			except win32api.error:
				pass
	finally:
		if key is not None:
			key.Close()

# A Helper for developers.  A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!) 
Example 28
Project: ironpython2   Author: IronLanguages   File: cmodule.py    Apache License 2.0 4 votes vote down vote up
def gen_bug_report(mod_name, needs_to_be_implemented, needs_to_be_removed):
    bug_report_name = "bug_reports\\%s.log" % mod_name
    bug_report = open(bug_report_name, "w")
    bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver)))
    
    bug_report.write("-------------------------------------------------------\n")
    bug_report.write("""After filtering out Python special method names, 
IronPython is still MISSING implementations for the 
following module attributes:
""")
    for x in needs_to_be_implemented:
        if re.search(REGEX_FILTER, x)==None:
            bug_report.write("    " + x)
    bug_report.write("\n\n")
    
    bug_report.write("-------------------------------------------------------\n")
    bug_report.write("""After filtering out Python special method names, 
IronPython is still PROVIDING implementations for the 
following module attributes which should NOT exist:
""")
    for x in needs_to_be_removed:
        if re.search(REGEX_FILTER, x)==None:
            bug_report.write("    " + x)
    bug_report.write("\n\n")
    
    #--unfiltered list of attributes to be added
    if len(needs_to_be_implemented)>0:
        bug_report.write("-------------------------------------------------------\n")
        bug_report.write("""Complete list of module attributes IronPython is still 
missing implementations for:
""")
        for x in needs_to_be_implemented:
            bug_report.write("    " + x)
        bug_report.write("\n\n\n")
    
    #--unfiltered list of attributes to be removed
    if len(needs_to_be_removed)>0:
        bug_report.write("-------------------------------------------------------\n")
        bug_report.write("""Complete list of module attributes that should be removed 
from IronPython:
""")
        for x in needs_to_be_removed:
            bug_report.write("    " + x)
    
    bug_report.close()
    return bug_report_name
    


#--MAIN------------------------------------------------------------------------ 
Example 29
Project: open-recipe   Author: dspray95   File: __init__.py    The Unlicense 4 votes vote down vote up
def SetupEnvironment():
	HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
	KEY_QUERY_VALUE = 0x1
	# Open the root key once, as this is quite slow on NT.
	try:
		keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
		key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
	except (win32api.error, AttributeError):
		key = None
		
	try:
		found = 0
		if key is not None:
			try:
				__path__.append( win32api.RegQueryValue(key, "Extensions" ))
				found = 1
			except win32api.error:
				# Nothing registered
				pass
		if not found:
			try:
				__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
			except win32api.error:
				# Give up in disgust!
				pass
	
		# For the sake of developers, we also look up a "BuildPath" key
		# If extension modules add support, we can load their .pyd's from a completely
		# different directory (see the comments below)
		try:
			if key is not None:
				global __build_path__
				__build_path__ = win32api.RegQueryValue(key, "BuildPath")
				__path__.append(__build_path__)
		except win32api.error:
			# __build_path__ neednt be defined.
			pass
		global __gen_path__
		if key is not None:
			try:
				__gen_path__ = win32api.RegQueryValue(key, "GenPath")
			except win32api.error:
				pass
	finally:
		if key is not None:
			key.Close()

# A Helper for developers.  A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!) 
Example 30
Project: arkScript   Author: akbchris   File: __init__.py    MIT License 4 votes vote down vote up
def SetupEnvironment():
	HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
	KEY_QUERY_VALUE = 0x1
	# Open the root key once, as this is quite slow on NT.
	try:
		keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
		key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
	except (win32api.error, AttributeError):
		key = None
		
	try:
		found = 0
		if key is not None:
			try:
				__path__.append( win32api.RegQueryValue(key, "Extensions" ))
				found = 1
			except win32api.error:
				# Nothing registered
				pass
		if not found:
			try:
				__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
			except win32api.error:
				# Give up in disgust!
				pass
	
		# For the sake of developers, we also look up a "BuildPath" key
		# If extension modules add support, we can load their .pyd's from a completely
		# different directory (see the comments below)
		try:
			if key is not None:
				global __build_path__
				__build_path__ = win32api.RegQueryValue(key, "BuildPath")
				__path__.append(__build_path__)
		except win32api.error:
			# __build_path__ neednt be defined.
			pass
		global __gen_path__
		if key is not None:
			try:
				__gen_path__ = win32api.RegQueryValue(key, "GenPath")
			except win32api.error:
				pass
	finally:
		if key is not None:
			key.Close()

# A Helper for developers.  A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!)