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, 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)
def choose_vc(self, vcs): """Display VC plugin(s) that can handle the location""" self.combobox_vcs.lock = True self.combobox_vcs.get_model().clear() default_active = -1 valid_vcs = [] # Try to keep the same VC plugin active on refresh() for idx, avc in enumerate(vcs): # See if the necessary version control command exists. If so, # make sure what we're diffing is a valid respository. If either # check fails don't let the user select the that version control # tool and display a basic error message in the drop-down menu. err_str = "" def vc_installed(cmd): if not cmd: return True try: return not vc._vc.call(["which", cmd]) except OSError: if os.name == 'nt': return not vc._vc.call(["where", cmd]) if not vc_installed(avc.CMD): # TRANSLATORS: this is an error message when a version control # application isn't installed or can't be found err_str = _("%s not installed" % avc.CMD) elif not avc.valid_repo(): # TRANSLATORS: this is an error message when a version # controlled repository is invalid or corrupted err_str = _("Invalid repository") else: valid_vcs.append(idx) if (self.vc is not None and self.vc.__class__ == avc.__class__): default_active = idx if err_str: self.combobox_vcs.get_model().append( [_("%s (%s)") % (avc.NAME, err_str), avc, False]) else: name = avc.NAME or _("None") self.combobox_vcs.get_model().append([name, avc, True]) if not valid_vcs: # If we didn't get any valid vcs then fallback to null null_vcs = _null.Vc(vcs[0].location) vcs.append(null_vcs) self.combobox_vcs.get_model().insert(0, [_("None"), null_vcs, True]) default_active = 0 if default_active == -1: if valid_vcs: default_active = min(valid_vcs) else: default_active = 0 # If we only have the null VC, give a better error message. if (len(vcs) == 1 and not vcs[0].CMD) or (len(valid_vcs) == 0): tooltip = _("No valid version control system found in this folder") elif len(vcs) == 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) > 1) self.combobox_vcs.lock = False self.combobox_vcs.set_active(default_active)
def choose_vc(self, location): """Display VC plugin(s) that can handle the location""" self.combobox_vcs.lock = True vcs_model = self.combobox_vcs.get_model() vcs_model.clear() default_active = -1 valid_vcs = [] location = os.path.abspath(location or ".") # VC systems work at the directory level, so make sure we're checking # for VC support there instead of on a specific file. if os.path.isfile(location): location = os.path.dirname(location) vcs = vc.get_vcs(location) # Try to keep the same VC plugin active on refresh() for idx, avc in enumerate(vcs): # See if the necessary version control command exists. If so, # make sure what we're diffing is a valid respository. If either # check fails don't let the user select the that version control # tool and display a basic error message in the drop-down menu. err_str = "" if not avc.is_installed(): # TRANSLATORS: this is an error message when a version control # application isn't installed or can't be found err_str = _("%s not installed" % avc.CMD) elif not avc.valid_repo(location): # TRANSLATORS: this is an error message when a version # controlled repository is invalid or corrupted err_str = _("Invalid repository") else: valid_vcs.append(idx) if (self.vc is not None and self.vc.__class__ == avc.__class__): default_active = idx if err_str: vcs_model.append( [_("%s (%s)") % (avc.NAME, err_str), avc, False]) else: name = avc.NAME or _("None") vcs_model.append([name, avc(location), True]) if not valid_vcs: # If we didn't get any valid vcs then fallback to null null_vcs = _null.Vc(location) vcs.append(null_vcs) vcs_model.insert( 0, [_("None"), null_vcs, True]) default_active = 0 if default_active == -1: if valid_vcs: default_active = min(valid_vcs) else: default_active = 0 # If we only have the null VC, give a better error message. if (len(vcs) == 1 and not vcs[0].CMD) or (len(valid_vcs) == 0): tooltip = _("No valid version control system found in this folder") elif len(vcs) == 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) > 1) self.combobox_vcs.lock = False self.combobox_vcs.set_active(default_active)