def get_base_dir(my, protocol=None, alias="default"): '''get the default base directory for this sobject''' dirs = [] base_dir = '' client_os = Environment.get_env_object().get_client_os() if client_os == 'nt': prefix = "win32" else: prefix = "linux" if not alias: alias = "default" if not protocol: protocol = my.protocol if protocol == "http": repo_handler = my.sobject.get_repo_handler(my.snapshot) if repo_handler.is_tactic_repo(): base_dir = Environment.get_web_dir(alias=alias) else: alias_dict = Config.get_dict_value("perforce", "web_base_dir") base_dir = alias_dict.get(alias) if not base_dir: asset_alias_dict = Environment.get_asset_dirs() base_dir = asset_alias_dict.get(alias) base_dir = "/%s" % os.path.basename(base_dir) if not base_dir: base_dir = alias_dict.get("default") if not base_dir: base_dir = "/assets" elif protocol == "remote": # NOTE: currently needs web to get the full http base url base_dir = Environment.get_env_object().get_base_url().to_string() sub_dir = my.get_base_dir(protocol='http', alias=alias) base_dir = "%s%s" % (base_dir, sub_dir[0]) elif protocol == "file": base_dir = Environment.get_asset_dir(alias=alias) elif protocol == "env": base_dir = "$TACTIC_ASSET_DIR" # This is the central repository as seen from the client elif protocol in ["client_lib", "client_repo"]: base_dir = my.get_custom_setting('%s_client_repo_dir' % prefix) if not base_dir: alias_dict = Config.get_dict_value("checkin", "%s_client_repo_dir" % prefix) base_dir = alias_dict.get(alias) if not base_dir: base_dir = Environment.get_asset_dir() # DEPRECATED: The local repo. This one has logic to add "repo" dir # at the end. Use local_repo which does not have this logic. # keeping this around for backward compatibility elif protocol == "local": remote_repo = my.get_remote_repo() if remote_repo: #base_dir = remote_repo.get_value("repo_base_dir") base_dir = Environment.get_asset_dir() else: if Environment.get_env_object().get_client_os() =='nt': base_dir = Config.get_value("checkin","win32_local_base_dir") else: base_dir = Config.get_value("checkin","linux_local_base_dir") base_dir += "/repo" # The local repo elif protocol == "local_repo": remote_repo = my.get_remote_repo() if remote_repo: base_dir = remote_repo.get_value("repo_base_dir") else: if Environment.get_env_object().get_client_os() =='nt': base_dir = Config.get_value("checkin","win32_local_repo_dir") else: base_dir = Config.get_value("checkin","linux_local_repo_dir") if not base_dir: base_dir = Environment.get_asset_dir() elif protocol == "sandbox": remote_repo = my.get_remote_repo() if remote_repo: base_dir = remote_repo.get_value("sandbox_base_dir") else: if not base_dir: base_dict = Config.get_dict_value("checkin","%s_sandbox_dir" % prefix) base_dir = base_dict.get(alias) elif protocol == "relative": return [] assert base_dir return [base_dir]
def get_display(my): top = my.top top.add_class("spt_sandbox_select_top") sandbox_options = [ { 'name': 'fast', 'base_dir': 'C:/Fast', }, { 'name': 'faster', 'base_dir': 'C:/Faster', }, { 'name': 'slow', 'base_dir': 'Z:/Slow', } ] process = my.kwargs.get("process") search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(search_key) search_type = sobject.get_base_search_type() client_os = Environment.get_env_object().get_client_os() if client_os == 'nt': prefix = "win32" else: prefix = "linux" alias_dict = Config.get_dict_value("checkin", "%s_sandbox_dir" % prefix) search_key = sobject.get_search_key() key = "sandbox_dir:%s" % search_key from pyasm.web import WidgetSettings value = WidgetSettings.get_value_by_key(key) sandboxes_div = DivWdg() top.add(sandboxes_div) sandboxes_div.add_relay_behavior( { 'type': 'mouseenter', 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var last_background = bvr.src_el.getStyle("background-color"); bvr.src_el.setAttribute("spt_last_background", last_background); bvr.src_el.setStyle("background-color", "#E0E0E0"); bvr.src_el.setStyle("opacity", "1.0"); ''' } ) sandboxes_div.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var last_background = bvr.src_el.getAttribute("spt_last_background"); bvr.src_el.setStyle("background-color", last_background); if (!bvr.src_el.hasClass("spt_selected")) { bvr.src_el.setStyle("opacity", "0.5"); } ''' } ) sandboxes_div.add_relay_behavior( { 'type': 'mouseup', 'key': key, 'bvr_match_class': 'spt_sandbox_option', 'cbjs_action': ''' var sandbox_dir = bvr.src_el.getAttribute("spt_sandbox_dir"); var server = TacticServerStub.get(); server.set_widget_setting(bvr.key, sandbox_dir); var applet = spt.Applet.get(); applet.makedirs(sandbox_dir); //var top = bvr.src_el.getParent(".spt_sandbox_select_top"); var top = bvr.src_el.getParent(".spt_checkin_top"); spt.panel.refresh(top); ''' } ) #search = Search("config/naming") #search.add_filter("search_type", search_type) #search.add_filter("process", process) #namings = search.get_sobjects() #naming = namings[0] from pyasm.biz import Snapshot, Naming virtual_snapshot = Snapshot.create_new() virtual_snapshot.set_value("process", process) # for purposes of the sandbox folder for the checkin widget, # the context is the process virtual_snapshot.set_value("context", process) naming = Naming.get(sobject, virtual_snapshot) if naming: naming_expr = naming.get_value("sandbox_dir_naming") alias_options = naming.get_value("sandbox_dir_alias") else: naming_expr = None alias_options = None if alias_options == "__all__": alias_options = alias_dict.keys() elif alias_options: alias_options = alias_options.split("|") else: alias_options = ['default'] for alias in alias_options: from pyasm.biz import DirNaming dir_naming = DirNaming(sobject=sobject, snapshot=virtual_snapshot) dir_naming.set_protocol("sandbox") dir_naming.set_naming(naming_expr) base_dir = dir_naming.get_dir(alias=alias) sandbox_div = DivWdg() sandboxes_div.add(sandbox_div) sandbox_div.add_class("spt_sandbox_option") sandbox_div.add_attr("spt_sandbox_dir", base_dir) if value == base_dir: sandbox_div.add_color("background", "background3") #sandbox_div.set_box_shadow() sandbox_div.add_class("spt_selected") else: sandbox_div.add_style("opacity", "0.5") sandbox_div.add_style("width: auto") sandbox_div.add_style("height: 55px") sandbox_div.add_style("padding: 5px") #sandbox_div.add_style("float: left") sandbox_div.add_style("margin: 15px") sandbox_div.add_border() if alias: alias_div = DivWdg() sandbox_div.add(alias_div) alias_div.add(alias) alias_div.add_style("font-size: 1.5em") alias_div.add_style("font-weight: bold") alias_div.add_style("margin-bottom: 15px") icon_wdg = IconWdg("Folder", IconWdg.FOLDER) sandbox_div.add(icon_wdg) sandbox_div.add(base_dir) return top
def get_base_dir(self, protocol=None, alias="default"): '''get the default base directory for this sobject''' dirs = [] base_dir = '' client_os = Environment.get_env_object().get_client_os() if client_os == 'nt': prefix = "win32" else: prefix = "linux" if not alias: alias = "default" if not protocol: protocol = self.protocol if protocol == "http": repo_handler = self.sobject.get_repo_handler(self.snapshot) if repo_handler.is_tactic_repo(): base_dir = Environment.get_web_dir(alias=alias) else: alias_dict = Config.get_dict_value("perforce", "web_base_dir") base_dir = alias_dict.get(alias) if not base_dir: asset_alias_dict = Environment.get_asset_dirs() base_dir = asset_alias_dict.get(alias) base_dir = "/%s" % os.path.basename(base_dir) if not base_dir: base_dir = alias_dict.get("default") if not base_dir: base_dir = "/assets" elif protocol == "remote": # NOTE: currently needs web to get the full http base url base_dir = Environment.get_env_object().get_base_url().to_string() sub_dir = self.get_base_dir(protocol='http', alias=alias) base_dir = "%s%s" % (base_dir, sub_dir[0]) elif protocol == "file": base_dir = Environment.get_asset_dir(alias=alias) elif protocol == "env": base_dir = "$TACTIC_ASSET_DIR" # This is the central repository as seen from the client elif protocol in ["client_lib", "client_repo"]: base_dir = self.get_custom_setting('%s_client_repo_dir' % prefix) if not base_dir: alias_dict = Config.get_dict_value("checkin", "%s_client_repo_dir" % prefix) base_dir = alias_dict.get(alias) if not base_dir: base_dir = Environment.get_asset_dir() # DEPRECATED: The local repo. This one has logic to add "repo" dir # at the end. Use local_repo which does not have this logic. # keeping this around for backward compatibility elif protocol == "local": remote_repo = self.get_remote_repo() if remote_repo: #base_dir = remote_repo.get_value("repo_base_dir") base_dir = Environment.get_asset_dir() else: if Environment.get_env_object().get_client_os() =='nt': base_dir = Config.get_value("checkin","win32_local_base_dir") else: base_dir = Config.get_value("checkin","linux_local_base_dir") base_dir += "/repo" # The local repo elif protocol == "local_repo": remote_repo = self.get_remote_repo() if remote_repo: base_dir = remote_repo.get_value("repo_base_dir") else: if Environment.get_env_object().get_client_os() =='nt': base_dir = Config.get_value("checkin","win32_local_repo_dir") else: base_dir = Config.get_value("checkin","linux_local_repo_dir") if not base_dir: base_dir = Environment.get_asset_dir() elif protocol == "sandbox": remote_repo = self.get_remote_repo() if remote_repo: base_dir = remote_repo.get_value("sandbox_base_dir") else: if not base_dir: base_dict = Config.get_dict_value("checkin","%s_sandbox_dir" % prefix) base_dir = base_dict.get(alias) elif protocol == "relative": return [] assert base_dir return [base_dir]