def __init__(self, dynamic_load=0, tab_key="tab", css=REG): self.tab_names = [] self.wdg_dict = {} self.dynamic_load = dynamic_load self.set_tab_key(tab_key) self.tab_style = css self.content_height = 0 self.mode = Container.get("tab_mode") # setting tab path self.tab_path = Container.get("tab_path") if not self.tab_path: self.tab_path = "Main" self.error_wdg = None self.div = DivWdg(css='left_content') if Environment.has_tactic_database(): self.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: self.invisible_list = [] super(TabWdg, self).__init__()
def __init__(self, dynamic_load=0, tab_key="tab", css=REG): self.tab_names = [] self.wdg_dict = {} self.dynamic_load = dynamic_load self.set_tab_key(tab_key) self.tab_style = css self.content_height = 0 self.mode = Container.get("tab_mode") # setting tab path self.tab_path = Container.get("tab_path") if not self.tab_path: self.tab_path = "Main" self.error_wdg = None self.div = DivWdg(css='left_content') if Environment.has_tactic_database(): self.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: self.invisible_list = [] super(TabWdg,self).__init__()
def __init__(my, dynamic_load=0, tab_key="tab", css=REG): my.tab_names = [] my.wdg_dict = {} my.dynamic_load = dynamic_load my.set_tab_key(tab_key) my.tab_style = css my.content_height = 0 my.mode = Container.get("tab_mode") # setting tab path my.tab_path = Container.get("tab_path") if not my.tab_path: my.tab_path = "Main" my.error_wdg = None my.div = DivWdg(css='left_content') if Environment.has_tactic_database(): my.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: my.invisible_list = [] super(TabWdg,my).__init__()
def __init__(my, dynamic_load=0, tab_key="tab", css=REG): my.tab_names = [] my.wdg_dict = {} my.dynamic_load = dynamic_load my.set_tab_key(tab_key) my.tab_style = css my.content_height = 0 my.mode = Container.get("tab_mode") # setting tab path my.tab_path = Container.get("tab_path") if not my.tab_path: my.tab_path = "Main" my.error_wdg = None my.div = DivWdg(css='left_content') if Environment.has_tactic_database(): my.invisible_list = ProdSetting.get_seq_by_key('invisible_tabs') else: my.invisible_list = [] super(TabWdg, my).__init__()
def add_behavior(my, bvr_spec): '''adds an individual behavior specification to the HTML based widget''' #print "bvr: ", str(bvr_spec).replace(r"\n", "\n") #print "---" if my.behaviors == None: my.behaviors = [] if type(bvr_spec) == types.DictType: # handle any cbjs string value that has newlines (e.g. ones specified using triple single quote block # quotes in order to have the javascript code readable as indented multi-line code) ... regex = re.compile( r'\n\s*' ) if my.__class__.__name__.find('CheckboxWdg') != -1: if bvr_spec.get('propagate_evt') == None: bvr_spec['propagate_evt'] = True script_path = bvr_spec.get('cbjs_script_path') if script_path: script_sobj = Container.get("HTML::custom_script") if script_sobj == None: basename = os.path.basename(script_path) dirname = os.path.dirname(script_path) search = Search("config/custom_script") search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() if script_sobj: Container.put("HTML::custom_script", script_sobj) v = script_sobj.get_value("script") bvr_spec['cbjs_action'] = regex.sub( '\n', v ) else: raise Exception( "Error: script path [%s] does not exist" % script_path ) for k,v in bvr_spec.iteritems(): if 'cbjs' in k and '\n' in v: bvr_spec[k] = regex.sub( '\n', v ) my.behaviors.append( bvr_spec ) elif type(bvr_spec) == types.StringType: # legacy support for any '.add_behavior' calls that provide a bvr_spec argument that is a string # representation of a behavior specification dictionary my.behaviors.append( my.convert_behavior_str(bvr_spec) ) else: raise Exception( "Behavior specification should be a dictionary, %s spec is not supported." % type(bvr_spec) ) count = Container.get("Widget:bvr_count") if not count: count = 1 else: count += 1 Container.put("Widget:bvr_count", count)
def push_palette(cls, palette): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) palette = Palette(palette=palette) palettes.append(palette)
def get_action_html(my): from pyasm.prod.site import EditorialTabWdg, MainTabWdg, ClientTabWdg #edit = SubmitWdg("do_edit", "Submit/Next" ) edit_continue = SubmitWdg("do_edit", "Submit/Close") edit_continue.add_event("onclick", "document.form.%s.value='true'" % my.CLOSE_WDG) # call an edit event #event = WebContainer.get_event("sthpw:submit") #edit.add_event( "onclick", event.get_caller() ) # create a cancel button to close the window cancel = ButtonWdg("Cancel") iframe = Container.get("iframe") cancel.add_event("onclick", "window.parent.%s" % iframe.get_off_script()) div = DivWdg(css='centered') div.center() #div.add(SpanWdg(edit, css='med')) div.add(SpanWdg(edit_continue, css='med')) div.add(SpanWdg(cancel, css='med')) return div
def get(): key = 'CacheList' cache_list = Container.get(key) if not cache_list: cache_list = CacheList() Container.put(key, cache_list) return cache_list
def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action)) button.add_style("margin: 3px 5px") return button
def get_display(my): # assert my.search is not None # search_type_obj = my.search.get_search_type_obj() search_key = my.sobject.get_search_key() title = my.sobject.get_code() upload_url = WebContainer.get_web().get_widget_url() upload_url.set_option("widget", "pyasm.prod.web.SObjectUploadWdg") upload_url.set_option("search_key", search_key) # upload_url.set_option("mode", "copy") upload_url.set_option("naming", "no") for name, value in my.upload_options.items(): upload_url.set_option(name, value) # get the main iframe iframe = Container.get("iframe") iframe.set_width(65) upload_action = iframe.get_on_script(upload_url.get_url()) # upload button upload_button = IconButtonWdg("file publish %s" % title, IconWdg.UPLOAD) upload_button.add_event("onclick", upload_action) my.add(upload_button, "upload_button") return super(SObjectFilePublishWdg, my).get_display()
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 get_by_key(cls, key, user=None, project_code=None, use_cache=True): if not user: user = Environment.get_user_name() # ignore the project_code column for now dict_key = '%s:%s:%s' %(cls.SEARCH_TYPE, project_code, user) if use_cache: settings_dict = Container.get(dict_key) else: settings_dict = None # explicit check for None if settings_dict == None: settings_dict = {} if use_cache: Container.put(dict_key, settings_dict) search = Search(cls.SEARCH_TYPE) search.add_filter("login", user) if project_code: search.add_filter("project_code", project_code) else: search.add_null_filter("project_code") # don't filter with the key in order to build a dict pref_settings = search.get_sobjects() for setting in pref_settings: settings_dict[setting.get_value('key')] = setting pref_setting = settings_dict.get(key) return pref_setting
def get_connections(cls, sobjects, direction="dst", context='', context_filters=[], src_search=None): '''return a Search instance if src_search is provided''' if not sobjects and not src_search: return [] search = Search(SObjectConnection) if direction == "dst": prefix = "src" else: prefix = "dst" if src_search: search.add_filter("%s_search_type" % prefix, src_search.get_search_type()) search.add_search_filter('%s_search_id' % prefix, src_search, op="in") else: search_types = [x.get_search_type() for x in sobjects] search_ids = [x.get_id() for x in sobjects] if len(Common.get_unique_list(search_types)) == 1: search.add_filter("%s_search_type" % prefix, search_types[0]) search.add_filters("%s_search_id" % prefix, search_ids) else: search.add_op("begin") for search_type, search_id in zip(search_types, search_ids): search.add_op("begin") search.add_filter("%s_search_type" % prefix, search_type) search.add_filter("%s_search_id" % prefix, search_id) search.add_op("and") search.add_op("or") if context: search.add_filter("context", context) elif context_filters: search.add_op_filters(context_filters) if src_search: return search # cache for connection sobjects key = search.get_statement() cache = Container.get("SObjectConnection:cache") if cache == None: cache = {} Container.put("SObjectConnection:cache", cache) ret_val = cache.get(key) if ret_val != None: return ret_val connections = search.get_sobjects() return connections
def set_pipeline(my, pipeline_xml, cache=True): '''set the pipeline externally''' # cache according to pipeline code, which will share the same xml object if my.is_insert(): cache = False search_key = my.get_search_key() xml_dict = Container.get("Pipeline:xml") if xml_dict == None: xml_dict = {} Container.put("Pipeline:xml", xml_dict) my.xml = xml_dict.get(search_key) if my.xml == None: my.xml = Xml() if cache: xml_dict[search_key] = my.xml if not pipeline_xml: pipeline_xml = "<pipeline/>" try: my.xml.read_string(pipeline_xml) except XmlException, e: my.xml.read_string("<pipeline/>")
def get(): # try getting from the web from state = Container.get("WebState") if not state: state = WebState() Container.put("WebState", state) return state
def __init__(my, buffer_id=None, display_id=None): super(DynamicLoaderWdg,my).__init__() ref_count = Container.get("DyanmicLoaderWdg:ref_count") if ref_count is None: ref_count = 0 if display_id is None: my.display_id = "dynamic_display_%s" % ref_count else: my.display_id = display_id if buffer_id is None: my.buffer_id = "dynamic_buffer_%s" % ref_count else: my.buffer_id = buffer_id my.loader_id = "dynamic_loader_%s" % ref_count Container.put("DyanmicLoaderWdg:ref_count", ref_count + 1 ) my.load_class = None my.load_args = None web = WebContainer.get_web() my.loader_url = web.get_dynamic_loader_url()
def get_process(my): '''Get from the ProcessFilterWdg in SObjectLoadWdg, otherwise get from FilterData''' process = '' # Ususally there is no pipeline defined for prod/shot_instance # so get from prod/shot search_type = my.search_type if search_type =='prod/shot_instance': search_type = 'prod/shot' state = Container.get("global_state") if state: process = state.get('process') else: # get it from FilterData data = FilterData.get() values = data.get_values_by_prefix('view_action_option') if values: process = values[0].get('load_%s_process' %search_type) if not process: from pyasm.prod.web import ProcessFilterWdg process_filter = ProcessFilterWdg(None, search_type) process = process_filter.get_value() return process
def get_process(my): '''Get from the ProcessFilterWdg in SObjectLoadWdg, otherwise get from FilterData''' process = '' # Ususally there is no pipeline defined for prod/shot_instance # so get from prod/shot search_type = my.search_type if search_type == 'prod/shot_instance': search_type = 'prod/shot' state = Container.get("global_state") if state: process = state.get('process') else: # get it from FilterData data = FilterData.get() values = data.get_values_by_prefix('view_action_option') if values: process = values[0].get('load_%s_process' % search_type) if not process: from pyasm.prod.web import ProcessFilterWdg process_filter = ProcessFilterWdg(None, search_type) process = process_filter.get_value() return process
def init(my): help = HelpItemWdg('Loader', 'The Loader lets you load 3D assets into your 3D applications. Among many options, you can choose to either reference, import, or open the asset through http or the internal file system.') my.add(help) pref = PrefSetting.get_value_by_key("use_java_maya") app = WebContainer.get_web().get_app_name_by_uri() if app == "Maya": if not Container.get('GeneralAppletWdg'): my.add( GeneralAppletWdg() ) Container.put('GeneralAppletWdg', True) site_menu = SiteMenuWdg() site_menu.add_style("float", "right") site_menu.add_style("margin-top", "-2px") my.add(site_menu) WebContainer.add_js('MayaWebTools.js') WebContainer.add_js('PyMaya.js') tab = MayaTabWdgImpl() tab_value = tab.set_tab_key("maya_tab") #my.handle_tab(tab) #my.add(tab,"tab") my.setup_tab("maya_tab", tab=tab) my.add( ProgressWdg() )
def get_resource(my): key = "Project:resource:%s" % my resource = Container.get(key) if resource == None: resource = ProjectResource(my) Container.put(key, resource) return resource
def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action) ) button.add_style("margin: 3px 5px") return button
def __init__(self, data=[]): if not data: self.data = [] elif type(data) in types.StringTypes: try: # optimize the loading of json data json_data = Container.get("json_data") if json_data == None: json_data = {} Container.put("json_data", json_data) self.data = json_data.get(data) if self.data == None: self.data = jsonloads(data) json_data[data] = self.data except ValueError, e: if e.__str__().find('No JSON object') != -1: raise SetupException('Data is not decodable as JSON.') # try a straight eval self.data = eval(data) except Exception as e: if e.__str__().find('cannot parse JSON description') != -1: raise SetupException('Data is not valid JSON.')
def get_global_project_code(cls): PROJECT_KEY = "Project:global" project_code = Container.get(PROJECT_KEY) if not project_code: project_code = "admin" Project.set_global_project_code(project_code) return project_code
def _test_add_drop_column(my): #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') my.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")) my.assertEquals(table_info == None, True) key = "%s:%s" % (db_resource, "country") cache_dict[key] = None exists = SearchType.column_exists(search_type, 'special_place') my.assertEquals(exists, False)
def get_display(my): #assert my.search is not None #search_type_obj = my.search.get_search_type_obj() search_key = my.sobject.get_search_key() title = my.sobject.get_code() upload_url = WebContainer.get_web().get_widget_url() upload_url.set_option("widget", "pyasm.prod.web.SObjectUploadWdg") upload_url.set_option("search_key", search_key) #upload_url.set_option("mode", "copy") upload_url.set_option("naming", "no") for name, value in my.upload_options.items(): upload_url.set_option(name,value) # get the main iframe iframe = Container.get("iframe") iframe.set_width(65) upload_action = iframe.get_on_script(upload_url.get_url()) # upload button upload_button = IconButtonWdg("file publish %s" % title, IconWdg.UPLOAD) upload_button.add_event("onclick", upload_action ) my.add(upload_button, "upload_button") return super(SObjectFilePublishWdg,my).get_display()
def get(): key = "JsWrapper" wrapper = Container.get(key) if wrapper == None: wrapper = JsWrapper() Container.put(key, wrapper) return wrapper
def __init__(my, buffer_id=None, display_id=None): super(DynamicLoaderWdg, my).__init__() ref_count = Container.get("DyanmicLoaderWdg:ref_count") if ref_count is None: ref_count = 0 if display_id is None: my.display_id = "dynamic_display_%s" % ref_count else: my.display_id = display_id if buffer_id is None: my.buffer_id = "dynamic_buffer_%s" % ref_count else: my.buffer_id = buffer_id my.loader_id = "dynamic_loader_%s" % ref_count Container.put("DyanmicLoaderWdg:ref_count", ref_count + 1) my.load_class = None my.load_args = None web = WebContainer.get_web() my.loader_url = web.get_dynamic_loader_url()
def init(self): help = HelpItemWdg( 'Loader', 'The Loader lets you load 3D assets into your 3D applications. Among many options, you can choose to either reference, import, or open the asset through http or the internal file system.' ) self.add(help) pref = PrefSetting.get_value_by_key("use_java_maya") app = WebContainer.get_web().get_app_name_by_uri() if app == "Maya": if not Container.get('GeneralAppletWdg'): self.add(GeneralAppletWdg()) Container.put('GeneralAppletWdg', True) site_menu = SiteMenuWdg() site_menu.add_style("float", "right") site_menu.add_style("margin-top", "-2px") self.add(site_menu) WebContainer.add_js('MayaWebTools.js') WebContainer.add_js('PyMaya.js') tab = MayaTabWdgImpl() tab_value = tab.set_tab_key("maya_tab") #self.handle_tab(tab) #self.add(tab,"tab") self.setup_tab("maya_tab", tab=tab) self.add(ProgressWdg())
def get_by_key(cls, key, user=None, project_code=None, use_cache=True): if not user: user = Environment.get_user_name() # ignore the project_code column for now dict_key = '%s:%s:%s' % (cls.SEARCH_TYPE, project_code, user) if use_cache: settings_dict = Container.get(dict_key) else: settings_dict = None # explicit check for None if settings_dict == None: settings_dict = {} if use_cache: Container.put(dict_key, settings_dict) search = Search(cls.SEARCH_TYPE) search.add_filter("login", user) if project_code: search.add_filter("project_code", project_code) else: search.add_null_filter("project_code") # don't filter with the key in order to build a dict pref_settings = search.get_sobjects() for setting in pref_settings: settings_dict[setting.get_value('key')] = setting pref_setting = settings_dict.get(key) return pref_setting
def get_action_html(self): from pyasm.prod.site import EditorialTabWdg, MainTabWdg, ClientTabWdg #edit = SubmitWdg("do_edit", "Submit/Next" ) edit_continue = SubmitWdg("do_edit", "Submit/Close" ) edit_continue.add_event("onclick", "document.form.%s.value='true'"%self.CLOSE_WDG) # call an edit event #event = WebContainer.get_event("sthpw:submit") #edit.add_event( "onclick", event.get_caller() ) # create a cancel button to close the window cancel = ButtonWdg("Cancel") iframe = Container.get("iframe") cancel.add_event("onclick", "window.parent.%s" % iframe.get_off_script() ) div = DivWdg(css='centered') div.center() #div.add(SpanWdg(edit, css='med')) div.add(SpanWdg(edit_continue, css='med')) div.add(SpanWdg(cancel, css='med')) return div
def __init__(my, data=[]): if not data: my.data = [] elif type(data) in types.StringTypes: try: # optimize the loading of json data json_data = Container.get("json_data") if json_data == None: json_data = {} Container.put("json_data", json_data) my.data = json_data.get(data) if my.data == None: my.data = jsonloads(data) json_data[data] = my.data except ValueError, e: if e.__str__().find('No JSON object') != -1: raise SetupException('Data is not decodable as JSON.') # try a straight eval my.data = eval(data) except Exception, e: if e.__str__().find('cannot parse JSON description') != -1: raise SetupException('Data is not valid JSON.')
def get_title(self): widget = Widget() if not Container.get('GeneralAppletWdg'): widget.add( GeneralAppletWdg() ) Container.put('GeneralAppletWdg', True) widget.add(super(LayerTableElementWdg, self).get_title()) return widget
def get_title(self): widget = Widget() if not Container.get('GeneralAppletWdg'): widget.add(GeneralAppletWdg()) Container.put('GeneralAppletWdg', True) widget.add(super(LayerTableElementWdg, self).get_title()) return widget
def pop_palette(cls): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) if len(palettes) == 0: return palettes[0] return palettes.pop()
def get(cls): filter_data = Container.get("FilterData") if filter_data == None: web = WebContainer.get_web() data = web.get_form_value('json') filter_data = FilterData(data) Container.put("FilterData", filter_data) return filter_data
def get_context(self): context_select = Container.get('context_filter') context = 'publish' if context_select: context = context_select.get_value() if context == "": values = context_select.get_option('values') context = values[len(values) - 1] return context
def get_global_project_code(cls): from pyasm.security import Site site = Site.get_site() PROJECT_KEY = "Project:global:%s:" % site project_code = Container.get(PROJECT_KEY) if not project_code: project_code = "admin" Project.set_global_project_code(project_code) return project_code
def get_context(my): context_select = Container.get('context_filter') context = 'publish' if context_select: context = context_select.get_value() if context == "": values = context_select.get_option('values') context = values[len(values)-1] return context
def get_unique_event_name(self): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: ref_count = 0 event_name = "event_name_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) return event_name
def get_unique_event_name(my): # generate a unique function name ref_count = Container.get("EventContainer:ref_count") if ref_count == None: ref_count = 0 event_name = "event_name_%s" % ref_count Container.put("EventContainer:ref_count", ref_count + 1 ) return event_name
def init(self): tab_path = Container.get("tab_path") if not tab_path: tab_path = self.name Container.put("tab_path", tab_path) if len(tab_path.split("/")) > 0: self.setup_tab(tab_path, css=TabWdg.SMALL) else: self.setup_tab(tab_path)
def get(cls): palettes = Container.get("Palette:palettes") if palettes == None: palettes = [] Container.put("Palette:palettes", palettes) if not palettes: palette = Palette() palettes.append(palette) else: palette = palettes[-1] return palette
def get_language(): lang = Container.get("language") if lang: return lang import os lang = os.environ.get('TACTIC_LANG') if not lang: lang = 'en' return lang
def get_project_db_resource(my): # get the db resource for attached to this particular project. # Not the db_resource for "sthpw/project" for which # project.get_db_resource() does key = "Project:db_resource:%s" % my.get_code() resource = Container.get(key) if resource != None: return resource # the project defines the resource database = my.get_database_name() assert database if database == 'sthpw': # get if from the config db_resource_code = None else: db_resource_code = my.get_value("db_resource", no_exception=True) if not db_resource_code: # this could be any project, not just sthpw # already looked at cache, so set use_cache to False db_resource = DbResource.get_default(database, use_cache=False) Container.put(key, db_resource) return db_resource #elif isinstance(db_resource_code, DbResource): elif DbResource.is_instance(db_resource_code): db_resource = db_resource_code Container.put(key, db_resource) return db_resource db_resource_code = db_resource_code.strip() search = Search("sthpw/db_resource") search.add_filter("code", db_resource_code) db_resource_sobj = search.get_sobject() if not db_resource_sobj: raise TacticException("Database Resource [%s] does not exist" % db_resource_code) host = db_resource_sobj.get_value("host") vendor = db_resource_sobj.get_value("vendor") host = db_resource_sobj.get_value("host") port = db_resource_sobj.get_value("port") user = db_resource_sobj.get_value("login") password = db_resource_sobj.get_value("password") db_resource = DbResource(database=database, host=host, port=port, vendor=vendor, password=password) Container.put(key, db_resource) return db_resource
def get_predefined_schema(cls, code): assert(code) schema = Container.get("Schema:%s" % code) if not schema: schema = Schema("sthpw/schema", dependencies=False) schema.set_value("schema", SCHEMA_XML[code]) schema.set_value("code", code) schema.init() Container.put("Schema:%s" % code, schema) return schema
def get_by_code(cls, project_name, use_cache=True): if project_name == "default": project = Container.get("default_project") return project if not use_cache: search = Search("sthpw/project") search.add_filter("code", project_name) return search.get_sobject() return super(Project, cls).get_by_code(project_name)
def get_next_job(my): from pyasm.prod.queue import Queue import random import time interval = 0.2 time.sleep(interval) job_search_type = my.get_job_search_type() servers_tried = [] job = None while 1: my.servers = Container.get("TransactionQueueServers") if my.servers == None: trigger = TransactionQueueServersTrigger() trigger.execute() my.servers = Container.get("TransactionQueueServers") # use a random load balancer. This algorithm is pretty # inefficient, but will only be an issue if there are lots # of servers num_servers = len(my.servers) if num_servers == 0: break server_index = random.randint(0, len(my.servers)-1) if server_index in servers_tried: continue server_code = my.servers[server_index].get_code() #print "server_code: ", server_code job = Queue.get_job(job_search_type=job_search_type, server_code=server_code) if job: break servers_tried.append(server_index) if len(servers_tried) == len(my.servers): break return job