Skip to content

Instantly share code, notes, and snippets.

@anshultiwari1
Last active November 25, 2015 13:09
Show Gist options
  • Save anshultiwari1/af570fb5c80df05370b4 to your computer and use it in GitHub Desktop.
Save anshultiwari1/af570fb5c80df05370b4 to your computer and use it in GitHub Desktop.
getting all sequences and render info list for all shots and thier size on the disk, based on information fetched from tactic database.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
import json
from operator import itemgetter
from tabulate import tabulate
import datetime
import argparse
sys.path.append("/nas/projects/development/productionTools/assetPublisher/tactic_modules")
import queryClass as qClass
u = qClass.queryClass("bjTactic", "bilal")
import getTicket as serverSetup
userQuery = None
ticket = None
def getCompleteSeqInfo():
targetFolders = ["/nas/projects/Tactic/bilal/sequences/", "/nas/projects/Tactic/bilal/render/"]
tgt_files = {}
level = 0
for tgf in targetFolders:
for path, dirs, files in os.walk(tgf):
level += 1
tgt_files[(level, path)] = []
for fil in files:
tgt_files[(level, path)].append((fil, os.path.getsize(os.path.join(path, fil))))
if tgt_files:
json.dumps(tgt_files, ensure_ascii=False, sort_keys=True)
def csvCheck(seq):
infoCSV = '/nas/projects/development/sys-scripts/sequenceInfo.csv'
if os.path.isfile(infoCSV):
f = open(infoCSV, 'r')
for line in f:
if seq in line:
line.split(',')
def seqInfoDetails(seq_arg, flag=False):
seq_obj = u.getSeqSObjectbyName(seq_arg)
seq = seq_obj[0]['name']
seq_code = seq_obj[0]['code']
print "============ getting details for {0} ===============\n".format(seq)
print tabulate([[seq, seq_code, seq_obj[0]['description']]], tablefmt="fancy_grid")
alb_files = {}
fur_files = {}
maya_files = {}
pblast_files = {}
total_seq_size = 0
total_seq_render_size = 0
fileCount = 0
seq_path = "/nas/projects/Tactic/bilal/sequences/"
#seq_info = "The sequence details are:\n"
seq_info_table = []
filters=[]
filters.append(("seq_code", seq_code))
scenes = sorted(u.server.query("bilal/scn", filters=filters), key=itemgetter('name'))
print "\nSequence"
for scene in scenes:
scn = scene['name']
total_scn_size = 0
#print "------ {0}_{1} ------\n".format(seq, scn)
#seq_info_table.append([seq, scn, "", ""])
first_row = 1
for sh in sorted(u.getShtSObjectbyName(seq_code, scene['code']), key=itemgetter('name')):
shot_name = sh['name']
shot = '{0}_{1}'.format(sh['name'], sh['code'])
total_shot_size = 0
for path, dirs, files in os.walk(os.path.join(seq_path, seq, scn, shot)):
for fil in files:
sys.stdout.write('\x1b[2K')
sys.stdout.write("\rWorking on ... {0}".format(fil))
sys.stdout.flush()
total_seq_size += os.path.getsize(os.path.join(path, fil))
total_scn_size += os.path.getsize(os.path.join(path, fil))
total_shot_size += os.path.getsize(os.path.join(path, fil))
fileCount += 1
if '.abc' in fil:
alb_files[os.path.join(path, fil)] = os.path.getsize(os.path.join(path, fil))
if '.fur' in fil:
fur_files[os.path.join(path, fil)] = os.path.getsize(os.path.join(path, fil))
if '.ma' in fil or '.mb' in fil:
maya_files[os.path.join(path, fil)] = os.path.getsize(os.path.join(path, fil))
if '.mov' in fil:
pblast_files[os.path.join(path, fil)] = os.path.getsize(os.path.join(path, fil))
if first_row ==1:
seq_info_table.append([seq, scn, sh['name'], size_format(total_shot_size)])
first_row += 1
else:
seq_info_table.append(["", "", sh['name'], size_format(total_shot_size)])
seq_info_table.append(["", "TOTAL SCN SIZE", "", size_format(total_scn_size)])
seq_info_table.append(["", "", "", ""])
sys.stdout.write('\x1b[2K\n')
sys.stdout.flush()
#print "\n-------- summary --------\n"
seq_info_table.append(["TOTAL SEQ SIZE", "", "", size_format(total_seq_size)])
print tabulate(seq_info_table, headers=["seq", "scene", "shot", "size"], tablefmt="fancy_grid")
#seq_info += "of the total {0} files, there are:\n {1} in {2} alembic files,\n {3} in {4} fur yeti files,\n {5} in {6} maya files,\n {7} in {8} playblast files.\n".format(fileCount, size_format(sum(alb_files.values())), len(alb_files.keys()), size_format(sum(fur_files.values())), len(fur_files.keys()), size_format(sum(maya_files.values())), len(maya_files.keys()), size_format(sum(pblast_files.values())), len(pblast_files.keys()))
seq_info = "of the total {0} files, there are:\n {1} in {2} alembic files,\n {3} in {4} fur yeti files,\n {5} in {6} maya files,\n {7} in {8} playblast files.\n".format(fileCount, size_format(sum(alb_files.values())), len(alb_files.keys()), size_format(sum(fur_files.values())), len(fur_files.keys()), size_format(sum(maya_files.values())), len(maya_files.keys()), size_format(sum(pblast_files.values())), len(pblast_files.keys()))
if flag:
print seq_info
info = '/nas/projects/development/sys-scripts/infoReport/{0}/{0}_SequenceInfoReport_{1}.csv'.format(seq, str(datetime.date.today()))
if not os.path.exists('/nas/projects/development/sys-scripts/infoReport/'+seq+'/'):
os.makedirs('/nas/projects/development/sys-scripts/infoReport/'+seq+'/')
f = open(info, 'w+')
f.write('\nSequence info '+seq+'\n')
for row in seq_info_table:
f.write((','.join(str(ch) for ch in row)).replace('""',' ')+'\n')
#f.write('\n----------------------------------------\n')
f.close()
def renderInfoDetails(seq_arg):
seq_obj = u.getSeqSObjectbyName(seq_arg)
seq = seq_obj[0]['name']
seq_code = seq_obj[0]['code']
total_seq_render_size = 0
render_path = "/nas/projects/Tactic/bilal/render/"
#render_info = "\nAnd the render details are:\n"
render_info_table =[]
filters=[]
filters.append(("seq_code", seq_code))
scenes = sorted(u.server.query("bilal/scn", filters=filters), key=itemgetter('name'))
print "\nRender"
for scene in scenes:
scn = scene['name']
total_scn_render_size = 0
#print "------ {0}_{1} ------\n\n".format(seq, scn)
#render_info_table.append([seq, scn, "", ""])
first_row = 1
for sh in sorted(u.getShtSObjectbyName(seq_code, scene['code']), key=itemgetter('name'),):
shot_name = sh['name']
shot = '{0}_{1}'.format(sh['name'], sh['code'])
total_shot_render_size = 0
for path, dirs, files in os.walk(os.path.join(render_path, seq, scn, sh['name'])):
for fil in files:
sys.stdout.write('\x1b[2K')
sys.stdout.write("\rWorking on ... {0}".format(fil))
sys.stdout.flush()
total_seq_render_size += os.path.getsize(os.path.join(path, fil))
total_scn_render_size += os.path.getsize(os.path.join(path, fil))
total_shot_render_size += os.path.getsize(os.path.join(path, fil))
if first_row ==1:
render_info_table.append([seq, scn, sh['name'], size_format(total_shot_render_size)])
first_row += 1
else:
render_info_table.append(["", "", sh['name'], size_format(total_shot_render_size)])
render_info_table.append(["", "TOTAL SCN SIZE", "", size_format(total_scn_render_size)])
render_info_table.append(["", "", "", ""])
sys.stdout.write('\x1b[2K\n')
sys.stdout.flush()
render_info_table.append(["TOTAL SEQ SIZE", "", "", size_format(total_seq_render_size)])
print tabulate(render_info_table, headers=["scene", "shot", "size"], tablefmt="fancy_grid")
#render_info += "with the total render size is {0}.\n".format(size_format(total_seq_render_size))
#print render_info
print '\n'
info = '/nas/projects/development/sys-scripts/infoReport/{0}/{0}_RenderInfoReport_{1}.csv'.format(seq, str(datetime.date.today()))
if not os.path.exists('/nas/projects/development/sys-scripts/infoReport/'+seq+'/'):
os.makedirs('/nas/projects/development/sys-scripts/infoReport/'+seq+'/')
f = open(info, 'w+')
f.write('\nRender info '+seq+'\n')
for row in render_info_table:
f.write((','.join(str(ch) for ch in row)).replace('""',' ')+'\n')
#f.write('\n================================================\n')
f.close()
def size_format(size):
units = ['B', 'KB', 'MB', 'GB', 'TB']
for u in units:
if size < 1024: return '%0.2f %s' %(size, u)
size /= 1024.0
return '%0.2f %s' %(size, units[-1])
def reportWrite():
info = '/nas/projects/development/sys-scripts/{0}_InfoReport{1}.txt'.format(seq, str(datetime.date.today()))
if os.path.isfile(info):
f = open(info, 'a')
def tactic_login():
ip="tactic"
proj="bilal"
uname = "anshul"
passwd="anshul"
serverSetup.setupClientServer(server_name=ip, project_code=proj, login=uname, password=passwd)
userQuery = qClass.queryClass(ip, proj)
ticket = userQuery.userLogin(uname, passwd)
def getSequenceList():
seqList = []
for seq in u.server.query("bilal/seq", filters=[]):
seqList.append(seq['name'])
seqList.sort()
return seqList
def main():
parser = argparse.ArgumentParser(description="process some sequence.")
parser.add_argument("sequence", type=str, nargs='*', help="sequence name for details")
parser.add_argument('--verbose', action='store_true', help="additional info")
args = parser.parse_args()
#print args
if not ticket:
tactic_login()
if not args.sequence:
args.sequence = getSequenceList()
#print args.sequence
for seq in args.sequence:
seqInfoDetails(seq, args.verbose)
renderInfoDetails(seq)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment