def _get_git_version(): """Function gets latest revision of the working copy. It only works in git repositories, and is actually a hack. """ try: from run_uh import get_content_dir_parent_path uh_path = get_content_dir_parent_path() git_head_path = os.path.join(uh_path, '.git', 'HEAD') if os.path.exists(git_head_path): head = open(git_head_path).readline().strip().partition(' ') if head[2]: head_file = os.path.join(uh_path, '.git', head[2]) else: head_file = git_head_path if os.path.exists(head_file): return unicode(open(head_file).readline().strip()[0:7]) #if there is no .git directory then check for gitversion.txt except ImportError: try: return unicode( open(os.path.join("content", "packages", "gitversion.txt")).read()) except IOError: return u"<unknown>" return u"<unknown>"
def get_git_version(): """Function gets latest revision of the working copy. It only works in git repositories, and is actually a hack. """ try: from run_uh import get_content_dir_parent_path uh_path = get_content_dir_parent_path() except ImportError: return "<unknown>" # Try git describe try: git = "git" if platform.system() == "Windows": git = "git.exe" # Note that this uses glob patterns, not regular expressions. # TAG_STRUCTURE = "20[0-9][0-9].[0-9]*" # describe = [git, "describe", "--tags", TAG_STRUCTURE] describe = [git, "describe", "--tags"] git_string = subprocess.check_output( describe, cwd=uh_path, universal_newlines=True).rstrip('\n') return git_string except (subprocess.CalledProcessError, RuntimeError): pass # Read current HEAD out of .git manually try: git_head_path = Path(uh_path, '.git', 'HEAD') if git_head_path.exists(): with git_head_path.open() as f: head = f.readline().strip().partition(' ') if head[2]: head_file = Path(uh_path, '.git', head[2]) else: head_file = git_head_path if head_file.exists(): with head_file.open() as f: return str(f.readline().strip()[0:7]) except ImportError: pass # Try gitversion.txt try: with open(os.path.join("content", "packages", "gitversion.txt")) as f: return f.read() except IOError: pass return "<unknown>"
def get_git_version(): """Function gets latest revision of the working copy. It only works in git repositories, and is actually a hack. """ try: from run_uh import get_content_dir_parent_path uh_path = get_content_dir_parent_path() except ImportError: return "<unknown>" # Try git describe try: git = "git" if platform.system() == "Windows": git = "git.exe" # Note that this uses glob patterns, not regular expressions. # TAG_STRUCTURE = "20[0-9][0-9].[0-9]*" # describe = [git, "describe", "--tags", TAG_STRUCTURE] describe = [git, "describe", "--tags"] git_string = subprocess.check_output(describe, cwd=uh_path, universal_newlines=True).rstrip('\n') return git_string except (subprocess.CalledProcessError, RuntimeError): pass # Read current HEAD out of .git manually try: git_head_path = Path(uh_path, '.git', 'HEAD') if git_head_path.exists(): with git_head_path.open() as f: head = f.readline().strip().partition(' ') if head[2]: head_file = Path(uh_path, '.git', head[2]) else: head_file = git_head_path if head_file.exists(): with head_file.open() as f: return str(f.readline().strip()[0:7]) except ImportError: pass # Try gitversion.txt try: with open(os.path.join("content", "packages", "gitversion.txt")) as f: return f.read() except IOError: pass return "<unknown>"
def get_git_version(): """Function gets latest revision of the working copy. It only works in git repositories, and is actually a hack. """ try: from run_uh import get_content_dir_parent_path uh_path = get_content_dir_parent_path() except ImportError: return u"<unknown>" # Try git describe try: git = "git" if platform.system() == "Windows": git = "git.exe" # Note that this uses glob patterns, not regular expressions. TAG_STRUCTURE = "20[0-9][0-9].[0-9]*" describe = [git, "describe", "--tags", "--match", TAG_STRUCTURE] return subprocess.check_output(describe, cwd=uh_path) except (subprocess.CalledProcessError, RuntimeError): pass # Read current HEAD out of .git manually try: git_head_path = os.path.join(uh_path, ".git", "HEAD") if os.path.exists(git_head_path): head = open(git_head_path).readline().strip().partition(" ") if head[2]: head_file = os.path.join(uh_path, ".git", head[2]) else: head_file = git_head_path if os.path.exists(head_file): return unicode(open(head_file).readline().strip()[0:7]) except ImportError: pass # Try gitversion.txt try: return unicode(open(os.path.join("content", "packages", "gitversion.txt")).read()) except IOError: pass return u"<unknown>"
def _get_git_version(): """Function gets latest revision of the working copy. It only works in git repositories, and is actually a hack. """ try: from run_uh import get_content_dir_parent_path uh_path = get_content_dir_parent_path() git_head_path = os.path.join(uh_path, '.git', 'HEAD') if os.path.exists(git_head_path): head = open(git_head_path).readline().strip().partition(' ') if head[2]: head_file = os.path.join(uh_path, '.git', head[2]) else: head_file = git_head_path if os.path.exists(head_file): return unicode(open(head_file).readline().strip()[0:7]) #if there is no .git directory then check for gitversion.txt except ImportError: try: return unicode(open(os.path.join("content", "packages", "gitversion.txt")).read()) except IOError: return u"<unknown>" return u"<unknown>"