1 from __future__
import print_function
3 from builtins
import str
19 return os.path.exists(fpath)
and os.access(fpath, os.X_OK)
21 fpath, fname = os.path.split(program)
26 for path
in os.environ[
"PATH"].split(os.pathsep):
27 exe_file = os.path.join(path, program)
33 def _get_svn_version(source_path):
34 "Get version information for a Subversion checkout. Due to the slow speed of svnversion, this will not return any indication if the source has been modified." 37 if _which(
"svn") ==
None:
43 info_process = subprocess.Popen([
"svn",
"info", source_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
46 for ver_line
in info_process.stdout.readlines():
47 if ver_line.find(b
'URL:') >= 0:
48 svn_path = ver_line.replace(b
'URL: ',b
'').strip()
49 if ver_line.find(b
'Revision:') >= 0:
50 svn_revision = ver_line.replace(b
'Revision: ',b
'').strip()
51 info_process.stdout.close()
52 except Exception
as exc:
53 raise VersionError(
"Error querying svn command: %s" % str(exc))
58 tag_match = re.search(b
'tags/([^/]+)(/[^/]*)*$', svn_path)
60 tag_name = tag_match.group(1)
64 branch_match = re.search(b
'branches/([^/]+)(/[^/]*)*$', svn_path)
66 branch_name = branch_match.group(1)
73 elif branch_name !=
None:
74 tag_branch = branch_name
77 if len(tag_branch) > 0:
78 rev_str = tag_branch + b
'-' + svn_revision
80 rev_str = svn_revision
82 return b
'SVN-' + rev_str
84 def _get_git_version(source_path):
85 "Get version information for a git clone" 88 if _which(
"git") ==
None:
91 prev_dir = os.getcwd()
95 git_process = subprocess.Popen([
"git",
"rev-parse",
"--verify",
"HEAD",
"--short"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
98 git_ver = git_process.stdout.readline().strip()
103 git_branch =
'(no branch)' 105 git_process = subprocess.Popen([
"git",
"symbolic-ref",
"HEAD"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
108 if git_process.returncode == 0:
109 git_branch = git_process.stdout.readline().strip().replace(b
"refs/heads/", b
"")
116 git_process = subprocess.Popen([
"git",
"status",
"--porcelain",
"-uno"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
119 status_ret = git_process.stdout.readline().strip()
120 if len(status_ret) > 0:
128 return b
"GIT-" + git_branch + b
'-' + git_ver + wdir_modified
131 "Retrieves version information for a GIT or Subversion directory. The returned string includes branch names as well as a revision number or hash. We first check if the path is a git clone, failing that we try subversion." 133 if not os.path.exists(source_path):
137 prev_dir = os.getcwd()
138 os.chdir(source_path)
139 if _which(
"git") !=
None:
141 ret_code = subprocess.call([
"git",
"rev-parse",
"--git-dir"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
147 if ret_code !=
None and ret_code == 0:
148 return _get_git_version(source_path)
150 return _get_svn_version(source_path)
153 "Query a L2 binary to get the compiled in version information" 155 process = subprocess.Popen([binary_filename,
"-v"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True)
156 ret_code = process.wait()
161 first_line = process.stdout.readline()
162 if not first_line.find(b
"Major version:") == 0:
165 major_version = first_line.split(b
":")[1].strip()
166 cm_version = process.stdout.readline().split(b
":")[1].strip()
167 lua_version = process.stdout.readline()
168 if len(lua_version) > 0:
169 lua_version = lua_version.split(b
":")[1].strip()
173 return major_version, cm_version, lua_version
177 if __name__ ==
"__main__":
178 if len(sys.argv) < 2:
179 print(
"Please supply a path to a Git or Subversion repository", file=sys.stderr)
182 if sys.version_info > (3,):
def source_version(source_path)
def binary_version(binary_filename)