Belle II Software  release-08-01-10
information.py
1 
8 from datetime import datetime
9 from subprocess import check_output
10 
11 
13 
14  """
15  Helper class for accessing the information about the environment.
16  """
17 
18  def __init__(self):
19  """
20  Get the variables from the environment variables.
21  """
22 
23  self.externals_versionexternals_version = ""
24 
25  self.externals_optionexternals_option = ""
26 
27  self.optionoption = ""
28 
29  self.architecturearchitecture = ""
30 
31  self.releaserelease = ""
32 
33  self.release_folderrelease_folder = ""
34 
35  self._cached_revision_cached_revision = ""
36 
37  @property
38  def revision_number(self):
39  """
40  Get the cached revision number from SVN or get it from SVN directly.
41  """
42  if not self._cached_revision_cached_revision:
43  self._cached_revision_cached_revision = self.get_current_revision_numberget_current_revision_number()
44 
45  return self._cached_revision_cached_revision
46 
47  def __str__(self):
48  """
49  A nice representation.
50  """
51  result = ""
52  result += "externals version: " + self.externals_versionexternals_version + "\n"
53  result += "externals option: " + self.externals_optionexternals_option + "\n"
54  result += "option: " + self.optionoption + "\n"
55  result += "architecture: " + self.architecturearchitecture + "\n"
56  result += "release: " + self.releaserelease + "\n"
57  result += "release folder: " + self.release_folderrelease_folder + "\n"
58  result += "revision number: " + self.revision_numberrevision_number + "\n"
59  result += "date: " + datetime.now().strftime("%Y-%m-%d") + "\n"
60  return result
61 
62  def __repr__(self):
63  """
64  Also for ipython.
65  """
66  return self.__str____str__()
67 
69  """
70  Try to download the current revision number from SVN.
71  """
72  try:
73  return check_output(["git", "log", "-1", "--format='%H'"], cwd=self.release_folderrelease_folder).decode()
74  except BaseException:
75  return ""
_cached_revision
Revision number (cached, the real getter is the property)
Definition: information.py:35