本文整理汇总了Python中win32com.__gen_path__方法的典型用法代码示例。如果您正苦于以下问题:Python win32com.__gen_path__方法的具体用法?Python win32com.__gen_path__怎么用?Python win32com.__gen_path__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32com
的用法示例。
在下文中一共展示了win32com.__gen_path__方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_win32com
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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)
示例2: GetGeneratePath
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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.
#
示例3: _SaveDicts
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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()
示例4: _Dump
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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
示例5: __init__
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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")
示例6: _LoadDicts
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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()
示例7: GetGeneratedInfos
# 需要导入模块: import win32com [as 别名]
# 或者: from win32com import __gen_path__ [as 别名]
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