def _test_get_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] filters.append( ['bin_id', bin_id] ) connectors = server.query("prod/submission_in_bin", filters) # get all of the submissions from the bin submission_ids = [x.get('submission_id') for x in connectors] filters = [ ['id', submission_ids] ] submissions = server.query("prod/submission", filters) # get all of the snapshots from the submissions for submission in submissions: search_key = submission.get('__search_key__') print "-"*20 snapshot = server.get_snapshot(search_key, include_paths=True) paths = snapshot.get('__paths__') for path in paths: print path
def _test_get_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] filters.append(['bin_id', bin_id]) connectors = server.query("prod/submission_in_bin", filters) # get all of the submissions from the bin submission_ids = [x.get('submission_id') for x in connectors] filters = [['id', submission_ids]] submissions = server.query("prod/submission", filters) # get all of the snapshots from the submissions for submission in submissions: search_key = submission.get('__search_key__') print "-" * 20 snapshot = server.get_snapshot(search_key, include_paths=True) paths = snapshot.get('__paths__') for path in paths: print path
def search(cls, filters=[]): SubjectInfo.logger.debug("Search with cls: %s" % cls) server = TacticServerStub() objects = server.query(cls.stype, filters=filters) # Here we do something different si = SubjectInfo(objects) return si
def main(): # get an instance of the stub server = TacticServerStub() # start the transaction server.start("Set query") try: # define the search type we are searching for search_type = "prod/asset" # define a filter filters = [] filters.append( ("asset_library", "chr") ) # do the query assets = server.query(search_type, filters) # show number found print("found [%s] assets" % len(assets) ) # go through the asset and print the code for asset in assets: code = asset.get("code") print(code) except: # in the case of an exception, abort all of the interactions server.abort() raise else: # otherwise, finish the transaction server.finish()
def main(args): # USAGE: query_shot.py <shot_code> shot_code = args[0] server = TacticServerStub() search_key = server.build_search_type(SEARCH_TYPE) # do the actual work server.start("Queried shot [%s]" % shot_code) try: filters = [('code', shot_code)] print server.query(search_key, filters) except: server.abort() raise else: server.finish()
def main(args): # USAGE: query_shot.py <shot_code> shot_code = args[0] server = TacticServerStub() search_key = server.build_search_type(SEARCH_TYPE) # do the actual work server.start("Queried shot [%s]" % shot_code) try: filters = [ ('code', shot_code) ] print server.query(search_key, filters) except: server.abort() raise else: server.finish()
def main(args): usage = "USAGE: checkin.py <search_type> <code> [context] <path>\n" usage += "example: python checkin.py beat Sc01.Bt01 .\\test\\image.png" context = "publish" # TODO: lots of assumptions here if len(args) == 2: # assume code and file path are equivalent code = args[1] file_path = args[1] elif len(args) == 3: code = args[1] file_path = args[2] elif len(args) == 4: code = args[1] context = args[2] file_path = args[3] else: print usage return search_type = args[0] server = TacticServerStub() # do the actual work server.start("Checked in file [%s] to [%s] - [%s]" % (file_path, search_type, code)) try: # query all of the search_types to simplify argument if search_type.find("/") == -1: columns = ["search_type"] results = server.query("sthpw/search_object", columns=columns) for result in results: test = result.get("search_type") if test.endswith("/%s" % search_type): search_type = test break else: raise Exception("Search type [%s] not found" % search_type) search_key = server.build_search_key(search_type, code) # upload the file server.upload_file(file_path) # checkin the uploaded file result = server.simple_checkin(search_key, context, file_path) except Exception as e: server.abort() print "ERROR: ", e.__str__() else: server.finish()
def main(args): usage = "USAGE: checkin.py <search_type> <code> [context] <path>\n" usage += "example: python checkin.py beat Sc01.Bt01 .\\test\\image.png" context = "publish" # TODO: lots of assumptions here if len(args) == 2: # assume code and file path are equivalent code = args[1] file_path = args[1] elif len(args) == 3: code = args[1] file_path = args[2] elif len(args) == 4: code = args[1] context = args[2] file_path = args[3] else: print usage return search_type = args[0] server = TacticServerStub() # do the actual work server.start("Checked in file [%s] to [%s] - [%s]" % (file_path, search_type, code) ) try: # query all of the search_types to simplify argument if search_type.find("/") == -1: columns = ["search_type"] results = server.query("sthpw/search_object", columns=columns) for result in results: test = result.get("search_type") if test.endswith("/%s" % search_type): search_type = test break else: raise Exception("Search type [%s] not found" % search_type) search_key = server.build_search_key(search_type, code) # upload the file server.upload_file(file_path) # checkin the uploaded file result = server.simple_checkin(search_key, context, file_path) except Exception, e: server.abort() print "ERROR: ", e.__str__()
def main(args, login=None): # USAGE: checkin_plates.py code = args[0] file_range = args[1] pattern = args[2] # hard-coded for now context = 'publish' server = TacticServerStub(login) # do the actual work server.start("Checked in file group [%s]" % pattern) try: # checkin the uploaded file filters = [] filters.append(('code', code)) results = server.query(SEARCH_TYPE, filters) # take the first one if results: id = results[0].get('id') else: print "Plate with code [%s] not found. Please insert an entry in the Plates tab first." %code return search_key = server.build_search_key(SEARCH_TYPE, id, column='id') # move the file dir = server.get_handoff_dir() print "Copied files to handoff dir\n" new_pattern = pattern file_type = 'main' # run group checkin server.group_checkin(search_key, context, file_path=new_pattern, file_type=file_type, \ file_range=file_range, mode='copy', info={'type':'2d_plates'}) except: server.abort() raise else: server.finish()
def main(args): search_type = args[0] code = args[1] if len(args) == 2: context = "publish" to_dir = "." elif len(args) == 3: context = "publish" to_dir = args[2] else: context = args[2] to_dir = args[3] server = TacticServerStub() # do the actual work server.start("Checked out file/s to [%s]" % to_dir) try: # query all of the search_types to simplify argument if search_type.find("/") == -1: columns = ["search_type"] results = server.query("sthpw/search_object", columns=columns) for result in results: test = result.get("search_type") if test.endswith("/%s" % search_type): search_type = test break else: raise Exception("Search type [%s] not found" % search_type) search_key = server.build_search_key(search_type, code) # checkin the uploaded file version = -1 result = server.checkout(search_key, context, version=version, to_dir=to_dir) print result except: server.abort() raise else: server.finish()
def main(args, login=None): # USAGE: checkin_render_layer.py shot_code = args[0] layer_name = args[1] version = args[2] context = args[3] file_range = args[4] pattern = args[5] server = TacticServerStub(login) # do the actual work server.start("Checked in file group [%s] to shot [%s] layer [%s]" % (pattern, shot_code, layer_name)) try: # move the file dir = server.get_handoff_dir() paths = expand_paths(pattern, file_range) move_file(paths, dir) file_name = os.path.basename(pattern) new_pattern = '%s/%s' % (dir, file_name) print "Files moved to handoff dir.\n" # checkin the moved files filters = [] filters.append(('shot_code', shot_code)) filters.append(('name', layer_name)) results = server.query('prod/layer', filters) # take the first one if results: id = results[0].get('id') search_type = server.build_search_type('prod/layer') # find the layer snapshot filters = [] filters.append(('version', version)) filters.append(('search_type', search_type)) filters.append(('search_id', id)) #TODO : may need a context to search for the proper layer results = server.query('sthpw/snapshot', filters) snap_code = '' if results: snap_code = results[0].get('code') # find the render render = None filters = [] filters.append(('search_type', search_type)) filters.append(('search_id', id)) filters.append(('snapshot_code', snap_code)) results = server.query(SEARCH_TYPE, filters) if results: render = results[0] if not render: render_data = { 'search_type': search_type, 'search_id': id, 'snapshot_code': snap_code } render = server.insert("prod/render", render_data) ''' results = server.query(SEARCH_TYPE, filters) render_id = 0 if results: render_id = results[0].get('id') # find the render id search_key = server.build_search_key(SEARCH_TYPE, render_id, column='id') ''' file_type = 'main' # run group checkin server.group_checkin(render.get("__search_key__"), context=context, file_path=new_pattern, file_type=file_type, file_range=file_range) except: server.abort() raise else: server.finish()
def main(args, login=None): # USAGE: checkin_render.py type = args[0] if type == "shot": parent_search_type = "prod/shot" elif type == "asset": parent_search_type = "prod/asset" else: parent_search_type = type code = args[1] file_range = args[2] pattern = args[3] layer_name = '' context = 'publish' if type == "layer": parent_search_type = "prod/layer" code, layer_name = args[1].split('|') server = TacticServerStub(login) # do the actual work server.start("Checked in file group [%s] to %s [%s]" % (pattern,type,code)) try: # checkin the uploaded file filters = [] if type=='layer': filters.append(('shot_code', code)) filters.append(('name', layer_name)) else: filters.append(('code', code)) results = server.query(parent_search_type, filters) # take the first one if results: id = results[0].get('id') else: if type =='layer': print "%s Code [%s] name [%s] not found. Please insert an entry in TACTIC first." %(type, code, layer_name) else: print "%s Code [%s] not found. Please insert an entry in TACTIC first." %(type, code) search_type = server.build_search_type(parent_search_type) file_type = 'main' render_type = '' # not used yet # move the file dir = server.get_handoff_dir() paths = expand_paths(pattern, file_range) copy_file(paths, dir) file_name = os.path.basename(pattern) new_pattern = '%s/%s' %(dir, file_name) print "Copied files to handoff dir\n" render = find_render(server, search_type, id, login, render_type) if not render: render_data = { 'search_type': search_type, 'search_id': id, 'login': login #'type': render_type } render = server.insert("prod/render", render_data) # run group checkin server.group_checkin(render.get("__search_key__"), context=context, file_path=new_pattern, file_type=file_type, file_range=file_range) except: server.abort() raise else: server.finish()
class Sample3dTest(unittest.TestCase): def setUp(self): pass def test_all(self): print "Running Sample3d Test" from pyasm.security import Batch from pyasm.biz import Project Batch() Project.set_project("sample3d") #self.server = TacticServerStub(protocol="local") self.server = TacticServerStub(protocol="xmlrpc") project_code = "sample3d" self.server.set_project(project_code) self.server.start("Sample3d Test") try: self._test_create_search_type() self._test_create_submission() self._test_get_submission() self._test_shot_sequence_hierarchy() self._test_query_snapshots() #self._test_performance() except Exception: self.server.abort() raise self.server.abort() #try: # self.server.query("prod/asset") #except Exception: # self.server.abort() # raise #self.server.abort() def _test_query_snapshots(self): filters = [] filters.append(['context', 'model']) filters.append(['search_type', 'prod/asset?project=sample3d']) snapshots = self.server.query_snapshots(filters=filters, include_paths=True) import time start = time.time() for snapshot in snapshots: print snapshot.get('__search_key__') print snapshot.get('__paths__') print "parent: ", snapshot.get('__parent__') print time.time() - start def _test_create_search_type(self): search_type = 'test' search_type_obj = self.server.create_search_type(search_type) print search_type_obj def _test_performance(self): for i in range(0, 1): assets = self.server.query("prod/asset") for asset in assets: asset_key = asset.get("__search_key__") snapshots = self.server.get_all_children( asset_key, 'sthpw/snapshot') #snapshot = self.server.get_snapshot(asset_key,context='model', include_paths=True) #print snapshot.get('__paths__') def _test_get_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] filters.append(['bin_id', bin_id]) connectors = server.query("prod/submission_in_bin", filters) # get all of the submissions from the bin submission_ids = [x.get('submission_id') for x in connectors] filters = [['id', submission_ids]] submissions = server.query("prod/submission", filters) # get all of the snapshots from the submissions for submission in submissions: search_key = submission.get('__search_key__') print "-" * 20 snapshot = server.get_snapshot(search_key, include_paths=True) paths = snapshot.get('__paths__') for path in paths: print path def _test_create_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] # asset parent_type = "prod/asset" parent_code = "chr001" parent_key = server.build_search_key(parent_type, parent_code) parent = server.get_by_search_key(parent_key) parent_id = parent.get('id') # create a submission data = { 'description': 'A test submission', 'artist': 'joe', 'context': 'model' } submission = server.insert("prod/submission", data, parent_key=parent_key) submission_key = submission.get('__search_key__') submission_id = submission.get('id') file_path = './miso_ramen.jpg' context = "publish" snapshot = server.simple_checkin(submission_key, context, file_path, mode="upload") # no connect to the bin with a connector data = {"bin_id": bin_id, 'submission_id': submission_id} server.insert("prod/submission_in_bin", data) def _test_shot_sequence_hierarchy(self): shot_key = "prod/shot?project=sample3d&code=RC_001_001" shot = self.server.get_by_search_key(shot_key) parent = self.server.get_parent(shot_key) self.assertEquals("RC_001", parent.get("code"))
def main(args, src_snapshot_code=None, src_search_type=None, src_search_code=None, src_context=None, src_version=None,\ tgt_context=None, tgt_version=None, file_path=None): if len(args) == 3: # assume code and file path are equivalent search_type = args[0] code = args[1] bin_info = args[2] elif len(args) == 4: search_type = args[0] code = args[1] bin_info = args[2] file_path = args[3] server = TacticServerStub() if file_path: description = "Dailies Submission [%s] to [%s] - [%s]" % (file_path, search_type, code) elif src_snapshot_code: description = "Dailies Submission internal reference [%s] to [%s] - [%s]" \ % (src_snapshot_code, search_type, code) else: description = "Dailies Submission internal reference [%s|%s] to [%s] - [%s]" \ % (src_search_type, src_search_code, search_type, code) server.start(title='Dailies Submission', description=description ) try: parts = bin_info.split('|') if len(parts) == 3: bin_code, type, label = parts[0], parts[1], parts[2] bins = server.query('prod/bin', [('code', bin_code), ('label', label), ('type', type)]) elif len(parts) == 2: bin_code, type = parts[0], parts[1] bins = server.query('prod/bin', [('code', bin_code), ('type', type)]) if not bins: raise TacticApiException("Bin code [%s], type [%s], label [%s] not found in system " % (bin_code, type, label)) search_key = server.build_search_key(search_type, code) sobject = server.query(search_type, [("code", code)]) if not sobject: raise TacticApiException("SObject [%s] with code [%s] not found" %(search_type, code)) sobject_id = sobject[0].get('id') # add a new submission full_search_type = server.build_search_type(search_type) submit_data = {'search_type': full_search_type,\ 'search_id': sobject_id,\ 'description': "Client Api Submission: [%s]" %code\ } if tgt_context and tgt_version != None: submit_data['context'] = tgt_context if tgt_version in ['0', 0 ,'-1', -1]: tgt_snapshot = server.get_snapshot(search_key, tgt_context, version=tgt_version) if not tgt_snapshot: print "tgt_context [%s] and tgt_version [%s] for this sobject cannot be found" %(tgt_context, tgt_version) else: tgt_version = tgt_snapshot.get('version') submit_data['version'] = tgt_version src_snapshot = None if src_snapshot_code: src_snapshot = server.query('sthpw/snapshot',filters=[('code', src_snapshot_code)], single=True) submit_data['context'] = src_snapshot.get('context') submit_data['version'] = src_snapshot.get('version') submission = server.insert('prod/submission', submit_data) # add to bin submit_in_bin_data = { 'bin_id': bins[0].get('id'), \ 'submission_id': submission.get('id')\ } server.insert('prod/submission_in_bin', submit_in_bin_data) print "New submission [%s] created for [%s].\n" %(submission.get('__search_key__'), full_search_type) if file_path: #NOTE: use the upload method instead of copy or move server.simple_checkin(submission.get('__search_key__'), 'publish', file_path, \ snapshot_type='submission', description='Client API dailies submission', mode='upload') else: if src_snapshot: pass elif src_search_type: src_search_key = server.build_search_key(src_search_type, src_search_code) else: src_search_key = search_key if not src_snapshot: src_snapshot = server.get_snapshot(src_search_key, context=src_context, version=src_version) if src_snapshot: snapshot_code = src_snapshot.get('code') # build a new snapshot submit_snapshot = server.create_snapshot(submission.get('__search_key__'), \ "publish", description='Client API dailies submission', \ snapshot_type='submission') # add dependency server.add_dependency_by_code(submit_snapshot.get('code'), snapshot_code) else: raise TacticApiException("No snapshot found for [%s] with context [%s] and version [%s]."\ %(src_search_key, src_context, src_version)) return except Exception, e: server.abort() print "ERROR: ", e.__str__()
class Sample3dTest(unittest.TestCase): def setUp(self): pass def test_all(self): print "Running Sample3d Test" from pyasm.security import Batch from pyasm.biz import Project Batch() Project.set_project("sample3d") #self.server = TacticServerStub(protocol="local") self.server = TacticServerStub(protocol="xmlrpc") project_code = "sample3d" self.server.set_project(project_code) self.server.start("Sample3d Test") try: self._test_create_search_type() self._test_create_submission() self._test_get_submission() self._test_shot_sequence_hierarchy() self._test_query_snapshots() #self._test_performance() except Exception: self.server.abort() raise self.server.abort() #try: # self.server.query("prod/asset") #except Exception: # self.server.abort() # raise #self.server.abort() def _test_query_snapshots(self): filters = [] filters.append( ['context', 'model'] ) filters.append( ['search_type', 'prod/asset?project=sample3d'] ) snapshots = self.server.query_snapshots(filters=filters, include_paths=True) import time start = time.time() for snapshot in snapshots: print snapshot.get('__search_key__') print snapshot.get('__paths__') print "parent: ", snapshot.get('__parent__') print time.time() - start def _test_create_search_type(self): search_type = 'test' search_type_obj = self.server.create_search_type(search_type) print search_type_obj def _test_performance(self): for i in range(0,1): assets = self.server.query("prod/asset") for asset in assets: asset_key = asset.get("__search_key__") snapshots = self.server.get_all_children(asset_key,'sthpw/snapshot') #snapshot = self.server.get_snapshot(asset_key,context='model', include_paths=True) #print snapshot.get('__paths__') def _test_get_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] filters.append( ['bin_id', bin_id] ) connectors = server.query("prod/submission_in_bin", filters) # get all of the submissions from the bin submission_ids = [x.get('submission_id') for x in connectors] filters = [ ['id', submission_ids] ] submissions = server.query("prod/submission", filters) # get all of the snapshots from the submissions for submission in submissions: search_key = submission.get('__search_key__') print "-"*20 snapshot = server.get_snapshot(search_key, include_paths=True) paths = snapshot.get('__paths__') for path in paths: print path def _test_create_submission(self): server = TacticServerStub() server.set_project("sample3d") # choose some arbitrary bin bin_id = 4 filters = [] # asset parent_type = "prod/asset" parent_code = "chr001" parent_key = server.build_search_key(parent_type, parent_code) parent = server.get_by_search_key(parent_key) parent_id = parent.get('id') # create a submission data = { 'description': 'A test submission', 'artist': 'joe', 'context': 'model' } submission = server.insert("prod/submission", data, parent_key=parent_key) submission_key = submission.get('__search_key__') submission_id = submission.get('id') file_path = './miso_ramen.jpg' context = "publish" snapshot = server.simple_checkin(submission_key, context, file_path, mode="upload") # no connect to the bin with a connector data = { "bin_id": bin_id, 'submission_id': submission_id } server.insert("prod/submission_in_bin", data) def _test_shot_sequence_hierarchy(self): shot_key = "prod/shot?project=sample3d&code=RC_001_001" shot = self.server.get_by_search_key(shot_key) parent = self.server.get_parent(shot_key) self.assertEquals("RC_001", parent.get("code") )
def main(args, login=None): # USAGE: checkin_render_layer.py shot_code = args[0] layer_name = args[1] version = args[2] context = args[3] file_range = args[4] pattern = args[5] server = TacticServerStub(login) # do the actual work server.start("Checked in file group [%s] to shot [%s] layer [%s]" % (pattern, shot_code, layer_name)) try: # move the file dir = server.get_handoff_dir() paths = expand_paths(pattern, file_range) move_file(paths, dir) file_name = os.path.basename(pattern) new_pattern = "%s/%s" % (dir, file_name) print "Files moved to handoff dir.\n" # checkin the moved files filters = [] filters.append(("shot_code", shot_code)) filters.append(("name", layer_name)) results = server.query("prod/layer", filters) # take the first one if results: id = results[0].get("id") search_type = server.build_search_type("prod/layer") # find the layer snapshot filters = [] filters.append(("version", version)) filters.append(("search_type", search_type)) filters.append(("search_id", id)) # TODO : may need a context to search for the proper layer results = server.query("sthpw/snapshot", filters) snap_code = "" if results: snap_code = results[0].get("code") # find the render render = None filters = [] filters.append(("search_type", search_type)) filters.append(("search_id", id)) filters.append(("snapshot_code", snap_code)) results = server.query(SEARCH_TYPE, filters) if results: render = results[0] if not render: render_data = {"search_type": search_type, "search_id": id, "snapshot_code": snap_code} render = server.insert("prod/render", render_data) """ results = server.query(SEARCH_TYPE, filters) render_id = 0 if results: render_id = results[0].get('id') # find the render id search_key = server.build_search_key(SEARCH_TYPE, render_id, column='id') """ file_type = "main" # run group checkin server.group_checkin( render.get("__search_key__"), context=context, file_path=new_pattern, file_type=file_type, file_range=file_range, ) except: server.abort() raise else: server.finish()
def main(args, login=None): # USAGE: checkin_render.py type = args[0] if type == "shot": parent_search_type = "prod/shot" elif type == "asset": parent_search_type = "prod/asset" else: parent_search_type = type code = args[1] file_range = args[2] pattern = args[3] layer_name = '' context = 'publish' if type == "layer": parent_search_type = "prod/layer" code, layer_name = args[1].split('|') server = TacticServerStub(login) # do the actual work server.start("Checked in file group [%s] to %s [%s]" % (pattern, type, code)) try: # checkin the uploaded file filters = [] if type == 'layer': filters.append(('shot_code', code)) filters.append(('name', layer_name)) else: filters.append(('code', code)) results = server.query(parent_search_type, filters) # take the first one if results: id = results[0].get('id') else: if type == 'layer': print "%s Code [%s] name [%s] not found. Please insert an entry in TACTIC first." % ( type, code, layer_name) else: print "%s Code [%s] not found. Please insert an entry in TACTIC first." % ( type, code) search_type = server.build_search_type(parent_search_type) file_type = 'main' render_type = '' # not used yet # move the file dir = server.get_handoff_dir() paths = expand_paths(pattern, file_range) copy_file(paths, dir) file_name = os.path.basename(pattern) new_pattern = '%s/%s' % (dir, file_name) print "Copied files to handoff dir\n" render = find_render(server, search_type, id, login, render_type) if not render: render_data = { 'search_type': search_type, 'search_id': id, 'login': login #'type': render_type } render = server.insert("prod/render", render_data) # run group checkin server.group_checkin(render.get("__search_key__"), context=context, file_path=new_pattern, file_type=file_type, file_range=file_range) except: server.abort() raise else: server.finish()