'''
This Python script will check for naming convention errors in
all mayaAscii files in given director path.
wxPython must be installed for GUI of the Script.
'''
# ScanMayaFile.py
import os
import wx
import re
from mayaFileScanBaseClass import mayaFileScanBaseClass
class mayaScanUI(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(900, 700))
self.SetIcon(wx.Icon('M:/212p-asset_lib/mel/icons/mickey_small.bmp',\
wx.BITMAP_TYPE_ICO))
panel = wx.Panel(self, -1)
font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
font.SetPointSize(9)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
st1 = wx.StaticText(panel, -1, 'Directory :')
st1.SetFont(font)
hbox1.Add(st1, 0, wx.RIGHT, 8)
self.tc1 = wx.TextCtrl(panel, -1,size=(100,22))
hbox1.Add(self.tc1, 2)
btn1 = wx.Button(panel, 101, 'Browse', size=(50, 23))
hbox1.Add(btn1,0)
vbox.Add(hbox1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
#vbox.Add((-1, 2))
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st2 = wx.StaticText(panel, -1, 'Log File :')
st2.SetFont(font)
hbox2.Add(st2, 0, wx.RIGHT, 8)
self.tc2 = wx.TextCtrl(panel, -1,size=(100,22))
hbox2.Add(self.tc2, 2)
btn2 = wx.Button(panel, 102, 'Browse', size=(50, 23))
hbox2.Add(btn2,0)
vbox.Add(hbox2, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
vbox.Add((-1, 10))
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
st3 = wx.StaticText(panel, -1, 'Error Log')
st3.SetFont(font)
hbox4.Add(st3, 0)
vbox.Add(hbox4, 0, wx.LEFT | wx.TOP, 10)
vbox.Add((-1, 10))
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.tc_txt = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE)
hbox3.Add(self.tc_txt, 1, wx.EXPAND)
vbox.Add(hbox3, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
vbox.Add((-1, 25))
vbox.Add((-1, 25))
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
btn_scn = wx.Button(panel, 104, 'Scan', size=(70, 30))
hbox5.Add(btn_scn, 0)
btn_cl = wx.Button(panel, 103, 'Close', size=(70, 30))
hbox5.Add(btn_cl, 0, wx.LEFT | wx.BOTTOM , 5)
vbox.Add(hbox5, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
self.Bind(wx.EVT_BUTTON, self.OnClose, id=103)
self.Bind(wx.EVT_BUTTON, self.opendir, id=101)
self.Bind(wx.EVT_BUTTON, self.openfile,id=102)
self.Bind(wx.EVT_BUTTON, self.scan_mayafile,id=104)
def OnClose(self,event):
self.Close()
def opendir(self, event):
dlg = wx.DirDialog(self, "Choose a directory:",\
style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
self.tc1.AppendText(dlg.GetPath())
dlg.Destroy()
def openfile(self, event):
dlg = wx.FileDialog(self, "Save Log File", os.getcwd(), "", "*.txt", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
mypath = os.path.basename(path)
self.tc2.AppendText(path)
dlg.Destroy()
def scan_mayafile(self,event):
'''Scans All Maya Files'''
basedir = self.tc1.GetValue()
logfile = self.tc2.GetValue()
epnames=['Prefix_']
for root,dirs,files in os.walk(basedir):
for f in files:
if(f.endswith('.ma')):
st =('\n\n-------------------------------------------------------------\n'+\
'Scanning File : '+os.path.join(root,f)+'\n--------------------------------\
-----------------------------'+'\n\n')
self.tc_txt.AppendText(st)
file = mayaFileScanBaseClass(os.path.join(root,f))
nodenames = file.fileScan()
for n in nodenames:
st =('Incorrect Node Name : '+n+'\n')
ftnpaths = file.fileScan_ftn()
if len(ftnpaths) > 0:
for ftn in ftnpaths:
if os.path.exists(ftn):
sub = ftn.split('/')
substr = sub[len(sub)-1]
i = 0
for j in epnames:
if substr.startswith(j):
i = 1
start = j
break
if i==0:
st =('File Name Wrong : '+substr+'\n')
self.tc_txt.AppendText(st)
else:
substr2 = substr.strip(start)
if len(re.findall('\W',substr2[0:-4])) > 0:
st =('Illegal Characters : '+substr+'\n')
self.tc_txt.AppendText(st)
else:
st =('Missing File : '+ftn+'\n')
self.tc_txt.AppendText(st)
#log.write('\n------------------------------------------------------------------\n')
self.tc_txt.AppendText('\n--------------------End of Scanning\
----------------------------------------------\n')
if logfile != '':
log = open(logfile,'w')
log.write(self.tc_txt.GetValue())
log.close()
app = wx.App()
mayaScanUI(None, -1, 'Scan mayaFile for Shader/Texture Network')
app.MainLoop()
No comments:
Post a Comment