Update search_undefinedFunctions.py (#7780)

This commit is contained in:
PabstMirror 2020-06-30 11:43:00 -05:00 committed by GitHub
parent ce0701864c
commit a39faa2026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,52 +7,68 @@ import ntpath
import sys import sys
import argparse import argparse
# handle x64 python clipboard, ref https://forums.autodesk.com/t5/maya-programming/ctypes-bug-cannot-copy-data-to-clipboard-via-python/m-p/9197068/highlight/true#M10992
import ctypes import ctypes
from ctypes import wintypes
CF_UNICODETEXT = 13
#from http://stackoverflow.com/a/3429034
#Get required functions, strcpy..
strcpy = ctypes.cdll.msvcrt.strcpy
ocb = ctypes.windll.user32.OpenClipboard #Basic Clipboard functions
ecb = ctypes.windll.user32.EmptyClipboard
gcd = ctypes.windll.user32.GetClipboardData
scd = ctypes.windll.user32.SetClipboardData
ccb = ctypes.windll.user32.CloseClipboard
ga = ctypes.windll.kernel32.GlobalAlloc # Global Memory allocation
gl = ctypes.windll.kernel32.GlobalLock # Global Memory Locking
gul = ctypes.windll.kernel32.GlobalUnlock
GMEM_DDESHARE = 0x2000
def Get( ): user32 = ctypes.WinDLL('user32')
ocb(None) # Open Clip, Default task kernel32 = ctypes.WinDLL('kernel32')
pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ...
data = ctypes.c_char_p(pcontents).value OpenClipboard = user32.OpenClipboard
#gul(pcontents) ? OpenClipboard.argtypes = wintypes.HWND,
ccb() OpenClipboard.restype = wintypes.BOOL
return data CloseClipboard = user32.CloseClipboard
CloseClipboard.restype = wintypes.BOOL
EmptyClipboard = user32.EmptyClipboard
EmptyClipboard.restype = wintypes.BOOL
GetClipboardData = user32.GetClipboardData
GetClipboardData.argtypes = wintypes.UINT,
GetClipboardData.restype = wintypes.HANDLE
SetClipboardData = user32.SetClipboardData
SetClipboardData.argtypes = (wintypes.UINT, wintypes.HANDLE)
SetClipboardData.restype = wintypes.HANDLE
GlobalLock = kernel32.GlobalLock
GlobalLock.argtypes = wintypes.HGLOBAL,
GlobalLock.restype = wintypes.LPVOID
GlobalUnlock = kernel32.GlobalUnlock
GlobalUnlock.argtypes = wintypes.HGLOBAL,
GlobalUnlock.restype = wintypes.BOOL
GlobalAlloc = kernel32.GlobalAlloc
GlobalAlloc.argtypes = (wintypes.UINT, ctypes.c_size_t)
GlobalAlloc.restype = wintypes.HGLOBAL
GlobalSize = kernel32.GlobalSize
GlobalSize.argtypes = wintypes.HGLOBAL,
GlobalSize.restype = ctypes.c_size_t
GMEM_MOVEABLE = 0x0002
GMEM_ZEROINIT = 0x0040
def Paste( data ): def Paste( data ):
ocb(None) # Open Clip, Default task data = data.encode('utf-16le')
ecb() OpenClipboard(None)
hCd = ga( GMEM_DDESHARE, len( bytes(data,"ascii") )+1 ) EmptyClipboard()
pchData = gl(hCd) handle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, len(data) + 2)
strcpy(ctypes.c_char_p(pchData),bytes(data,"ascii")) pcontents = GlobalLock(handle)
gul(hCd) ctypes.memmove(pcontents, data, len(data))
scd(1,hCd) GlobalUnlock(handle)
ccb() SetClipboardData(CF_UNICODETEXT, handle)
CloseClipboard()
def getFunctions(filepath): def getFunctions(filepath):
selfmodule = (re.search('addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1) selfmodule = (re.search(r'addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1)
# print("Checking {0} from {1}".format(filepath,selfmodule)) # print("Checking {0} from {1}".format(filepath,selfmodule))
with open(filepath, 'r') as file: with open(filepath, 'r') as file:
content = file.read() content = file.read()
srch = re.compile('[^E]FUNC\(([_a-zA-Z0-9]*)\)') srch = re.compile(r'[^E]FUNC\(([_a-zA-Z0-9]*)\)')
modfuncs = srch.findall(content) modfuncs = srch.findall(content)
modfuncs = sorted(set(modfuncs)) modfuncs = sorted(set(modfuncs))
srch = re.compile('EFUNC\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)') srch = re.compile(r'EFUNC\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)')
exfuncs = srch.findall(content) exfuncs = srch.findall(content)
exfuncs = sorted(set(exfuncs)) exfuncs = sorted(set(exfuncs))
@ -67,17 +83,17 @@ def getFunctions(filepath):
def getStrings(filepath): def getStrings(filepath):
selfmodule = (re.search('addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1) selfmodule = (re.search(r'addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1)
# print("Checking {0} from {1}".format(filepath,selfmodule)) # print("Checking {0} from {1}".format(filepath,selfmodule))
with open(filepath, 'r') as file: with open(filepath, 'r') as file:
content = file.read() content = file.read()
srch = re.compile('[^E][CL]STRING\(([_a-zA-Z0-9]*)\)') srch = re.compile(r'[^E][CL]STRING\(([_a-zA-Z0-9]*)\)')
modStrings = srch.findall(content) modStrings = srch.findall(content)
modStrings = sorted(set(modStrings)) modStrings = sorted(set(modStrings))
srch = re.compile('E[CL]STRING\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)') srch = re.compile(r'E[CL]STRING\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)')
exStrings = srch.findall(content) exStrings = srch.findall(content)
exStrings = sorted(set(exStrings)) exStrings = sorted(set(exStrings))
@ -126,7 +142,7 @@ def main():
outputCode = "{0} allFunctions = {1}; allStrings = {2}; {3} {4}".format(codeHeader, list(set(allFunctions)), list(set(allStrings)), codeFuncCheck, codeStringCheck) outputCode = "{0} allFunctions = {1}; allStrings = {2}; {3} {4}".format(codeHeader, list(set(allFunctions)), list(set(allStrings)), codeFuncCheck, codeStringCheck)
print(outputCode) print(outputCode)
Paste(outputCode); Paste(outputCode)
print ("") print ("")
print ("Copied to clipboard, [funcs {0} / strings {1}]'".format(len(set(allFunctions)), len(set(allStrings)))) print ("Copied to clipboard, [funcs {0} / strings {1}]'".format(len(set(allFunctions)), len(set(allStrings))))