def need(restype, resid, filename = None, modname = None): """Open a resource file, if needed. restype and resid are required parameters, and identify the resource for which to test. If it is available we are done. If it is not available we look for a file filename (default: modname with .rsrc appended) either in the same folder as where modname was loaded from, or otherwise across sys.path. Returns the refno of the resource file opened (or None)""" if modname is None and filename is None: raise ArgumentError, 'Either filename or modname argument (or both) must be given' if type(resid) is type(1): try: h = Res.GetResource(restype, resid) except Res.Error: pass else: return else: try: h = Res.GetNamedResource(restype, resid) except Res.Error: pass else: return if not filename: if '.' in modname: filename = modname.split('.')[-1] + '.rsrc' else: filename = modname + '.rsrc' searchdirs = [] if modname == '__main__': searchdirs = [os.curdir] if modname in sys.modules: mod = sys.modules[modname] if hasattr(mod, '__file__'): searchdirs = [os.path.dirname(mod.__file__)] searchdirs.extend(sys.path) for dir in searchdirs: pathname = os.path.join(dir, filename) if os.path.exists(pathname): break else: raise ResourceFileNotFoundError, filename refno = open_pathname(pathname) if type(resid) is type(1): h = Res.GetResource(restype, resid) else: h = Res.GetNamedResource(restype, resid) return refno
def need(restype, resid, filename=None, modname=None): if modname is None: if filename is None: raise ArgumentError, 'Either filename or modname argument (or both) must be given' if type(resid) is type(1): try: h = Res.GetResource(restype, resid) except Res.Error: pass else: return else: try: h = Res.GetNamedResource(restype, resid) except Res.Error: pass else: return if not filename: if '.' in modname: filename = modname.split('.')[-1] + '.rsrc' else: filename = modname + '.rsrc' searchdirs = [] if modname == '__main__': searchdirs = [os.curdir] if modname in sys.modules: mod = sys.modules[modname] if hasattr(mod, '__file__'): searchdirs = [os.path.dirname(mod.__file__)] searchdirs.extend(sys.path) for dir in searchdirs: pathname = os.path.join(dir, filename) if os.path.exists(pathname): break else: raise ResourceFileNotFoundError, filename refno = open_pathname(pathname) h = type(resid) is type(1) and Res.GetResource(restype, resid) else: h = Res.GetNamedResource(restype, resid) return refno
"""macresource - Locate and open the resources needed for a script."""
#
"""PythonCGISlave.py