zander opened this issue on Jan 13, 2021 ยท 14 posts
structure posted Thu, 14 January 2021 at 9:53 PM Forum Coordinator
This script works with both normal and gzipped files
from __future__ import print_function
import gzip
import os
import os.path
import sys
# =====================================================
class _dialogs:
def get_folder( self, start = "" ):
style = ( wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON )
dialog = wx.DirDialog( None, 'Select a Folder ', start , style )
return dialog.GetPath() if dialog.ShowModal() == wx.ID_OK else False
# =====================================================
def read_lines( lines, isgzipped, references = [] ):
if isgzipped:
lines = lines.split("\n")
for line in lines:
if "Runtime" in line.title():
if not line.lstrip() in references:
references.append( line.lstrip() )
return references
# =====================================================
def has_extension( object_type ):
try:
ext = os.path.splitext( object_type )[1]
except:
ext = None
if ext:
return True
else:
return False
# =====================================================
def is_gz_file(filepath):
with open(filepath, 'rb') as check_gz_status:
return check_gz_status.read(2) == b'\x1f\x8b'
# =====================================================
def print_references( references ):
if references:
for ref in references:
print( ref.rstrip() )
# =====================================================
def legal_file_types():
return ('.pz3','.cr2','.pz2','.pp2','.hr2','.fc2','.hd2','.lt2','.cm2','.mt5','.mc6',
'.pzz','.crz','.p2z','.ppz','.hrz','.fcz','.hdz','.ltz','.cmz','.mz5','.mcz')
# =====================================================
use_exts = legal_file_types()
searchfolder = _dialogs().get_folder()
underline = '-'*30
references = []
sysop = False
# =====================================================
if searchfolder:
list_of_files = os.listdir( searchfolder )
for file in list_of_files:
file = os.path.join( searchfolder, file )
if file.endswith( use_exts ):
if has_extension( file ):
if sys.version_info.major == 3:
sysop = True
print( f"\n\nExamining {file}\n{underline}\n" )
elif sys.version_info.major == 2:
sysop = True
print( "\n\nExamining {}\n{}\n".format( file, underline ) )
else:
sysop = False
print( "Python 2 or 3 is required to run this file.")
if sysop:
if not is_gz_file( file ):
try:
with open( file, "r" ) as lines:
references = read_lines( lines, False, references )
print_references( references )
except:
continue
else:
if not file.endswith( ignore_exts ):
with gzip.open( file ,'rb' ) as lines:
lines = lines.read()
lines = lines.decode("utf8")
references = read_lines( lines, True )
print_references( references )
references = []
# =====================================================
this gives an output resembling this:
Examining x:\\Poser\\Runtime\\Libraries\\Character\\Creepy Kid Too\\Creepy Kid 2 WM 9+.cr2
------------------------------
figureResFile :Runtime:Geometries:Creepy Kid Too:Creepy Kid Too.obj
textureMap ":Runtime:Textures:Creepy Kid Too:TeethGums.jpg"
file ":Runtime:Textures:Creepy Kid Too:TeethGums.jpg"
textureMap ":Runtime:Textures:Creepy Kid Too:EyesTex.jpg"
file ":Runtime:Textures:Creepy Kid Too:EyesTex.jpg"
reflectionMap ":Runtime:Textures:Creepy Kid Too:EyesTex.jpg"
bumpMap ":Runtime:Textures:Creepy Kid Too:TeethGums.jpg"
textureMap ":Runtime:Textures:Creepy Kid Too:Body.jpg"
file ":Runtime:Textures:Creepy Kid Too:Body.jpg"
file ":Runtime:Textures:Creepy Kid Too:displace.jpg"
Locked Out