def FindVssProjectInfo(fullfname): """Looks up the file system for an INI file describing the project. Looking up the tree is for ni style packages. Returns (projectName, pathToFileName) where pathToFileName contains the path from the ini file to the actual file. """ path, fnameonly = os.path.split(fullfname) origPath = path project = "" retPaths = [fnameonly] while not project: iniName = os.path.join(path, g_iniName) database = win32api.GetProfileVal("Python", "Database", "", iniName) project = win32api.GetProfileVal("Python", "Project", "", iniName) if project: break # No valid INI file in this directory - look up a level. path, addpath = os.path.split(path) if not addpath: # Root? break retPaths.insert(0, addpath) if not project: win32ui.MessageBox( "%s\r\n\r\nThis directory is not configured for Python/VSS" % origPath) return return project, "/".join(retPaths), database
def read_dosvox_ini_items(section): keys = win32api.GetProfileVal(section, None, "", DOSVOX_INI).split("\x00")[:-1] vals = [ win32api.GetProfileVal(section, key, "", DOSVOX_INI) for key in keys ] return keys, vals
def DefaultHandler(self, event): # print 'event', str(event), 'id', event.GetId(), 'type', event.GetEventType() iEventID = event.GetId() iEventType = event.GetEventType() oWindow = event.GetEventObject() iID = oWindow.GetId() #print 'event', event, 'eventID', iEventID, 'eventType', iEventType, 'windowID', iID oParent = oWindow.GetParent() # for control in self.Controls.keys(): # window = self.FindWindowByName(control) for control, window in self.Controls.items(): try: result = window.GetValue() except: try: result = window.GetSelection() except: try: result = window.GetLabel() except: try: result = window.GetSelections() except: result = None self.Results[control] = result sName = event.GetEventObject().GetName() if self.ini and IsFocusEvent(event): sSection = self.GetTitle() sIni = self.ini sValue = win32api.GetProfileVal(sSection, sName, '', sIni) i = sValue.find(',') # if i >= 0: sValue = sValue[i + 1:].strip() # print sIni, sSection, sName, sValue self.SetStatus(sValue) if self.CustomHandler: return self.CustomHandler(self, event, sName) # self.Close() # if self.IsModal() and IsCloseEvent(event): self.EndModal(iID) if self.IsModal() and not IsFocusEvent(event) and sName.startswith('Button_'): self.EndModal(iID)
def InstallPerfmonForService(serviceName, iniName, dllName=None): # If no DLL name, look it up in the INI file name if not dllName: # May be empty string! dllName = win32api.GetProfileVal("Python", "dll", "", iniName) # Still not found - look for the standard one in the same dir as win32service.pyd if not dllName: try: tryName = os.path.join( os.path.split(win32service.__file__)[0], "perfmondata.dll" ) if os.path.isfile(tryName): dllName = tryName except AttributeError: # Frozen app? - anyway, can't find it! pass if not dllName: raise ValueError("The name of the performance DLL must be available") dllName = win32api.GetFullPathName(dllName) # Now setup all the required "Performance" entries. hkey = win32api.RegOpenKey( win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\%s" % (serviceName), 0, win32con.KEY_ALL_ACCESS, ) try: subKey = win32api.RegCreateKey(hkey, "Performance") try: win32api.RegSetValueEx(subKey, "Library", 0, win32con.REG_SZ, dllName) win32api.RegSetValueEx( subKey, "Open", 0, win32con.REG_SZ, "OpenPerformanceData" ) win32api.RegSetValueEx( subKey, "Close", 0, win32con.REG_SZ, "ClosePerformanceData" ) win32api.RegSetValueEx( subKey, "Collect", 0, win32con.REG_SZ, "CollectPerformanceData" ) finally: win32api.RegCloseKey(subKey) finally: win32api.RegCloseKey(hkey) # Now do the "Lodctr" thang... try: import perfmon path, fname = os.path.split(iniName) oldPath = os.getcwd() if path: os.chdir(path) try: perfmon.LoadPerfCounterTextStrings("python.exe " + fname) finally: os.chdir(oldPath) except win32api.error as details: print("The service was installed OK, but the performance monitor") print("data could not be loaded.", details)
def get_extension_defn(moduleName, mapFileName): if win32api is None: return None dsp = win32api.GetProfileVal(moduleName, "dsp", "", mapFileName) if dsp=="": print 'warning: dsp not found' return None # We allow environment variables in the file name dsp = win32api.ExpandEnvironmentStrings(dsp) # If the path to the .DSP file is not absolute, assume it is relative # to the description file. if not os.path.isabs(dsp): dsp = os.path.join( os.path.split(mapFileName)[0], dsp) # Parse it to extract the source files. sourceFiles = parse_dsp(dsp) if sourceFiles is None: print 'warning: no source files' return None module = CExtension(moduleName, sourceFiles) # Put the path to the DSP into the environment so entries can reference it. os.environ['dsp_path'] = os.path.split(dsp)[0] os.environ['ini_path'] = os.path.split(mapFileName)[0] cl_options = win32api.GetProfileVal(moduleName, "cl", "", mapFileName) if cl_options: module.AddCompilerOption(win32api.ExpandEnvironmentStrings(cl_options)) exclude = win32api.GetProfileVal(moduleName, "exclude", "", mapFileName) exclude = string.split(exclude) if win32api.GetProfileVal(moduleName, "Unicode", 0, mapFileName): module.AddCompilerOption('/D UNICODE /D _UNICODE') libs = string.split(win32api.GetProfileVal(moduleName, "libs", "", mapFileName)) for lib in libs: module.AddLinkerLib(win32api.ExpandEnvironmentStrings(lib)) for exc in exclude: if exc in module.sourceFiles: modules.sourceFiles.remove(exc) return module
def delete(self, key): """delete an item for a key (really set to "") """ print 'delete: %s, %s'% (self.section, key) value = win32api.WriteProfileVal( self.section, key, None, self.filename) checkValue = win32api.GetProfileVal(self.section, key, 'nonsens', self.filename) if checkValue != 'nonsens': print 'delete failed: %s, %s: got %s instead'% (self.section, key, checkValue)
def set(self, key, value): """set an item for akey """ ## print 'set: %s, %s: %s'% (self.section, key, value) win32api.WriteProfileVal( self.section, key, value, self.filename) checkValue = win32api.GetProfileVal(self.section, key, 'nonsens', self.filename) if not (checkValue == value or \ value in [0, 1] and checkValue == str(value)): print 'set failed: %s, %s: %s, got %s instead'% (self.section, key, value, checkValue)
def get(self, key, defaultValue=None): """get an item from a key """ if defaultValue is None: defaultValue = '' else: defaultValue = str(defaultValue) value = win32api.GetProfileVal(self.section, key, defaultValue, self.filename) ## if value: ## print 'get: %s, %s: %s'% (self.section, key, value) if value in ("0", "1"): return int(value) return value
def set(self, key, value): """set an item for akey 0 or empty deletes automatically """ ## print 'set: %s, %s: %s'% (self.section, key, value) if value in [0, "0"]: self.delete(key) elif not value: self.delete(key) else: win32api.WriteProfileVal(self.section, key, str(value), self.filename) checkValue = win32api.GetProfileVal(self.section, key, 'nonsens', self.filename) if not (checkValue == value or \ value in [0, 1] and checkValue == str(value)): print 'set failed: %s, %s: %s, got %s instead' % ( self.section, key, value, checkValue)
"""Extension management for Windows.
def getFloat(self, key, default=0.0): """INIファイル指定キーから実数の取得""" return float( w32a.GetProfileVal(self.section, key, str(default), self.iniFile))
def getInt(self, key, default=0): """INIファイル指定キーから整数の取得""" return int( w32a.GetProfileVal(self.section, key, str(default), self.iniFile))
def getStr(self, key, default=""): """INIファイル指定キーから文字列の取得""" return w32a.GetProfileVal(self.section, key, default, self.iniFile)