コード例 #1
0
ファイル: dir_naming.py プロジェクト: 0-T-0/TACTIC
    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]
コード例 #2
0
    def add_top_behaviors(self, top):

        # convert this to a repo directory
        asset_dir = Environment.get_asset_dir()
        web_dir = Environment.get_web_dir()

        web = WebContainer.get_web()
        browser = web.get_browser()
        use_applet = web.use_applet()

        if browser == 'Qt':
            top.add_relay_behavior({
                'type':
                'dblclick',
                'bvr_match_class':
                'spt_dir_list_item',
                'cbjs_action':
                '''
            var path = bvr.src_el.getAttribute("spt_path");
            var asset_dir = '%s';
            var web_dir = '%s';
            var relative_dir = path.replace(asset_dir, "");
            var url = web_dir + "/" + relative_dir;

            var url_parts = url.split("/");
            var file = url_parts.pop();
            file = encodeURIComponent(file);
            url_parts.push(file);
            url = url_parts.join("/");

            var class_name = 'tactic.ui.widget.EmbedWdg';
            var kwargs = {
                src: url
            }

            var parts = path.split("/");
            var filename = parts[parts.length-1];
            spt.tab.set_main_body_tab()
            spt.tab.add_new(filename, filename, class_name, kwargs);
            ''' % (asset_dir, web_dir)
            })
        else:
            top.add_relay_behavior({
                'type':
                'dblclick',
                'bvr_match_class':
                'spt_dir_list_item',
                'cbjs_action':
                '''
            var path = bvr.src_el.getAttribute("spt_path");
            if (path.indexOf('####') != -1) {
                spt.info('Cannot open the file sequence');
            } else {
                var asset_dir = '%s';
                var web_dir = '%s';
                var relative_dir = path.replace(asset_dir, "");
                var url = web_dir + "/" + relative_dir;

                // Encode the filename
                var url_parts = url.split("/");
                var filename = url_parts.pop();
                filename = encodeURIComponent(filename);
                url_parts.push(filename);
                url = url_parts.join("/");

                window.open(url);
            }
            ''' % (asset_dir, web_dir)
            })

        if use_applet:
            # add a top menu
            menu = Menu(width=180)
            menu_item = MenuItem(type='title', label='Actions')
            menu.add(menu_item)

            menu_item = MenuItem(type='action', label='Download to Folder')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                var activator = spt.smenu.get_activator(bvr);
                var applet = spt.Applet.get();
                var select_dir = true;
                var dir = applet.open_file_browser('', select_dir);
                if (!dir) {
                    dir = applet.get_current_dir();
                }
                if (!dir) {
                    spt.alert("No folder selected to copy to");
                    return;
                }
                
                var path = activator.getAttribute("spt_path");

                var asset_dir = '%s';
                var env = spt.Environment.get();
                var server_url = env.get_server_url();
                var url = server_url + "/assets/" + path.replace(asset_dir, "");
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                spt.app_busy.show("Downloading file", filename);
                applet.download_file(url, dir + "/" + filename);
                spt.app_busy.hide();
                if (dir)
                    spt.notify.show_message("Download to '" + dir + "' completed.")
                ''' % asset_dir
            })
            #menu_item = MenuItem(type='action', label='Check-out To Sandbox')
            #menu.add(menu_item)
            #menu_item.add_behavior( {
            #'type': 'click_up',
            #'cbjs_action': '''spt.alert('Not implemented yet.')'''
            #} )
            menu_item = MenuItem(type='action', label='Copy to Clipboard')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.command.clipboard_cmd.ClipboardCopyCmd';
            var search_keys = [search_key];
            var kwargs = {
                search_keys: search_keys
            }
            try {
                spt.app_busy.show("Copy to Clipboard ...");
                server.execute_cmd(class_name, kwargs);
                spt.app_busy.hide();
                }
            catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            '''
            })

            menu_item = MenuItem(type='action', label='View Metadata')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.ui.checkin.SnapshotMetadataWdg';
            var kwargs = {
                search_key: search_key
            }
            spt.panel.load_popup("Metadata", class_name, kwargs);
            '''
            })

            menus_in = {
                'FILE_MENU_CTX': menu,
            }
            SmartMenu.attach_smart_context_menu(top, menus_in, False)

        self.add_selection(top)

        super(SnapshotDirListWdg, self).add_top_behaviors(top)
コード例 #3
0
    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]
コード例 #4
0
ファイル: snapshot_files_wdg.py プロジェクト: mincau/TACTIC
    def add_top_behaviors(self, top):

        # convert this to a repo directory
        asset_dir = Environment.get_asset_dir()
        web_dir = Environment.get_web_dir()

        web = WebContainer.get_web()
        browser = web.get_browser()
        use_applet = web.use_applet()

        if browser == 'Qt':
            top.add_relay_behavior( {
            'type': 'dblclick',
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
            var path = bvr.src_el.getAttribute("spt_path");
            var asset_dir = '%s';
            var web_dir = '%s';
            var relative_dir = path.replace(asset_dir, "");
            var url = web_dir + "/" + relative_dir;

            var url_parts = url.split("/");
            var file = url_parts.pop();
            file = encodeURIComponent(file);
            url_parts.push(file);
            url = url_parts.join("/");

            var class_name = 'tactic.ui.widget.EmbedWdg';
            var kwargs = {
                src: url
            }

            var parts = path.split("/");
            var filename = parts[parts.length-1];
            spt.tab.set_main_body_tab()
            spt.tab.add_new(filename, filename, class_name, kwargs);
            ''' % (asset_dir, web_dir)
            } )
        else:
            top.add_relay_behavior( {
            'type': 'dblclick',
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
            var path = bvr.src_el.getAttribute("spt_path");
            if (path.indexOf('####') != -1) {
                spt.info('Cannot open the file sequence');
            } else {
                var asset_dir = '%s';
                var web_dir = '%s';
                var relative_dir = path.replace(asset_dir, "");
                var url = web_dir + "/" + relative_dir;

                // Encode the filename
                var url_parts = url.split("/");
                var filename = url_parts.pop();
                filename = encodeURIComponent(filename);
                url_parts.push(filename);
                url = url_parts.join("/");

                window.open(url);
            }
            ''' % (asset_dir, web_dir)
            } )

        if use_applet:
            # add a top menu
            menu = Menu(width=180)
            menu_item = MenuItem(type='title', label='Actions')
            menu.add(menu_item)

            menu_item = MenuItem(type='action', label='Download to Folder')
            menu.add(menu_item)
            menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var activator = spt.smenu.get_activator(bvr);
                var applet = spt.Applet.get();
                var select_dir = true;
                var dir = applet.open_file_browser('', select_dir);
                if (!dir) {
                    dir = applet.get_current_dir();
                }
                if (!dir) {
                    spt.alert("No folder selected to copy to");
                    return;
                }
                
                var path = activator.getAttribute("spt_path");

                var asset_dir = '%s';
                var env = spt.Environment.get();
                var server_url = env.get_server_url();
                var url = server_url + "/assets/" + path.replace(asset_dir, "");
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                spt.app_busy.show("Downloading file", filename);
                applet.download_file(url, dir + "/" + filename);
                spt.app_busy.hide();
                if (dir)
                    spt.notify.show_message("Download to '" + dir + "' completed.")
                ''' % asset_dir
            } )
            #menu_item = MenuItem(type='action', label='Check-out To Sandbox')
            #menu.add(menu_item)
            #menu_item.add_behavior( {
            #'type': 'click_up',
            #'cbjs_action': '''spt.alert('Not implemented yet.')'''
            #} )
            menu_item = MenuItem(type='action', label='Copy to Clipboard')
            menu.add(menu_item)
            menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.command.clipboard_cmd.ClipboardCopyCmd';
            var search_keys = [search_key];
            var kwargs = {
                search_keys: search_keys
            }
            try {
                spt.app_busy.show("Copy to Clipboard ...");
                server.execute_cmd(class_name, kwargs);
                spt.app_busy.hide();
                }
            catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            '''
            } )


            menu_item = MenuItem(type='action', label='View Metadata')
            menu.add(menu_item)
            menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.ui.checkin.SnapshotMetadataWdg';
            var kwargs = {
                search_key: search_key
            }
            spt.panel.load_popup("Metadata", class_name, kwargs);
            '''
            } )

            menus_in = {
                'FILE_MENU_CTX': menu,
            }
            SmartMenu.attach_smart_context_menu( top, menus_in, False )


        self.add_selection(top)
 
        super(SnapshotDirListWdg, self).add_top_behaviors(top)