Python win32com.__gen_path__() Examples
The following are 10
code examples of win32com.__gen_path__().
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
win32com
, or try the search function
.
Example #1
Source File: test_sandbox.py From pledgeservice with Apache License 2.0 | 7 votes |
def test_win32com(self): """ win32com should not be prevented from caching COM interfaces in gen_py. """ import win32com gen_py = win32com.__gen_path__ target = os.path.join(gen_py, 'test_write') sandbox = DirectorySandbox(self.dir) try: try: sandbox.run(self._file_writer(target)) except SandboxViolation: self.fail("Could not create gen_py file due to SandboxViolation") finally: if os.path.exists(target): os.remove(target)
Example #2
Source File: gencache.py From ironpython2 with Apache License 2.0 | 6 votes |
def GetGeneratePath(): """Returns the name of the path to generate to. Checks the directory is OK. """ assert not is_readonly, "Why do you want the genpath for a readonly store?" try: os.makedirs(win32com.__gen_path__) #os.mkdir(win32com.__gen_path__) except os.error: pass try: fname = os.path.join(win32com.__gen_path__, "__init__.py") os.stat(fname) except os.error: f = open(fname,"w") f.write('# Generated file - this directory may be deleted to reset the COM cache...\n') f.write('import win32com\n') f.write('if __path__[:-1] != win32com.__gen_path__: __path__.append(win32com.__gen_path__)\n') f.close() return win32com.__gen_path__ # # The helpers for win32com.client.Dispatch and OCX clients. #
Example #3
Source File: test_sandbox.py From oss-ftp with MIT License | 6 votes |
def test_win32com(self): """ win32com should not be prevented from caching COM interfaces in gen_py. """ import win32com gen_py = win32com.__gen_path__ target = os.path.join(gen_py, 'test_write') sandbox = DirectorySandbox(self.dir) try: try: sandbox.run(self._file_writer(target)) except SandboxViolation: self.fail("Could not create gen_py file due to SandboxViolation") finally: if os.path.exists(target): os.remove(target)
Example #4
Source File: test_sandbox.py From Flask with Apache License 2.0 | 6 votes |
def test_win32com(self): """ win32com should not be prevented from caching COM interfaces in gen_py. """ import win32com gen_py = win32com.__gen_path__ target = os.path.join(gen_py, 'test_write') sandbox = DirectorySandbox(self.dir) try: try: sandbox.run(self._file_writer(target)) except SandboxViolation: self.fail("Could not create gen_py file due to SandboxViolation") finally: if os.path.exists(target): os.remove(target)
Example #5
Source File: test_sandbox.py From Flask with Apache License 2.0 | 6 votes |
def test_win32com(self): """ win32com should not be prevented from caching COM interfaces in gen_py. """ import win32com gen_py = win32com.__gen_path__ target = os.path.join(gen_py, 'test_write') sandbox = DirectorySandbox(self.dir) try: try: sandbox.run(self._file_writer(target)) except SandboxViolation: self.fail("Could not create gen_py file due to SandboxViolation") finally: if os.path.exists(target): os.remove(target)
Example #6
Source File: gencache.py From ironpython2 with Apache License 2.0 | 5 votes |
def _SaveDicts(): if is_readonly: raise RuntimeError("Trying to write to a readonly gencache ('%s')!" \ % win32com.__gen_path__) f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb") try: p = pickle.Pickler(f) p.dump(pickleVersion) p.dump(clsidToTypelib) finally: f.close()
Example #7
Source File: gencache.py From ironpython2 with Apache License 2.0 | 5 votes |
def _Dump(): print "Cache is in directory", win32com.__gen_path__ # Build a unique dir d = {} for clsid, (typelibCLSID, lcid, major, minor) in clsidToTypelib.iteritems(): d[typelibCLSID, lcid, major, minor] = None for typelibCLSID, lcid, major, minor in d.iterkeys(): mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor) print "%s - %s" % (mod.__doc__, typelibCLSID) # Boot up
Example #8
Source File: sapi5com.py From awesometts-anki-addon with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): """ Attempts to retrieve list of voices from the SAPI.SpVoice API. However, if not running on Windows, no environment inspection is attempted and an exception is immediately raised. """ if not self.IS_WINDOWS: raise EnvironmentError("SAPI 5 is only available on Windows") super(SAPI5COM, self).__init__(*args, **kwargs) # win32com and pythoncom are Windows only, pylint:disable=import-error try: import win32com.client except IOError: # some Anki packages have an unwritable cache path self._logger.warn("win32com.client import failed; trying again " "with alternate __gen_path__ set") import win32com import os.path import tempfile win32com.__gen_path__ = os.path.join(tempfile.gettempdir(), 'gen_py') import win32com.client self._client = win32com.client import pythoncom self._pythoncom = pythoncom # pylint:enable=import-error voices = self._client.Dispatch('SAPI.SpVoice').getVoices() self._voice_map = { voice.getAttribute('name'): voice for voice in [voices.item(i) for i in range(voices.count)] } if not self._voice_map: raise EnvironmentError("No voices returned by SAPI 5")
Example #9
Source File: gencache.py From ironpython2 with Apache License 2.0 | 4 votes |
def _LoadDicts(): # Load the dictionary from a .zip file if that is where we live. if hasattr(win32com, "__loader__"): import cStringIO as io loader = win32com.__loader__ arc_path = loader.archive dicts_path = os.path.join(win32com.__gen_path__, "dicts.dat") if dicts_path.startswith(arc_path): dicts_path = dicts_path[len(arc_path)+1:] else: # Hm. See below. return try: data = loader.get_data(dicts_path) except AttributeError: # The __loader__ has no get_data method. See below. return except IOError: # Our gencache is in a .zip file (and almost certainly readonly) # but no dicts file. That actually needn't be fatal for a frozen # application. Assuming they call "EnsureModule" with the same # typelib IDs they have been frozen with, that EnsureModule will # correctly re-build the dicts on the fly. However, objects that # rely on the gencache but have not done an EnsureModule will # fail (but their apps are likely to fail running from source # with a clean gencache anyway, as then they would be getting # Dynamic objects until the cache is built - so the best answer # for these apps is to call EnsureModule, rather than freezing # the dict) return f = io.StringIO(data) else: # NOTE: IOError on file open must be caught by caller. f = open(os.path.join(win32com.__gen_path__, "dicts.dat"), "rb") try: p = pickle.Unpickler(f) version = p.load() global clsidToTypelib clsidToTypelib = p.load() versionRedirectMap.clear() finally: f.close()
Example #10
Source File: gencache.py From ironpython2 with Apache License 2.0 | 4 votes |
def GetGeneratedInfos(): zip_pos = win32com.__gen_path__.find(".zip\\") if zip_pos >= 0: import zipfile zip_file = win32com.__gen_path__[:zip_pos+4] zip_path = win32com.__gen_path__[zip_pos+5:].replace("\\", "/") zf = zipfile.ZipFile(zip_file) infos = {} for n in zf.namelist(): if not n.startswith(zip_path): continue base = n[len(zip_path)+1:].split("/")[0] try: iid, lcid, major, minor = base.split("x") lcid = int(lcid) major = int(major) minor = int(minor) iid = pywintypes.IID("{" + iid + "}") except ValueError: continue except pywintypes.com_error: # invalid IID continue infos[(iid, lcid, major, minor)] = 1 zf.close() return list(infos.keys()) else: # on the file system files = glob.glob(win32com.__gen_path__+ "\\*") ret = [] for file in files: if not os.path.isdir(file) and not os.path.splitext(file)[1]==".py": continue name = os.path.splitext(os.path.split(file)[1])[0] try: iid, lcid, major, minor = name.split("x") iid = pywintypes.IID("{" + iid + "}") lcid = int(lcid) major = int(major) minor = int(minor) except ValueError: continue except pywintypes.com_error: # invalid IID continue ret.append((iid, lcid, major, minor)) return ret