def populate_vcs_for_location(self, location): """Display VC plugin(s) that can handle the location""" vcs_model = self.combobox_vcs.get_model() vcs_model.clear() # VC systems can be executed at the directory level, so make sure # we're checking for VC support there instead of # on a specific file or on deleted/unexisting path inside vc location = os.path.abspath(location or ".") while not os.path.isdir(location): parent_location = os.path.dirname(location) if len(parent_location) >= len(location): # no existing parent: for example unexisting drive on Windows break location = parent_location else: # existing parent directory was found for avc in vc.get_vcs(location): err_str = '' vc_details = {'name': avc.NAME, 'cmd': avc.CMD} if not avc.is_installed(): # Translators: This error message is shown when a version # control binary isn't installed. err_str = _("%(name)s (%(cmd)s not installed)") elif not avc.valid_repo(location): # Translators: This error message is shown when a version # controlled repository is invalid. err_str = _("%(name)s (Invalid repository)") if err_str: vcs_model.append([err_str % vc_details, avc, False]) continue vcs_model.append([avc.NAME, avc(location), True]) valid_vcs = [(i, r[1].NAME) for i, r in enumerate(vcs_model) if r[2]] default_active = min(valid_vcs)[0] if valid_vcs else 0 # Keep the same VC plugin active on refresh, otherwise use the first current_vc_name = self.vc.NAME if self.vc else None same_vc = [i for i, name in valid_vcs if name == current_vc_name] if same_vc: default_active = same_vc[0] if not valid_vcs: # If we didn't get any valid vcs then fallback to null null_vcs = _null.Vc(location) vcs_model.insert(0, [null_vcs.NAME, null_vcs, True]) tooltip = _("No valid version control system found in this folder") elif len(vcs_model) == 1: tooltip = _("Only one version control system found in this folder") else: tooltip = _("Choose which version control system to use") self.combobox_vcs.set_tooltip_text(tooltip) self.combobox_vcs.set_sensitive(len(vcs_model) > 1) self.combobox_vcs.set_active(default_active)
def populate_vcs_for_location(self, location): """Display VC plugin(s) that can handle the location""" vcs_model = self.combobox_vcs.get_model() vcs_model.clear() # VC systems can be executed at the directory level, so make sure # we're checking for VC support there instead of # on a specific file or on deleted/unexisting path inside vc location = os.path.abspath(location or ".") while not os.path.isdir(location): parent_location = os.path.dirname(location) if len(parent_location) >= len(location): # no existing parent: for example unexisting drive on Windows break location = parent_location else: # existing parent directory was found for avc in get_vcs(location): err_str = '' vc_details = {'name': avc.NAME, 'cmd': avc.CMD} if not avc.is_installed(): # Translators: This error message is shown when a version # control binary isn't installed. err_str = _("%(name)s (%(cmd)s not installed)") elif not avc.valid_repo(location): # Translators: This error message is shown when a version # controlled repository is invalid. err_str = _("%(name)s (Invalid repository)") if err_str: vcs_model.append([err_str % vc_details, avc, False]) continue vcs_model.append([avc.NAME, avc(location), True]) valid_vcs = [(i, r[1].NAME) for i, r in enumerate(vcs_model) if r[2]] default_active = min(valid_vcs)[0] if valid_vcs else 0 # Keep the same VC plugin active on refresh, otherwise use the first current_vc_name = self.vc.NAME if self.vc else None same_vc = [i for i, name in valid_vcs if name == current_vc_name] if same_vc: default_active = same_vc[0] if not valid_vcs: # If we didn't get any valid vcs then fallback to null null_vcs = _null.Vc(location) vcs_model.insert(0, [null_vcs.NAME, null_vcs, True]) tooltip = _("No valid version control system found in this folder") elif len(vcs_model) == 1: tooltip = _("Only one version control system found in this folder") else: tooltip = _("Choose which version control system to use") self.combobox_vcs.set_tooltip_text(tooltip) self.combobox_vcs.set_sensitive(len(vcs_model) > 1) self.combobox_vcs.set_active(default_active)
def populate_vcs_for_location(self, location): """Display VC plugin(s) that can handle the location""" vcs_model = self.combobox_vcs.get_model() vcs_model.clear() # VC systems can be executed at the directory level, so make sure # we're checking for VC support there instead of # on a specific file or on deleted/unexisting path inside vc location = os.path.abspath(location or ".") while not os.path.isdir(location): parent_location = os.path.dirname(location) if len(parent_location) >= len(location): # no existing parent: for example unexisting drive on Windows break location = parent_location else: # existing parent directory was found for avc, enabled in get_vcs(location): err_str = '' vc_details = {'name': avc.NAME, 'cmd': avc.CMD} if not enabled: # Translators: This error message is shown when no # repository of this type is found. err_str = _("%(name)s (not found)") elif not avc.is_installed(): # Translators: This error message is shown when a version # control binary isn't installed. err_str = _("%(name)s (%(cmd)s not installed)") elif not avc.valid_repo(location): # Translators: This error message is shown when a version # controlled repository is invalid. err_str = _("%(name)s (invalid repository)") if err_str: vcs_model.append([err_str % vc_details, avc, False]) continue vcs_model.append([avc.NAME, avc(location), True]) default_active = self.get_default_vc(vcs_model) if not any(enabled for _, _, enabled in vcs_model): # If we didn't get any valid vcs then fallback to null null_vcs = _null.Vc(location) vcs_model.insert(0, [null_vcs.NAME, null_vcs, True]) tooltip = _("No valid version control system found in this folder") else: tooltip = _("Choose which version control system to use") self.combobox_vcs.set_tooltip_text(tooltip) self.combobox_vcs.set_active(default_active)