def import_default_side_bar(self): code = Search.eval("@GET(config/widget_config['code','WIDGET_CONFIG000000'].code)", single=True) if code: print "Default side bar already exists!" return project_code = self.kwargs.get('project_code') # It looks like project=XXX on SearchType.create does not work Project.set_project(project_code) config = SearchType.create("config/widget_config?project=%s" % project_code) config.set_value("code", "WIDGET_CONFIG000000") config.set_value("category", "SideBarWdg") config.set_value("search_type", "SideBarWdg") config.set_value("view", "project_view") xml = '''<?xml version='1.0' encoding='UTF-8'?> <config> <project_view> <element name='_home' title='Examples'/> </project_view> </config> ''' config.set_value("config", xml) config.commit()
def init(self): web = WebContainer.get_web() project_code = web.get_form_value("project") if project_code: Project.set_project(project_code) method = web.get_form_value("method") widget_class = web.get_form_value("widget") if widget_class == "": return arg_type = web.get_form_value("arg_type") if arg_type == "dict" and not method: args = web.get_form_args() exec(Common.get_import_from_class_path(widget_class)) widget = eval("%s.init_dynamic(args)" % widget_class) elif method: widget = Common.create_from_method(widget_class, method) else: widget_args = web.get_form_values(WebEnvironment.ARG_NAME) widget = Common.create_from_class_path(widget_class, widget_args) # tell the widget that it is the top widget widget.set_as_top() self.add(widget)
def test_all(my): try: db_res = DbResource.get_default('unittest') sql = DbContainer.get(db_res) impl = sql.get_database_impl() db_type = impl.get_database_type() if db_type == "PostgreSQL": my.prefix = '''"unittest"."public"''' my.sthpw_prefix = '''"sthpw"."public"''' else: my.prefix = '''"unittest"''' my.sthpw_prefix = '''"sthpw"''' my._test_get_connect() my._test_select_class() my._test_insert_class() my._test_update_class() my._test_insert_and_delete() my._test_create_table() my._test_transaction() my._test_order_by() my._test_rpn_filters() my._test_search_filter() my._test_join() my._test_add_drop_column() finally: Project.set_project('unittest') my.test_env.delete()
def _test_join(my): """ test a select """ Project.set_project('unittest') select = Select() db_res = DbResource.get_default('unittest') select.set_database(db_res) select.add_table("person") select.add_join('person','city', 'city_code','code') select.add_join('city','country', 'country_code','code') select.add_order_by("name_last") statement = select.get_statement() my.assertEquals(statement, '''SELECT %s"person".* FROM %s"person" LEFT OUTER JOIN %s"city" ON "person"."city_code" = "city"."code" LEFT OUTER JOIN %s"country" ON "city"."country_code" = "country"."code" ORDER BY "person"."name_last"''' % (my.prefix, my.prefix, my.prefix, my.prefix) ) search = Search('unittest/person') search.add_join('unittest/city', 'unittest/person') statement = search.get_statement() my.assertEquals(statement, '''SELECT %s"person".* FROM %s"person" LEFT OUTER JOIN %s"city" ON "person"."city_code" = "city"."code"''' % (my.prefix,my.prefix, my.prefix)) statement = search.get_statement() # this one has no schema connection, so will be ignored search.add_join('sthpw/login', 'unittest/person') my.assertEquals(statement, '''SELECT %s"person".* FROM %s"person" LEFT OUTER JOIN %s"city" ON "person"."city_code" = "city"."code"''' % (my.prefix, my.prefix, my.prefix)) search.add_join('unittest/country', 'unittest/city') statement = search.get_statement() my.assertEquals(statement, '''SELECT %s"person".* FROM %s"person" LEFT OUTER JOIN %s"city" ON "person"."city_code" = "city"."code" LEFT OUTER JOIN %s"country" ON "city"."country_code" = "country"."code"''' % (my.prefix, my.prefix, my.prefix, my.prefix) )
def _test_copy_project(self): #transaction = Transaction.get(create=True) try: os.system('dropdb -U postgres "game_copy"') from tactic.command import ProjectTemplateInstallerCmd cmd = ProjectTemplateInstallerCmd(project_code='game_copy', template_code='game', mode='copy') cmd.execute() schema_entry = Search.eval("@GET(sthpw/schema['code','game_copy'].code)", single=True) self.assertEquals(schema_entry, 'game_copy') project_entry = Search.eval("@GET(sthpw/project['code','game_copy'].code)", single=True) self.assertEquals(project_entry, 'game_copy') Project.set_project('game_copy') widget_config_st = Search.eval("@GET(config/widget_config['code','1GAME'].search_type)", single=True) self.assertEquals(widget_config_st, 'game/ticket') widget_config_counts = Search.eval("@COUNT(config/widget_config)") self.assertEquals(widget_config_counts, 133) Project.set_project('unittest') finally: sql = DbContainer.get('sthpw') sql.do_update("delete from project where code ='game_copy'") sql.do_update("delete from schema where code ='game_copy'") sql.commit() DbContainer.close_all() os.system('dropdb -U postgres "game_copy"')
def test_all(self): Batch() from pyasm.web.web_init import WebInit WebInit().execute() test_env = UnittestEnvironment() test_env.create() self._test_command() self._test_trigger() trigger_key = "triggers:cache" Container.put(trigger_key, None) try: self._test_api_trigger() self._test_insert_trigger() # test copy project from template self._test_copy_project() # clear again for subsequent Client API test trigger_key = "triggers:cache" Container.put(trigger_key, None) trigger_key2 = Trigger.KEY Container.put(trigger_key2, None) finally: Project.set_project('unittest') test_env.delete()
def execute(self): self.base_dir = self.kwargs.get("base_dir") if not self.base_dir: self.base_dir = Environment.get_template_dir() self.project_code = self.kwargs.get("project_code") if not self.project_code: self.project_code = Project.get_project_code() assert self.project_code # project code can be called anything, and we want to have a _template suffix for the template code #self.plugin_code = "%s_template" % self.project_code #self.template_project_code = re.sub( '_template$', '', self.plugin_code) self.template_project_code = self.project_code self.project = Project.get_by_code(self.project_code) if not self.project: raise TacticException('This project [%s] does not exist'%self.project_code) self.project_type = self.project.get_value("type") if not self.project_type: self.project_type = self.project_code Project.set_project(self.project_code) self.export_template()
def get_loader_xml(my, ticket, project_code, snapshot_code, context="", options=""): '''uses the loader to generate an execute xml that can be used to load the assets''' try: my.init(ticket) Project.set_project(project_code) snapshot = Snapshot.get_by_code(snapshot_code) # get the loader implementation loader_context = ProdLoaderContext() loader_context.set_context(context) # pass on any message options for the loader if options != "": loader_context.set_options(options) loader = loader_context.get_loader(snapshot) loader.execute() execute_xml = loader.get_execute_xml() xml = execute_xml.get_xml() finally: DbContainer.close_all() return xml
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()
def test_all(self): batch = Batch() Environment.get_security().set_admin(True) from pyasm.unittest import UnittestEnvironment, Sample3dEnvironment test_env = UnittestEnvironment() test_env.create() sample3d_env = Sample3dEnvironment(project_code='sample3d') sample3d_env.create() Project.set_project("unittest") try: self.access_manager = Environment.get_security().get_access_manager() self._test_all() finally: # Reset access manager for tear down Environment.get_security()._access_manager = self.access_manager Environment.get_security().reset_access_manager() self._tear_down() Environment.get_security().set_admin(True) test_env.delete() Environment.get_security().set_admin(True) sample3d_env.delete() Site.pop_site()
def update_session(my, ticket, project_code, user, pid, data): try: my.init(ticket) Project.set_project(project_code) # get the session sobject sobject = None search = Search("prod/session_contents", project_code=project_code) search.add_filter("login", user) search.add_filter("pid", pid) sobject = search.get_sobject() # if none exists, then create one if sobject == None: search_type = SearchType.build_search_type('prod/session_contents', project_code) sobject = SearchType.create(search_type) sobject.set_value("login", user) sobject.set_value("pid", pid) sobject.set_value("data", data) impl = search.get_database_impl() sobject.set_value("timestamp", impl.get_timestamp_now(), quoted=False) sobject.commit() finally: DbContainer.close_all() return True
def create_set(my, ticket, project_code, set_name, cat_name, selected): '''an xml to create a new set node''' xml = '' asset_code = '' try: my.init(ticket) Project.set_project(project_code) cmd = MayaSetCreateCmd() cmd.set_set_name(set_name) cmd.set_cat_name(cat_name) Command.execute_cmd(cmd) asset_code = cmd.get_asset_code() if asset_code: cmd = CreateSetNodeCmd() cmd.set_asset_code(asset_code) cmd.set_instance(set_name) cmd.set_contents(selected) cmd.execute() execute_xml = cmd.get_execute_xml() xml = execute_xml.get_xml() finally: DbContainer.close_all() return [xml, asset_code]
def test_all(self): '''entry point function''' self.description = "Checkin unit test" self.errors = [] Batch() # FIXME: this is needed for the triggers to be registerd. These # triggers have nothing to do with the web from pyasm.web import WebInit WebInit().execute() test_env = UnittestEnvironment() test_env.create() self.transaction = Transaction.get(create=True) Project.set_project("unittest") try: #Command.execute_cmd(self) # undo the command #undo = UndoCmd() #undo.execute() self.execute() finally: self.transaction.rollback() test_env.delete()
def checkin_shot_set(my, ticket, project_code, shot_code, process, context, \ checkin_as, currency, unknown_ref, desc): snapshot_code = '' try: my.init(ticket) Project.set_project(project_code) shot = Shot.get_by_code(shot_code) checkin = ShotCheckin(shot) checkin.set_description(desc) checkin.set_process(process) checkin.set_context(context) is_current = True if currency == 'False': is_current = False is_revision = False if checkin_as == 'Revision': is_revision = True checkin.set_current(is_current) checkin.set_revision(is_revision) checkin.set_option("unknown_ref", unknown_ref) Command.execute_cmd(checkin) snapshot_code = checkin.snapshot.get_code() finally: DbContainer.close_all() return snapshot_code
def execute(my): my.base_dir = my.kwargs.get("base_dir") if not my.base_dir: my.base_dir = Environment.get_template_dir() my.project_code = my.kwargs.get("project_code") if not my.project_code: my.project_code = Project.get_project_code() assert my.project_code # project code can be called anything, and we want to have a _template suffix for the template code #my.plugin_code = "%s_template" % my.project_code #my.template_project_code = re.sub( '_template$', '', my.plugin_code) my.template_project_code = my.project_code my.project = Project.get_by_code(my.project_code) if not my.project: raise TacticException('This project [%s] does not exist'%my.project_code) my.project_type = my.project.get_value("type") if not my.project_type: my.project_type = my.project_code Project.set_project(my.project_code) my.export_template()
def setUp(my): # start batch environment Batch() from pyasm.biz import Project Project.set_project("unittest")
def test_all(my): '''entry point function''' my.description = "Checkin unit test" my.errors = [] Batch() # FIXME: this is needed for the triggers to be registerd. These # triggers have nothing to do with the web from pyasm.web import WebInit WebInit().execute() test_env = UnittestEnvironment() test_env.create() Project.set_project("unittest") try: Command.execute_cmd(my) # undo the command undo = UndoCmd() undo.execute() finally: test_env.delete()
def get_application_wdg(self): page = None try: project = Project.get() except Exception as e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg() page.set_message(e.__str__()) page.status = '' application = self.get_top_wdg() # get the main page widget # NOTE: this needs to happen after the body is put in a Container if not page: page = self.get_page_widget() page.set_as_top() if type(page) in types.StringTypes: page = StringWdg(page) application.add(page, 'content') return application
def checkin_textures(my, ticket, project_code, asset_code, paths, file_ranges, node_names, attrs, use_handoff_dir=False, md5s=[]): '''creates a number of textures under a single asset''' new_paths = [] try: my.init(ticket) Project.set_project(project_code) parent = Asset.get_by_code(asset_code) #parent = Search.get_by_search_key(search_key) context = 'publish' checkin = TextureCheckin(parent, context, paths, file_ranges, node_names, attrs, use_handoff_dir=use_handoff_dir, md5s=md5s) Command.execute_cmd(checkin) new_paths = checkin.get_texture_paths() #md5_list = checkin.get_texture_md5() file_code_list = checkin.get_file_codes() #loader_context = ProdLoaderContext() #updater = loader_context.get_updater(snapshot, asset_code, instance) #execute_xml = updater.get_execute_xml() #xml = execute_xml.to_string() finally: DbContainer.close_all() return new_paths, file_code_list
def _process_task(my, task, mode): project = Project.get_project_code() if not task.kwargs.get("user"): user = Environment.get_user_name() if not task.kwargs.get("project"): project_code = Project.get_project_code() task.kwargs['project'] = project_code task.kwargs['mode'] = mode
def execute(my): try: #Batch() #Command.execute_cmd(timed_trigger) Project.set_project(my.project_code) timed_triggers[my.index].execute() except Exception, e: print "Error running trigger" raise
def get_application_wdg(my): page = None try: project = Project.get() except Exception, e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg()
def __init__(self, project_code=None, login_code=None, site=None): self.set_app_server("batch") if not site: # if not explicitly set, keep the current site site = Site.get_site() plugin_dir = Environment.get_plugin_dir() if plugin_dir not in sys.path: sys.path.insert(0, plugin_dir) super(Batch,self).__init__() self.login_code = login_code # clear the main container Container.create() if site: Site.set_site(site) # set this as the environment if not project_code: self.context = self.get_default_context() else: self.context = project_code Environment.set_env_object( self ) # set up the security object security = Security() Environment.set_security(security) self._do_login() site_dir = Environment.get_site_dir() if site_dir not in sys.path: sys.path.insert(0, site_dir) # set the project from pyasm.biz import Project if self.context == "batch": Project.set_project("admin") else: Project.set_project(self.context) self.initialize_python_path() # start workflow engine #from pyasm.command import Workflow #Workflow().init() DbContainer.commit_thread_sql()
def get_application_wdg(my): page = None try: project = Project.get() except Exception, e: Project.set_project("sthpw") from pyasm.widget import Error404Wdg page = Error404Wdg() page.set_message(e.__str__()) page.status = ''
def execute(self): try: #Batch() #Command.execute_cmd(timed_trigger) Project.set_project(self.project_code) timed_triggers[self.index].execute() except Exception as e: raise finally: DbContainer.close_thread_sql() DbContainer.commit_thread_sql() DbContainer.close_all()
def test_all(self): # start batch environment Batch(login_code='admin') test_env = UnittestEnvironment() test_env.create() Project.set_project('admin') try: self._test_csv_export() finally: test_env.delete()
def checkin_frames(my, ticket, project_code, queue_id): try: my.init(ticket) Project.set_project(project_code) cmd = CheckinFramesXMLRPC() cmd.set_args(ticket, queue_id) Command.execute_cmd(cmd) finally: DbContainer.close_all() return True
def get_by_key(cls, key, search_type=None): project = Project.get_project_code() dict_key = '%s:%s' %(key, search_type) search = Search(cls.SEARCH_TYPE, project_code=project) search.add_filter("key", key) if search_type: search.add_filter("search_type", search_type) if Project.get_project_name() in ['admin', 'sthpw']: return None prod_setting = ProdSetting.get_by_search(search, dict_key) return prod_setting
def test_all(my): Batch() from pyasm.web.web_init import WebInit WebInit().execute() test_env = UnittestEnvironment() test_env.create() my.transaction = Transaction.get(create=True) try: my._test_multiple_schema() finally: my.transaction.rollback() Project.set_project('unittest') test_env.delete()
def create_assets(my, ticket, project_code, set_code, names): try: my.init(ticket) Project.set_project(project_code) cmd = CreateSetAssetsCmd() cmd.set_set_code(set_code) cmd.set_names(names) Command.execute_cmd(cmd) asset_codes = cmd.get_asset_codes() finally: DbContainer.close_all() return asset_codes
def execute(my): database = "sthpw" sql = DbContainer.get(database) value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X where cc > 1;") #value_array = sql.do_query("select code, cc from (select code, count(code) as cc from file group by code order by cc desc) as X;") print "found [%s] pairs" % len(value_array) for count, value_list in enumerate(value_array): if count >= BATCH: break # get the file object file_code = value_list[0] search = Search("sthpw/file") search.add_filter("code", file_code) files = search.get_sobjects() #if len(files) == 1: # continue for file in files: project_code = file.get_value("project_code") if not project_code: print "WARNING: file [%s] has no project_code" % file_code continue project = Project.get_by_code(project_code) initials = project.get_initials() id = file.get_id() new_file_code = "%s%s" % (id, initials) if file_code == new_file_code: continue print "-"*20 print "switching: ", file_code, "to", new_file_code snapshot_code = file.get_value("snapshot_code") snapshot = Snapshot.get_by_code(snapshot_code) assert snapshot snapshot_xml = snapshot.get_xml_value("snapshot") print snapshot_xml.to_string() node = snapshot_xml.get_node("snapshot/file[@file_code='%s']" % file_code) Xml.set_attribute(node, "file_code", new_file_code) print snapshot_xml.to_string() assert node # set the file_code file.set_value("code", new_file_code) file.commit() # set the snapshot snapshot.set_value("snapshot", snapshot_xml.to_string() ) snapshot.commit()
def add_unregistered_hours(my, main_div): '''draw the unregistered hours''' row_div = FloatDivWdg() row_div.add_style("margin-bottom: 4px") main_div.add(row_div) process_div = _get_div(my.process_len) process_div.add("unregistered hours") #process_div.add_style('color: #999') row_div.add(process_div) for i in TimecardWdg.WEEK_CALENDAR: unreg_hours = 0.0 div = _get_div(50) row_div.add(div) div.add_class('center_content') span = SpanWdg() div.add(span) span.add_style('padding: 0 6px 0 6px') max_hours = Project.get_reg_hours() if not max_hours: max_hours = TimecardWdg.MAX_REG_HOURS max_hours = float(max_hours) # get all the timecards for the week and hours reg_hours = Timecard.get_registered_hours(None, my.week, i, my.year) unreg_hours = max_hours-reg_hours if unreg_hours <= 0: my.overtime_dict[i] = abs(unreg_hours) unreg_hours = IconWdg(icon=IconWdg.GOOD) else: my.overtime_dict[i] = '' unreg_hours = str(unreg_hours) span.add(unreg_hours)
def _add_options(my): ''' add the options to the select ''' search_type = my._get_search_type() if not search_type: return # get all processes if no search type is given proj_code = Project.extract_project_code(search_type) is_group_restricted = False if my.has_empty: my.add_first_option() else: from asset_filter_wdg import ProcessFilterWdg if ProcessFilterWdg.has_restriction(): is_group_restricted = True process_names, process_values = Pipeline.get_process_select_data(\ search_type, is_filter=my.is_filter, project_code=proj_code,\ is_group_restricted=is_group_restricted, sobject = my._sobject) my.set_option("values", process_values) my.set_option("labels", process_names) if not my.is_filter: behavior = { 'type': 'onchange', 'cbjs_action': "if (bvr.src_el.value=='')\ {alert('Please choose a valid process.');}" }
def get_parent_schema(my): parent_schema_code = my.xml.get_value("schema/@parent") if parent_schema_code: if parent_schema_code == "__NONE__": return None parent_schema = Schema.get_by_code(parent_schema_code) return parent_schema else: # Note: assume schema code == project_code schema_code = my.get_value("code") from pyasm.biz import Project project = Project.get_by_code(schema_code) if not project: return None project_code = project.get_code() project_type = project.get_base_type() if not project_type: return None parent_schema = Schema.get_predefined_schema(project_type) return parent_schema
def _test_add_drop_column(self): #Project.set_project('unittest') from pyasm.command import ColumnAddCmd, ColumnDropCmd, Command cmd = ColumnAddCmd('unittest/country', 'special_place', 'varchar(256)') Command.execute_cmd(cmd) search_type = 'unittest/country' # clear cache SearchType.clear_column_cache(search_type) DatabaseImpl.clear_table_cache() exists = SearchType.column_exists(search_type, 'special_place') self.assertEquals(exists, True) # now drop the column cmd = ColumnDropCmd(search_type, 'special_place') Command.execute_cmd(cmd) # clear cache SearchType.clear_column_cache(search_type) cache_dict = Container.get("DatabaseImpl:column_info") # assume database is the same as sthpw database_type = Project.get_by_code("unittest").get_database_type() db_resource = DbResource.get_default('unittest') table_info = cache_dict.get("%s:%s" % (db_resource, "country")) self.assertEquals(table_info == None, True) key = "%s:%s" % (db_resource, "country") cache_dict[key] = None exists = SearchType.column_exists(search_type, 'special_place') self.assertEquals(exists, False)
def create_snapshot_xml(my, file_objects, snapshot_xml=None): builder = SnapshotBuilder(snapshot_xml) root = builder.get_root_node() from pyasm.search.sql import DbContainer from pyasm.biz import Project project = Project.get() db_resource = project.get_project_db_resource() sql = DbContainer.get(db_resource) if sql.get_database_type() == 'SQLServer': import datetime Xml.set_attribute(root, "timestamp", datetime.datetime.now()) else: Xml.set_attribute(root, "timestamp", time.asctime() ) Xml.set_attribute(root, "context", my.context ) for i in range(0, len(file_objects)): file_object = file_objects[i] file_type = my.file_types[i] file_info = {} file_info['type'] = file_type if file_object.get_file_range(): file_info['file_range'] = my.file_range.get_key() builder.add_file(file_object, file_info) for input_snapshot in my.input_snapshots: builder.add_ref_by_snapshot(input_snapshot) return builder.to_string()
def get(cls, texture_code, parent_code, project_code=None, is_multi=False): if not project_code: project_code = Project.get_project_code() search = Search(cls.SEARCH_TYPE, project_code) #search.set_show_retired(True) if texture_code: search.add_filter('code', texture_code) # backward compatible with using shot code if isinstance(parent_code, basestring): from pyasm.prod.biz import Shot parent = Shot.get_by_code(parent_code) else: parent = parent_code if not parent: if is_multi: return [] else: return None search.add_filter('search_type', parent.get_search_type()) search.add_filter('search_id', parent.get_id()) parent_key = SearchKey.get_by_sobject(parent) search_type = search.get_search_type() key = "%s|%s|%s" % (search_type, texture_code, parent_key) sobj = cls.get_by_search(search, key, is_multi=is_multi) return sobj
def execute(self): sobject = self.get_caller() search_type = sobject.get_base_search_type() all_logins = False if search_type == 'config/widget_config': category = sobject.get_value("category") if not category: category = sobject.get_value("search_type") if category != 'SideBarWdg': return user = sobject.get_value('login') user = user.strip() if not user: all_logins = True from pyasm.biz import Project project = Project.get() project_code = project.get_code() login = Environment.get_user_name() tmp_dir = "%s/cache/side_bar" % Environment.get_tmp_dir() project_check = True if search_type == 'sthpw/login_group': login_objs = sobject.get_logins() logins = [x.get_value('login') for x in login_objs] project_check = False else: if all_logins: expr = '@GET(sthpw/login.login)' logins = Search.eval(expr) else: logins = [login] filenames = [] if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) return search = Search('sthpw/project') projects = search.get_sobjects() project_codes = [x.get_value('code') for x in projects] for login in logins: if project_check: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) else: for project_code in project_codes: filename = "%s__%s.html" % (project_code, login) filenames.append(filename) #filenames = os.listdir(tmp_dir) for filename in filenames: #if not filename.startswith("%s__" % project_code): # print "skip filename ", filename path = "%s/%s" % (tmp_dir, filename) if os.path.exists(path): print "Deleting: ", path os.unlink(path)
def create(cls, shot, asset, instance_name="", type="asset", unique=False): shot_col = shot.get_foreign_key() search = Search(cls.SEARCH_TYPE) search.add_filter(shot_col, shot.get_code()) search.add_filter("type", type) #if unique: # search.add_filter("name", instance_name) search.add_filter("asset_code", asset.get_code()) search.add_order_by('name desc') sobjs = search.get_sobjects() # if unique and exists, then return if unique and sobjs: Environment.add_warning( "Instance exists", "Shot '%s' already has an instance for asset '%s'" % (shot.get_code(), asset.get_code())) return naming = Project.get_naming("node") instance_name = naming.get_shot_instance_name(shot, asset, sobjs) #instance_name = cls.get_instance_name(sobjs, instance_name) instance = SObjectFactory.create(cls.SEARCH_TYPE) instance.set_value(shot_col, shot.get_code()) instance.set_value("asset_code", asset.get_code()) instance.set_value("name", instance_name) instance.set_value("type", type) instance.commit() return instance
def add_related_connection(self, src_sobject, dst_sobject, src_path=None): '''adding the related sobject code to this current sobject''' self.add_related_sobject(src_sobject) self.add_related_sobject(dst_sobject) #shot_col = dst_sobject.get_foreign_key() schema = self.get_schema() st1 = self.get_base_search_type() st2 = dst_sobject.get_base_search_type() relationship = schema.get_relationship(st1, st2) attrs = schema.get_relationship_attrs(st1, st2) from_col = attrs.get("from_col") search = Search(self.SEARCH_TYPE) search.add_filter(from_col, dst_sobject.get_code()) search.add_filter("type", "asset") search.add_filter("asset_code", src_sobject.get_code()) search.add_order_by('name desc') instances = search.get_sobjects() """ # if it allows order by, I can switch to this filters = [('asset_code', src_sobject.get_code())] instances = dst_sobject.get_related_sobjects(self.SEARCH_TYPE, filters=filters) """ naming = Project.get_naming("node") instance_name = naming.get_shot_instance_name(dst_sobject, src_sobject, instances) self.set_value('name', instance_name) self.set_value('type', 'asset')
def check(my): project_code = my.kwargs.get('project_code') regexs = '^\d|\W' m = re.search(r'%s' % regexs, project_code) if m: if isinstance(project_code, unicode): project_code = project_code.encode('utf-8') else: project_code = unicode(project_code).encode('utf-8') raise TacticException( '<project_code> [%s] cannot contain special characters or start with a number.' % project_code) # check to see if this project already exists test_project = Project.get_by_code(project_code) if test_project: if test_project.get_value('s_status') == 'retired': raise TacticException( 'Project with code [%s] already exists but is retired.' % project_code) else: raise TacticException( 'Project with code [%s] already exists.' % project_code) return True
def get_naming(cls, naming_type, sobject=None, project=None): '''get a certain type of naming determined by type of naming''' naming_cls = "" # this import statement is needed for running Batch from pyasm.biz import Project if not project: if sobject: project = sobject.get_project() else: project = Project.get() if project: naming_cls = project.get_value("%s_naming_cls" % naming_type, no_exception=True) if not naming_cls and project.get_project_type(): naming_cls = project.get_project_type().get_value( "%s_naming_cls" % naming_type, no_exception=True) # if none is defined, use defaults if not naming_cls: # TODO: this should probably be stored somewhere else if naming_type == "file": naming_cls = "pyasm.biz.FileNaming" elif naming_type == "dir": naming_cls = "pyasm.biz.DirNaming" elif naming_type == "node": naming_cls = "pyasm.prod.biz.ProdNodeNaming" naming = Common.create_from_class_path(naming_cls) return naming
def copy_sobject(self, sobject, dst_search_type, context=None, checkin_mode='inplace'): new_sobject = SearchType.create(dst_search_type) search_type = SearchType.get(dst_search_type) columns = SearchType.get_columns(dst_search_type) data = sobject.get_data() for name, value in data.items(): if name in ['id','pipeline_code']: continue if name not in columns: continue if not value: continue if name == "code": value = Common.get_next_sobject_code(sobject, 'code') if not value: continue new_sobject.set_value(name, value) if SearchType.column_exists(dst_search_type, "project_code"): project_code = Project.get_project_code() new_sobject.set_value("project_code", project_code) new_sobject.commit() # get all of the current snapshots and file paths associated if not context: snapshots = Snapshot.get_all_current_by_sobject(sobject) else: snapshots = [Snapshot.get_current_by_sobject(sobject, context)] if not snapshots: return msgs = [] for snapshot in snapshots: #file_paths = snapshot.get_all_lib_paths() file_paths_dict = snapshot.get_all_paths_dict() file_types = file_paths_dict.keys() if not file_types: continue # make sure the paths match the file_types file_paths = [file_paths_dict.get(x)[0] for x in file_types] mode = checkin_mode # checkin the files (inplace) try: context = snapshot.get_value('context') checkin = FileCheckin(new_sobject, context=context, file_paths=file_paths, file_types=file_types, mode=mode) checkin.execute() #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot") except CheckinException, e: msgs.append('Post-process Check-in Error for %s: %s ' %(context, e.__str__()))
def add(command, kwargs, queue_type, priority, description, message_code=None): queue = SearchType.create("sthpw/queue") queue.set_value("project_code", Project.get_project_code()) #queue.set_sobject_value(sobject) queue.set_value("queue", queue_type) queue.set_value("state", "pending") queue.set_value("login", Environment.get_user_name()) queue.set_value("command", command) data = jsondumps(kwargs) queue.set_value("data", data) if message_code: queue.set_value("message_code", message_code) queue.set_value("priority", priority) queue.set_value("description", description) queue.set_user() queue.commit() return queue
def create(my): project = Project.get_by_code(my.project_code) if project: my.delete() print "Setting up a basic Sample3d project" # create the project create_cmd = CreateProjectCmd( project_code=my.project_code, project_title="Sample 3D") #, project_type="unittest") create_cmd.execute() # install the unittest plugin installer = PluginInstaller(relative_dir="TACTIC/internal/sample3d", verbose=False) installer.execute() # add 30 shots for x in xrange(30): shot = SearchType.create("prod/shot") shot.set_value('name', 'shot%s' % x) shot.set_value('sequence_code', 'SEQ_01') shot.commit(triggers=False) if not Search.eval("@SOBJECT(prod/sequence['code','SEQ_01'])"): seq = SearchType.create("prod/sequence") seq.set_value('code', 'SEQ_01') seq.commit(triggers=False)
def get_display(self): widget = DivWdg() self.set_as_panel(widget, class_name='spt_view_panel spt_panel') # create a table widget and set the sobjects to it table_id = "main_body_table" filter = self.kwargs.get('filter') table = TableLayoutWdg(table_id=table_id, search_type="sthpw/timecard", \ view="table", inline_search=True, filter=filter, search_view='search' ) search_type = "sthpw/timecard" from tactic.ui.app import SearchWdg search_wdg = SearchWdg(search_type=search_type, view='search', filter=filter) widget.add(search_wdg) search = search_wdg.get_search() # FIX to current project timecard for now search.add_filter('project_code', Project.get_project_code()) #search.add_project_filter() table.alter_search(search) print "SEA ", search.get_statement() sobjects = search.get_sobjects() print "SOB ", sobjects table.set_sobjects(sobjects, search) widget.add(table) #widget.add(SpecialDayWdg()) return widget
def get_to(my): recipients = super(GeneralPublishEmailHandler, my).get_to() sobj = my.sobject search = Search(Task) search_type = sobj.get_search_type() search_id = sobj.get_id() search.add_filter('search_type', search_type) search.add_filter('search_id', search_id) # it will get the context if process not found #search.add_filter('process', note.get_process()) from pyasm.biz import Project search.add_filter('project_code', Project.get_project_code()) tasks = search.get_sobjects() for task in tasks: assigned = my._get_login(task.get_assigned()) if assigned: recipients.add(assigned) supe = my._get_login(task.get_supervisor()) if supe: recipients.add(supe) return recipients
def get_input_value(my, sobject, snapshot): ''' value of the loading checkbox''' # use the naming naming = Project.get_naming("node") naming.set_sobject(sobject) naming.set_snapshot(snapshot) namespace = naming.get_value() instance = sobject.get_name() snap_node_name = snapshot.get_node_name() """ # Currently, web state object is not rebuilt. shot_id = my.search_id if not shot_id: shot_id = WebState.get().get_state("shot_id") if shot_id == "": shot_id = WebContainer.get_web().get_form_value("shot_id") if shot_id == "": raise WidgetException("No shot found value passed in") """ #shot = my.parent.get_shot() shot_code = my.parent.get_value("shot_code") value = "%s|%s|%s|%s|%s|%s" % (snapshot.get_code(), shot_code, \ instance, snapshot.get_context(), namespace, snap_node_name) return value
def get_defaults(self): '''specifies the defaults for this sobject''' project_code = Project.get_project_code() me = Environment.get_user_name() defaults = {"project_code": project_code, "login": me} return defaults
def get_display(my): #defining init is better than get_display() for this kind of SelectWdg search = Search( SearchType.SEARCH_TYPE ) if my.mode == None or my.mode == my.ALL_BUT_STHPW: # always add the login / login group search types filter = search.get_regex_filter("search_type", "login|task|note|timecard|trigger|milestone", "EQ") no_sthpw_filter = search.get_regex_filter("search_type", "^(sthpw).*", "NEQ") search.add_where('%s or %s' %(filter, no_sthpw_filter)) elif my.mode == my.CURRENT_PROJECT: project = Project.get() project_code = project.get_code() #project_type = project.get_project_type().get_type() project_type = project.get_value("type") search.add_where("\"namespace\" in ('%s','%s') " % (project_type, project_code)) search.add_order_by("search_type") search_types = search.get_sobjects() values = SObject.get_values(search_types, 'search_type') labels = [ x.get_label() for x in search_types ] values.append('CustomLayoutWdg') labels.append('CustomLayoutWdg') my.set_option('values', values) my.set_option('labels', labels) #my.set_search_for_options(search, "search_type", "get_label()") my.add_empty_option(label='-- Select Search Type --') return super(SearchTypeSelectWdg, my).get_display()
def get_db_triggers(cls): site_triggers = Container.get(cls.KEY) if site_triggers == None: # find all of the triggers search = Search("sthpw/trigger") search.add_project_filter() site_triggers = search.get_sobjects() Container.put(cls.KEY, site_triggers) # find all of the project triggers from pyasm.biz import Project project_code = Project.get_project_code() key = "%s:%s" % (cls.KEY, project_code) project_triggers = Container.get(key) if project_triggers == None: if project_code not in ['admin', 'sthpw']: try: search = Search("config/trigger") project_triggers = search.get_sobjects() except SearchException, e: print "WARNING: ", e project_triggers = [] else: project_triggers = [] Container.put(key, project_triggers)
def get_display(self): web = WebContainer.get_web() user = WebContainer.get_user_name() local_dir = web.get_local_dir() context_url = web.get_site_context_url().to_string() server = web.get_base_url().to_string() upload_url = web.get_upload_url() html = Html() html.writeln( '''\n<script>try{ app = new PyXSI(); } catch(e){ app = null;} if (app) { app.user = '******'; app.local_dir = '%(local_dir)s'; app.context_url = '%(context_url)s'; app.base_url = '%(server)s'; app.upload_url = '%(upload_url)s'; app.project_code = '%(project_code)s';} </script>''' % { 'user': user, 'local_dir': local_dir, 'context_url': context_url, 'server': server, 'upload_url': upload_url, 'project_code': Project.get_project_code() }) return html
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") html.add_attr("xmlns:v", 'urn:schemas-microsoft-com:vml') is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add(my.get_copyright_wdg()) widget.add(html) # create the header head = HtmlElement("head") html.add(head) head.add( '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n' ) head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add( '<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>' ) # add the css styling head.add(my.get_css_wdg()) # add the title in the header try: project = Project.get() except Exception, e: print "ERROR: ", e # if the project doesn't exist, then use the admin project project = Project.get_by_code("admin")
def get_shot_loader_xml(my, ticket, project_code, snapshot_code, shot_code, instance_name, context="", options=""): '''uses the loader to generate an execute xml that can be used to load the assets''' try: my.init(ticket) Project.set_project(project_code) snapshot = Snapshot.get_by_code(snapshot_code) # get the shot shot = Shot.get_by_code(shot_code) if not shot: raise ServiceException("No shot [%s] exists" % shot_code) # get the loader implementation loader_context = ProdLoaderContext() loader_context.set_shot(shot) loader_context.set_context(context) # pass on any message options for the loader if options != "": loader_context.set_options(options) loader = loader_context.get_loader(snapshot) # just set the shot if we are loading the shot if shot_code == instance_name: loader.set_instance(shot) else: instance = ShotInstance.get_by_shot(shot, instance_name) if not instance: raise TacticException('Asset Instance [%s] not found in shot [%s]'%(instance_name, shot.get_code())) loader.set_instance(instance) # setting all instances in anim to be loaded with the unique flag loader.set_unique() loader.execute() execute_xml = loader.get_execute_xml() xml = execute_xml.get_xml() finally: DbContainer.close_all() return xml
def create(cls, command, transaction_data, description, title='', state=None): user_name = Environment.get_user_name() #namespace = Environment.get_env_object().get_context_name() from pyasm.biz import Project namespace = Project.get_global_project_code() # TODO: need to add a ticket column to the transaction_log table security = Environment.get_security() ticket = security.get_ticket_key() #transaction_data = transaction_data.replace("\\", "\\\\") length_before = len(transaction_data) cutoff = 10 * 1024 if length_before > cutoff: import zlib, binascii transaction_data = Common.process_unicode_string(transaction_data) ztransaction_data = binascii.hexlify( zlib.compress(transaction_data)) ztransaction_data = "zlib:%s" % ztransaction_data length_after = len(ztransaction_data) print "transaction log compress: ", "%s%%" % int( float(length_after) / float(length_before) * 100), "[%s] to [%s]" % (length_before, length_after) else: ztransaction_data = transaction_data # a new entry deletes all redos for that user TransactionLog.delete_all_redo() log = SObjectFactory.create("sthpw/transaction_log") log.set_value("login", user_name) log.set_value("command", command) log.set_value("transaction", ztransaction_data) log.set_value("title", title) log.set_value("description", description) log.set_value("type", "undo") log.set_value("namespace", namespace) log.set_value("ticket", ticket) if state: log.set_value("state", state) server = Config.get_value("install", "server") if server: log.set_value("server_code", server) log.commit(triggers=False) # FIXME: # only do an sobject log before the cutoff ... above this it gets # very slow. Need a way of doing very fast inserts if length_before <= cutoff: cls.create_sobject_log(log, transaction_data) return log
def _test_get_connect(self): database = 'unittest' project = Project.get_by_code(database) db_resource = project.get_project_db_resource() sql1 = DbContainer.get(db_resource) sql2 = DbContainer.get(db_resource) self.assertEquals(sql1, sql2)
def get_context_data(self, search_type=None): '''get the list of contexts that can be checked in with this widget''' # usually there is no pipeline for prod/shot_instance #search_type = self.search_type labels, values = Pipeline.get_process_select_data(search_type, \ project_code=Project.get_project_code()) return labels, values
def _create_timecard(my, search_type, search_id): '''create an entry in the timecard table''' timecard = SObjectFactory.create("sthpw/timecard") timecard.set_value("search_type", search_type) timecard.set_value("search_id", search_id) timecard.set_value('login', Environment.get_user_name()) timecard.set_value('project_code', Project.get_project_name()) return timecard
def get_header_class_name(cls): project = Project.get() class_name = project.get_value("header_class_name", no_exception=True) if not class_name: class_name = Config.get_value("install", "header_class_name") if not class_name: class_name = 'tactic.ui.app.PageNavContainerWdg' return class_name
def get_config(my): # TEST config_xml = ''' <config> <custom_filter> <element name='asset_library'> <display class='SelectWdg'> <query>prod/asset_library|code|code</query> <empty>true</empty> </display> </element> <element name='pipeline_code'> <display class='SelectWdg'> <query>sthpw/pipeline|code|code</query> <empty>true</empty> </display> </element> </custom_filter> </config> ''' my.view = my.kwargs.get("search_view") if not my.view: my.view = 'custom_filter' #view = "custom_filter" project_code = Project.extract_project_code(my.search_type) search = Search("config/widget_config", project_code=project_code ) search.add_filter("view", my.view) search.add_filter("search_type", my.base_search_type) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = ''' <config> <custom_filter> </custom_filter> </config> ''' # use the one defined in the default config file file_configs = WidgetConfigView.get_configs_from_file(my.base_search_type, my.view) if file_configs: config = file_configs[0] xml_node = config.get_view_node() if xml_node is not None: xml = Xml(config.get_xml().to_string()) config_xml = '<config>%s</config>' %xml.to_string(node=xml_node) from pyasm.widget import WidgetConfig config = WidgetConfig.get(view=my.view, xml=config_xml) return config