def create_program_action(parent, text, name, icon=None, nt_name=None): """Create action to run a program""" if is_text_string(icon): icon = get_icon(icon) if os.name == 'nt' and nt_name is not None: name = nt_name path = programs.find_program(name) if path is not None: return create_action(parent, text, icon=icon, triggered=lambda: programs.run_program(name))
def run_vcs_tool(path, tool): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS tools: 'commit', 'browse' Return False if the VCS tool is not installed""" infos = get_vcs_infos(get_vcs_root(path)) for name, args in infos[tool]: if programs.find_program(name): programs.run_program(name, args, cwd=path) return else: raise RuntimeError( _("For %s support, please install one of the<br/> " "following tools:<br/><br/> %s") % (infos['name'], ', '.join([name for name, cmd in infos['commit']])))
def run_vcs_tool(path, tool): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS tools: 'commit', 'browse' Return False if the VCS tool is not installed""" infos = get_vcs_infos(get_vcs_root(path)) for name, args in infos[tool]: if programs.find_program(name): programs.run_program(name, args, cwd=path) return else: raise RuntimeError(_("For %s support, please install one of the<br/> " "following tools:<br/><br/> %s") % (infos['name'], ', '.join([name for name,cmd in infos['commit']]) ))
def get_hg_revision(repopath): """Return Mercurial revision for the repository located at repopath Result is a tuple (global, local, branch), with None values on error For example: >>> get_hg_revision(".") ('eba7273c69df+', '2015+', 'default') """ try: hg = programs.find_program('hg') assert hg is not None and osp.isdir(osp.join(repopath, '.hg')) output = subprocess.Popen([hg, 'id', '-nib', repopath], stdout=subprocess.PIPE).communicate()[0] # output is now: ('eba7273c69df+ 2015+ default\n', None) return tuple(output.strip().split()) except (subprocess.CalledProcessError, AssertionError, AttributeError): # print("Error: Failed to get revision number from Mercurial - %s" % exc) return (None, None, None)
def is_hg_installed(): """Return True if Mercurial is installed""" return programs.find_program('hg') is not None