def execute(my): #protocol = 'xmlrpc' protocol = 'local' if protocol == 'local': server = TacticServerStub.get() else: server = TacticServerStub(protocol=protocol,setup=False) TacticServerStub.set(server) project = my.data.get("project") ticket = my.data.get("ticket") assert project assert ticket server.set_server("localhost") server.set_project(project) server.set_ticket(ticket) my.class_name = my.data.get('class_name') assert my.class_name # get the script to run script_code = my.data.get("script_code") if script_code: search_type = "config/custom_script" search_key = server.build_search_key(search_type, script_code) script_obj = server.get_by_search_key(search_key) script = script_obj.get('script') my.run_script(script) else: print "Nothing to run"
def execute(my): #protocol = 'xmlrpc' protocol = 'local' if protocol == 'local': server = TacticServerStub.get() else: server = TacticServerStub(protocol=protocol, setup=False) TacticServerStub.set(server) project = my.data.get("project") ticket = my.data.get("ticket") assert project assert ticket server.set_server("localhost") server.set_project(project) server.set_ticket(ticket) my.class_name = my.data.get('class_name') assert my.class_name # get the script to run script_code = my.data.get("script_code") if script_code: search_type = "config/custom_script" search_key = server.build_search_key(search_type, script_code) script_obj = server.get_by_search_key(search_key) script = script_obj.get('script') my.run_script(script) else: print "Nothing to run"
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 _test_insert_trigger(self): # create a db trigger sobject = Search.eval( "@SOBJECT(sthpw/trigger['event','insert|unittest/person'])", single=True) if sobject: raise Exception( 'Please delete the insert|unittest/person trigger in sthpw first' ) trigger_sobj = SearchType.create("sthpw/trigger") trigger_sobj.set_value("event", "insert|unittest/person") trigger_sobj.set_value("class_name", "pyasm.command.command_test.TestInsertHandler") trigger_sobj.set_value("description", "Unittest Test Api Handler") trigger_sobj.commit() search = Search("sthpw/trigger") count = search.get_count() # use the client api to insert that trigger server = TacticServerStub(protocol='xmlrpc') server.start("insert trigger test") try: # create a new person search_type = "unittest/person" code = "fred" search_key = server.build_search_key(search_type, code) Container.put("TestApiHandler/search_key", search_key) # insert data = {'code': code} # insert test: if the trigger fails then an exception should be # raised ...? server.insert(search_type, data) finally: server.abort() trigger_sobj.delete() search = Search('sthpw/trigger') search.add_filter('event', 'insert|unittest/person') trig = search.get_sobject() self.assertEquals(trig, None)
def _test_insert_trigger(self): # create a db trigger sobject = Search.eval("@SOBJECT(sthpw/trigger['event','insert|unittest/person'])", single=True) if sobject: raise Exception('Please delete the insert|unittest/person trigger in sthpw first') trigger_sobj = SearchType.create("sthpw/trigger") trigger_sobj.set_value("event", "insert|unittest/person") trigger_sobj.set_value("class_name", "pyasm.command.command_test.TestInsertHandler") trigger_sobj.set_value("description", "Unittest Test Api Handler") trigger_sobj.commit() search = Search("sthpw/trigger") count = search.get_count() # use the client api to insert that trigger server = TacticServerStub(protocol='xmlrpc') server.start("insert trigger test") try: # create a new person search_type = "unittest/person" code = "fred" search_key = server.build_search_key(search_type, code) Container.put("TestApiHandler/search_key", search_key) # insert data = { 'code': code } # insert test: if the trigger fails then an exception should be # raised ...? server.insert(search_type, data) finally: server.abort() trigger_sobj.delete() search = Search('sthpw/trigger') search.add_filter('event', 'insert|unittest/person') trig = search.get_sobject() self.assertEquals(trig, None)
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_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, login=None): # USAGE: checkin_shot.py <shot_code> <context> <path> shot_code = args[0] context = args[1] file_path = args[2] server = TacticServerStub(login) search_key = server.build_search_key(SEARCH_TYPE, shot_code) # do the actual work server.start("Checked in file [%s]" % file_path) try: # upload the file #server.upload_file(file_path) # checkin the uploaded file result = server.simple_checkin(search_key, context, file_path, mode='upload') except: server.abort() raise else: server.finish()
def main(args, login=None): # USAGE: checkin_shot.py <shot_code> <context> <path> shot_code = args[0] context = args[1] file_path = args[2] server = TacticServerStub(login) search_key = server.build_search_key(SEARCH_TYPE, shot_code) # do the actual work server.start("Checked in file [%s]" % file_path) try: # upload the file # server.upload_file(file_path) # checkin the uploaded file result = server.simple_checkin(search_key, context, file_path, mode="upload") except: server.abort() raise else: server.finish()
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_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 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__()