Package rekall :: Module _version
[frames] | no frames]

Source Code for Module rekall._version

  1   
  2  # Machine Generated - do not edit! 
  3   
  4  # This file is produced when the main "version.py update" command is run. That 
  5  # command copies this file to all sub-packages which contain 
  6  # setup.py. Configuration is maintain in version.yaml at the project's top 
  7  # level. 
  8   
9 -def get_versions():
10 return tag_version_data(raw_versions(), """version.yaml""")
11
12 -def raw_versions():
13 return json.loads(""" 14 { 15 "codename": "Hurricane Ridge", 16 "version": "1.7.0", 17 "post": "0", 18 "rc": "1" 19 } 20 """)
21 22 import json 23 import os 24 import subprocess 25 26 try: 27 # We are looking for the git repo which contains this file. 28 MY_DIR = os.path.dirname(os.path.abspath(__file__)) 29 except: 30 MY_DIR = None 31
32 -def is_tree_dirty():
33 try: 34 return bool(subprocess.check_output( 35 ["git", "diff", "--name-only"], stderr=subprocess.PIPE, 36 cwd=MY_DIR, 37 ).splitlines()) 38 except (OSError, subprocess.CalledProcessError): 39 return False
40
41 -def get_version_file_path(version_file="version.yaml"):
42 try: 43 return os.path.join(subprocess.check_output( 44 ["git", "rev-parse", "--show-toplevel"], stderr=subprocess.PIPE, 45 cwd=MY_DIR, 46 ).strip(), version_file) 47 except (OSError, subprocess.CalledProcessError): 48 return None
49
50 -def number_of_commit_since(version_file="version.yaml"):
51 """Returns the number of commits since version.yaml was changed.""" 52 try: 53 last_commit_to_touch_version_file = subprocess.check_output( 54 ["git", "log", "--no-merges", "-n", "1", "--pretty=format:%H", 55 version_file], cwd=MY_DIR, stderr=subprocess.PIPE, 56 ).strip() 57 58 all_commits = subprocess.check_output( 59 ["git", "log", "--no-merges", "-n", "1000", "--pretty=format:%H"], 60 stderr=subprocess.PIPE, cwd=MY_DIR, 61 ).splitlines() 62 return all_commits.index(last_commit_to_touch_version_file) 63 except (OSError, subprocess.CalledProcessError, ValueError): 64 return None
65 66
67 -def get_current_git_hash():
68 try: 69 return subprocess.check_output( 70 ["git", "log", "--no-merges", "-n", "1", "--pretty=format:%H"], 71 stderr=subprocess.PIPE, cwd=MY_DIR, 72 ).strip() 73 except (OSError, subprocess.CalledProcessError): 74 return None
75
76 -def tag_version_data(version_data, version_path="version.yaml"):
77 current_hash = get_current_git_hash() 78 # Not in a git repository. 79 if current_hash is None: 80 version_data["error"] = "Not in a git repository." 81 82 else: 83 version_data["revisionid"] = current_hash 84 version_data["dirty"] = is_tree_dirty() 85 version_data["dev"] = number_of_commit_since( 86 get_version_file_path(version_path)) 87 88 # Format the version according to pep440: 89 pep440 = version_data["version"] 90 if int(version_data.get("post", 0)) > 0: 91 pep440 += ".post" + version_data["post"] 92 93 elif int(version_data.get("rc", 0)) > 0: 94 pep440 += ".rc" + version_data["rc"] 95 96 if version_data.get("dev", 0): 97 # A Development release comes _before_ the main release. 98 last = version_data["version"].rsplit(".", 1) 99 version_data["version"] = "%s.%s" % (last[0], int(last[1]) + 1) 100 pep440 = version_data["version"] + ".dev" + str(version_data["dev"]) 101 102 version_data["pep440"] = pep440 103 104 return version_data
105