<gh_stars>0
import os
import subprocess


def get_git_tag():
    """Get the latest tag 

    If the current working directory is a git repository
    return the latest tag on it. If not tags exists return
    the latest commit hash. If both of these fail return None
    """
    try:
        label = subprocess.check_output(['git', 'describe']).decode().strip()
        return label
    except subprocess.CalledProcessError as grepexc:
        return get_git_commit()


def get_git_commit():
    """Get the latest git commit

    If the current working directory is a git repository
    return the latest commit else return None
    """
    try:
        label = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()
        return label
    except subprocess.CalledProcessError as grepexc:
        return None


def which(pgm):
    # from http://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command
    path=os.getenv('PATH')
    for p in path.split(os.path.pathsep):
        p=os.path.join(p, pgm)
        if os.path.exists(p) and os.access(p, os.X_OK):
            return p


def walk_dir(templates, dest, filter=None):
    l = []
    for root, folders, files in os.walk(templates):
        for filename in files:
            if filename.endswith('.pyc') or (filter and filename not in filter):
                continue
            relative_dir = '.{0}'.format(os.path.split(os.path.join(root, filename).replace(templates, ''))[0])
            l.append((os.path.join(root, filename), os.path.join(dest, relative_dir)))
    return l
import os
import subprocess


def get_git_tag():
    """Get the latest tag 

    If the current working directory is a git repository
    return the latest tag on it. If not tags exists return
    the latest commit hash. If both of these fail return None
    """
    try:
        label = subprocess.check_output(['git', 'describe']).decode().strip()
        return label
    except subprocess.CalledProcessError as grepexc:
        return get_git_commit()


def get_git_commit():
    """Get the latest git commit

    If the current working directory is a git repository
    return the latest commit else return None
    """
    try:
        label = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()
        return label
    except subprocess.CalledProcessError as grepexc:
        return None


def which(pgm):
    # from http://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command
    path=os.getenv('PATH')
    for p in path.split(os.path.pathsep):
        p=os.path.join(p, pgm)
        if os.path.exists(p) and os.access(p, os.X_OK):
            return p


def walk_dir(templates, dest, filter=None):
    l = []
    for root, folders, files in os.walk(templates):
        for filename in files:
            if filename.endswith('.pyc') or (filter and filename not in filter):
                continue
            relative_dir = '.{0}'.format(os.path.split(os.path.join(root, filename).replace(templates, ''))[0])
            l.append((os.path.join(root, filename), os.path.join(dest, relative_dir)))
    return l
Get the latest tag       If the current working directory is a git repository     return the latest tag on it. If not tags exists return     the latest commit hash. If both of these fail return None Get the latest git commit      If the current working directory is a git repository     return the latest commit else return None # from http://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command