Exemplo n.º 1
0
def ShowInfo(spec):
	if not spec:
		tlbSpec = selecttlb.SelectTlb(excludeFlags=selecttlb.FLAG_HIDDEN)
		if tlbSpec is None:
			return
		try:
			tlb = pythoncom.LoadRegTypeLib(tlbSpec.clsid, tlbSpec.major, tlbSpec.minor, tlbSpec.lcid)
		except pythoncom.com_error: # May be badly registered.
			sys.stderr.write("Warning - could not load registered typelib '%s'\n" % (tlbSpec.clsid))
			tlb = None
		
		infos = [(tlb, tlbSpec)]
	else:
		infos = GetTypeLibsForSpec(spec)
	for (tlb, tlbSpec) in infos:
		desc = tlbSpec.desc
		if desc is None:
			if tlb is None:
				desc = "<Could not load typelib %s>" % (tlbSpec.dll)
			else:
				desc = tlb.GetDocumentation(-1)[0]
		print(desc)
		print(" %s, lcid=%s, major=%s, minor=%s" % (tlbSpec.clsid, tlbSpec.lcid, tlbSpec.major, tlbSpec.minor))
		print(" >>> # Use these commands in Python code to auto generate .py support")
		print(" >>> from win32com.client import gencache")
		print(" >>> gencache.EnsureModule('%s', %s, %s, %s)" % (tlbSpec.clsid, tlbSpec.lcid, tlbSpec.major, tlbSpec.minor))
Exemplo n.º 2
0
def main():
	import getopt
	hiddenSpec = 1
	outputName = None
	verboseLevel = 1
	doit = 1
	bForDemand = bForDemandDefault
	try:
		opts, args = getopt.getopt(sys.argv[1:], 'vo:huiqd')
		for o,v in opts:
			if o=='-h':
				hiddenSpec = 0
			elif o=='-o':
				outputName = v
			elif o=='-v':
				verboseLevel = verboseLevel + 1
			elif o=='-q':
				verboseLevel = verboseLevel - 1
			elif o=='-i':
				if len(args)==0:
					ShowInfo(None)
				else:
					for arg in args:
						ShowInfo(arg)
				doit = 0
			elif o=='-d':
				bForDemand = not bForDemand

	except (getopt.error, error) as msg:
		sys.stderr.write (str(msg) + "\n")
		usage()

	if bForDemand and outputName is not None:
		sys.stderr.write("Can not use -d and -o together\n")
		usage()

	if not doit:
		return 0		
	if len(args)==0:
		rc = selecttlb.SelectTlb()
		if rc is None:
			sys.exit(1)
		args = [ rc ]

	if outputName is not None:
		path = os.path.dirname(outputName)
		if path != '' and not os.path.exists(path):
			os.makedirs(path)
		if sys.version_info > (3,0):
			f = open(outputName, "wt", encoding="mbcs")
		else:
			import codecs # not available in py3k.
			f = codecs.open(outputName, "w", "mbcs")			
	else:
		f = None

	for arg in args:
		GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel, bForDemand = bForDemand, bBuildHidden = hiddenSpec)

	if f:	
		f.close()
                doit = 0
            elif o == '-d':
                bForDemand = not bForDemand

    except (getopt.error, error), msg:
        sys.stderr.write(str(msg) + "\n")
        usage()

    if bForDemand and outputName is not None:
        sys.stderr.write("Can not use -d and -o together\n")
        usage()

    if not doit:
        return 0
    if len(args) == 0:
        rc = selecttlb.SelectTlb()
        if rc is None:
            sys.exit(1)
        args = [rc]

    if outputName is not None:
        path = os.path.dirname(outputName)
        if path != '' and not os.path.exists(path):
            os.makedirs(path)
        if sys.version_info > (3, 0):
            f = open(outputName, "wt", encoding="mbcs")
        else:
            import codecs  # not available in py3k.
            f = codecs.open(outputName, "w", "mbcs")
    else:
        f = None