We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pootle Install 
I am a Pootle novice, I successfully installed it on the mac, but when i want to deploy to the production environment, the following installation error occurs.

# Steps to reproduce:

1. I create a virtualenv env
2. Install Pootle requirements
3. Install Pootle, using `pip install --process-dependency-links Pootle`

# Results (Expected/Actual):

```Python
Collecting Pootle
  Using cached Pootle-2.8.1.tar.bz2
    Complete output from command python setup.py egg_info:
    Pootle requires a non-PyPI dependency, when using pip ensure you use the --process-dependency-links option.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-_2TvXs/Pootle/setup.py", line 453, in <module>
        long_description=parse_long_description(README_FILE, tag=True),
      File "/tmp/pip-build-_2TvXs/Pootle/setup.py", line 404, in parse_long_description
        replace_urls()
      File "/tmp/pip-build-_2TvXs/Pootle/setup.py", line 332, in replace_urls
        branch = version.get_git_branch()
      File "/tmp/pip-build-_2TvXs/Pootle/pootle/core/utils/version.py", line 231, in get_git_branch
        'HEAD']).strip()
    AttributeError: 'NoneType' object has no attribute 'strip'
```


# Environment (i.e. 'pootle --version', DB, OS, Browser):

python version: 2.7.12
system: ubuntu 16.04


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/core/utils/version.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 # Some functions are taken from or modelled on the version management in
10 # Django.  Those are:
11 # Copyright (c) Django Software Foundation and individual contributors.  All
12 # rights reserved.
13 
14 from __future__ import print_function
15 
16 import datetime
17 import os
18 import subprocess
19 
20 try:
21     from django.utils.lru_cache import lru_cache
22 except ImportError:
23     # Required for Python 2.7 support and when backported Django version is
24     # unavailable
25     def lru_cache():
26         def fake(func):
27             return func
28         return fake
29 
30 from pootle.constants import VERSION
31 
32 
33 CANDIDATE_MARKERS = ('alpha', 'beta', 'rc', 'final')
34 
35 
36 def get_version(version=None):
37     """Returns a PEP 440-compliant version number from VERSION.
38 
39     The following examples show a progression from development through
40     pre-release to release and the resultant versions generated:
41 
42     >>> get_version((2, 7, 1, 'alpha', 0))
43     '2.7.1.dev20150530132219'
44     >>> get_version((2, 7, 1, 'alpha', 1))
45     '2.7.1a1'
46     >>> get_version((2, 7, 1, 'beta', 1))
47     '2.7.1b1'
48     >>> get_version((2, 7, 1, 'rc', 2))
49     '2.7.1rc2'
50     >>> get_version((2, 7, 1, 'final', 0))
51     '2.7.1'
52     """
53     version = get_complete_version(version)
54 
55     # Now build the two parts of the version number:
56     # main = X.Y[.Z]
57     # sub = .devN - for pre-alpha releases
58     #     | {a|b|rc}N - for alpha, beta and rc releases
59 
60     main = get_main_version(version)
61     candidate_pos = _get_candidate_pos(version)
62     candidate = version[candidate_pos]
63     candidate_extra = version[candidate_pos+1]
64 
65     sub = ''
66     if _is_development_candidate(version):
67         git_changeset = get_git_changeset()
68         if git_changeset:
69             sub = '.dev%s' % git_changeset
70         else:
71             sub = '.dev0'
72 
73     elif candidate != 'final':
74         mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
75         sub = mapping[candidate] + str(candidate_extra)
76 
77     return str(main + sub)
78 
79 
80 def _is_development_candidate(version):
81     """Is this a pre-alpha release
82 
83     >>> _is_development_candidate((2, 1, 0, 'alpha', 0))
84     True
85     >>> _is_development_candidate((2, 1, 0, 'beta', 1))
86     False
87     """
88     candidate_pos = _get_candidate_pos(version)
89     candidate = version[candidate_pos]
90     candidate_extra = version[candidate_pos+1]
91     return candidate == 'alpha' and candidate_extra == 0
92 
93 
94 def _get_candidate_pos(version):
95     """Returns the position of the candidate marker.
96 
97     >>> _get_candidate_pos((1, 2, 0, 'alpha', 0))
98     3
99     """
100     return [i for i, part in enumerate(version)
101             if part in CANDIDATE_MARKERS][0]
102 
103 
104 def _get_candidate(version):
105     """Returns the candidate. One of alpha, beta, rc or final.
106 
107     >>> _get_candidate((0, 1, 2, 'rc', 1))
108     'rc'
109     """
110     return version[_get_candidate_pos(version)]
111 
112 
113 def _get_version_string(parts):
114     """Returns an X.Y.Z version from the list of version parts.
115 
116     >>> _get_version_string((1, 1, 0))
117     '1.1.0'
118     >>> _get_version_string((1, 1, 0, 1))
119     '1.1.0.1'
120     """
121     return '.'.join(str(x) for x in parts)
122 
123 
124 def get_main_version(version=None):
125     """Returns main version (X.Y[.Z]) from VERSION.
126 
127     >>> get_main_version((1, 2, 3, 'alpha', 1))
128     '1.2.3'
129     """
130     version = get_complete_version(version)
131     candidate_pos = _get_candidate_pos(version)
132     return _get_version_string(version[:candidate_pos])
133 
134 
135 def get_major_minor_version(version=None):
136     """Returns X.Y from VERSION.
137 
138     >>> get_major_minor_version((1, 2, 3, 'final', 0))
139     '1.2'
140     """
141     version = get_complete_version(version)
142     return _get_version_string(version[:2])
143 
144 
145 def get_complete_version(version=None):
146     """Returns a tuple of the Pootle version. Or the supplied ``version``
147 
148     >>> get_complete_version((1, 2, 3, 'alpha', 0))
149     (1, 2, 3, 'alpha', 0)
150     """
151     if version is not None:
152         return version
153 
154     return VERSION
155 
156 
157 def get_docs_version(version=None, positions=2):
158     """Return the version used in documentation.
159 
160     >>> get_docs_version((1, 2, 1, 'alpha', 0))
161     'dev'
162     >>> get_docs_version((1, 2, 1, 'rc', 2))
163     '1.2'
164     """
165     version = get_complete_version(version)
166     candidate_pos = _get_candidate_pos(version)
167     if positions > candidate_pos:
168         positions = candidate_pos
169     if _is_development_candidate(version):
170         return 'dev'
171     return _get_version_string(version[:positions])
172 
173 
174 def get_rtd_version(version=None):
175     """Return the docs version string reported in the RTD site."""
176     version_str = get_docs_version(version=version, positions=2)
177     return (
178         'latest'
179         if version_str == 'dev'
180         else 'stable-%s.x' % (version_str, )
181     )
182 
183 
184 def _shell_command(command):
185     """Return the first result of a shell ``command``"""
186     repo_dir = os.path.dirname(os.path.abspath(__file__))
187 
188     try:
189         command_subprocess = subprocess.Popen(
190             command,
191             stdout=subprocess.PIPE,
192             stderr=subprocess.PIPE,
193             cwd=repo_dir,
194             universal_newlines=True
195         )
196     except OSError:
197         return None
198 
199     return command_subprocess.communicate()[0]
200 
201 
202 @lru_cache()
203 def get_git_changeset():
204     """Returns a numeric identifier of the latest git changeset.
205 
206     The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
207     This value isn't guaranteed to be unique, but collisions are very unlikely,
208     so it's sufficient for generating the development version numbers.
209 
210     >>> get_git_changeset()
211     '20150530132219'
212     """
213     timestamp = _shell_command(
214         ['/usr/bin/git', 'log', '--pretty=format:%ct', '--quiet', '-1', 'HEAD']
215     )
216     try:
217         timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
218     except ValueError:
219         return None
220     return timestamp.strftime('%Y%m%d%H%M%S')
221 
222 
223 @lru_cache()
224 def get_git_branch():
225     """Returns the current git branch.
226 
227     >>> get_git_branch()
228     'feature/proper_version'
229     """
230     branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q',
231                              'HEAD']).strip()
232     if not branch:
233         return None
234     return "/".join(branch.split("/")[2:])
235 
236 
237 @lru_cache()
238 def get_git_hash():
239     """Returns the current git commit hash or None.
240 
241     >>> get_git_hash()
242     'ad768e8'
243     """
244     git_hash = _shell_command(
245         ['/usr/bin/git', 'rev-parse', '--verify', '--short', 'HEAD']
246     )
247     if git_hash:
248         return git_hash.strip()
249     return None
250 
251 
252 if __name__ == "__main__":
253     from sys import argv
254     if len(argv) == 2:
255         if argv[1] == "main":
256             print(get_main_version())
257         elif argv[1] == "major_minor":
258             print(get_major_minor_version())
259         elif argv[1] == "docs":
260             print(get_docs_version())
261     else:
262         print(get_version())
263 
264 
265 def is_prerelease(version=None):
266     """Is this a final release or not"""
267 
268     return _get_candidate(get_complete_version(version)) != 'final'
269
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/core/utils/version.py b/pootle/core/utils/version.py
--- a/pootle/core/utils/version.py
+++ b/pootle/core/utils/version.py
@@ -228,10 +228,10 @@
     'feature/proper_version'
     """
     branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q',
-                             'HEAD']).strip()
+                             'HEAD'])
     if not branch:
         return None
-    return "/".join(branch.split("/")[2:])
+    return "/".join(branch.strip().split("/")[2:])
 
 
 @lru_cache()

{"golden_diff": "diff --git a/pootle/core/utils/version.py b/pootle/core/utils/version.py\n--- a/pootle/core/utils/version.py\n+++ b/pootle/core/utils/version.py\n@@ -228,10 +228,10 @@\n     'feature/proper_version'\n     \"\"\"\n     branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q',\n-                             'HEAD']).strip()\n+                             'HEAD'])\n     if not branch:\n         return None\n-    return \"/\".join(branch.split(\"/\")[2:])\n+    return \"/\".join(branch.strip().split(\"/\")[2:])\n \n \n @lru_cache()\n", "issue": "Pootle Install \nI am a Pootle novice, I successfully installed it on the mac, but when i want to deploy to the production environment, the following installation error occurs.\r\n\r\n# Steps to reproduce:\r\n\r\n1. I create a virtualenv env\r\n2. Install Pootle requirements\r\n3. Install Pootle, using `pip install --process-dependency-links Pootle`\r\n\r\n# Results (Expected/Actual):\r\n\r\n```Python\r\nCollecting Pootle\r\n  Using cached Pootle-2.8.1.tar.bz2\r\n    Complete output from command python setup.py egg_info:\r\n    Pootle requires a non-PyPI dependency, when using pip ensure you use the --process-dependency-links option.\r\n    Traceback (most recent call last):\r\n      File \"<string>\", line 1, in <module>\r\n      File \"/tmp/pip-build-_2TvXs/Pootle/setup.py\", line 453, in <module>\r\n        long_description=parse_long_description(README_FILE, tag=True),\r\n      File \"/tmp/pip-build-_2TvXs/Pootle/setup.py\", line 404, in parse_long_description\r\n        replace_urls()\r\n      File \"/tmp/pip-build-_2TvXs/Pootle/setup.py\", line 332, in replace_urls\r\n        branch = version.get_git_branch()\r\n      File \"/tmp/pip-build-_2TvXs/Pootle/pootle/core/utils/version.py\", line 231, in get_git_branch\r\n        'HEAD']).strip()\r\n    AttributeError: 'NoneType' object has no attribute 'strip'\r\n```\r\n\r\n\r\n# Environment (i.e. 'pootle --version', DB, OS, Browser):\r\n\r\npython version: 2.7.12\r\nsystem: ubuntu 16.04\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n# Some functions are taken from or modelled on the version management in\n# Django.  Those are:\n# Copyright (c) Django Software Foundation and individual contributors.  All\n# rights reserved.\n\nfrom __future__ import print_function\n\nimport datetime\nimport os\nimport subprocess\n\ntry:\n    from django.utils.lru_cache import lru_cache\nexcept ImportError:\n    # Required for Python 2.7 support and when backported Django version is\n    # unavailable\n    def lru_cache():\n        def fake(func):\n            return func\n        return fake\n\nfrom pootle.constants import VERSION\n\n\nCANDIDATE_MARKERS = ('alpha', 'beta', 'rc', 'final')\n\n\ndef get_version(version=None):\n    \"\"\"Returns a PEP 440-compliant version number from VERSION.\n\n    The following examples show a progression from development through\n    pre-release to release and the resultant versions generated:\n\n    >>> get_version((2, 7, 1, 'alpha', 0))\n    '2.7.1.dev20150530132219'\n    >>> get_version((2, 7, 1, 'alpha', 1))\n    '2.7.1a1'\n    >>> get_version((2, 7, 1, 'beta', 1))\n    '2.7.1b1'\n    >>> get_version((2, 7, 1, 'rc', 2))\n    '2.7.1rc2'\n    >>> get_version((2, 7, 1, 'final', 0))\n    '2.7.1'\n    \"\"\"\n    version = get_complete_version(version)\n\n    # Now build the two parts of the version number:\n    # main = X.Y[.Z]\n    # sub = .devN - for pre-alpha releases\n    #     | {a|b|rc}N - for alpha, beta and rc releases\n\n    main = get_main_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    candidate = version[candidate_pos]\n    candidate_extra = version[candidate_pos+1]\n\n    sub = ''\n    if _is_development_candidate(version):\n        git_changeset = get_git_changeset()\n        if git_changeset:\n            sub = '.dev%s' % git_changeset\n        else:\n            sub = '.dev0'\n\n    elif candidate != 'final':\n        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}\n        sub = mapping[candidate] + str(candidate_extra)\n\n    return str(main + sub)\n\n\ndef _is_development_candidate(version):\n    \"\"\"Is this a pre-alpha release\n\n    >>> _is_development_candidate((2, 1, 0, 'alpha', 0))\n    True\n    >>> _is_development_candidate((2, 1, 0, 'beta', 1))\n    False\n    \"\"\"\n    candidate_pos = _get_candidate_pos(version)\n    candidate = version[candidate_pos]\n    candidate_extra = version[candidate_pos+1]\n    return candidate == 'alpha' and candidate_extra == 0\n\n\ndef _get_candidate_pos(version):\n    \"\"\"Returns the position of the candidate marker.\n\n    >>> _get_candidate_pos((1, 2, 0, 'alpha', 0))\n    3\n    \"\"\"\n    return [i for i, part in enumerate(version)\n            if part in CANDIDATE_MARKERS][0]\n\n\ndef _get_candidate(version):\n    \"\"\"Returns the candidate. One of alpha, beta, rc or final.\n\n    >>> _get_candidate((0, 1, 2, 'rc', 1))\n    'rc'\n    \"\"\"\n    return version[_get_candidate_pos(version)]\n\n\ndef _get_version_string(parts):\n    \"\"\"Returns an X.Y.Z version from the list of version parts.\n\n    >>> _get_version_string((1, 1, 0))\n    '1.1.0'\n    >>> _get_version_string((1, 1, 0, 1))\n    '1.1.0.1'\n    \"\"\"\n    return '.'.join(str(x) for x in parts)\n\n\ndef get_main_version(version=None):\n    \"\"\"Returns main version (X.Y[.Z]) from VERSION.\n\n    >>> get_main_version((1, 2, 3, 'alpha', 1))\n    '1.2.3'\n    \"\"\"\n    version = get_complete_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    return _get_version_string(version[:candidate_pos])\n\n\ndef get_major_minor_version(version=None):\n    \"\"\"Returns X.Y from VERSION.\n\n    >>> get_major_minor_version((1, 2, 3, 'final', 0))\n    '1.2'\n    \"\"\"\n    version = get_complete_version(version)\n    return _get_version_string(version[:2])\n\n\ndef get_complete_version(version=None):\n    \"\"\"Returns a tuple of the Pootle version. Or the supplied ``version``\n\n    >>> get_complete_version((1, 2, 3, 'alpha', 0))\n    (1, 2, 3, 'alpha', 0)\n    \"\"\"\n    if version is not None:\n        return version\n\n    return VERSION\n\n\ndef get_docs_version(version=None, positions=2):\n    \"\"\"Return the version used in documentation.\n\n    >>> get_docs_version((1, 2, 1, 'alpha', 0))\n    'dev'\n    >>> get_docs_version((1, 2, 1, 'rc', 2))\n    '1.2'\n    \"\"\"\n    version = get_complete_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    if positions > candidate_pos:\n        positions = candidate_pos\n    if _is_development_candidate(version):\n        return 'dev'\n    return _get_version_string(version[:positions])\n\n\ndef get_rtd_version(version=None):\n    \"\"\"Return the docs version string reported in the RTD site.\"\"\"\n    version_str = get_docs_version(version=version, positions=2)\n    return (\n        'latest'\n        if version_str == 'dev'\n        else 'stable-%s.x' % (version_str, )\n    )\n\n\ndef _shell_command(command):\n    \"\"\"Return the first result of a shell ``command``\"\"\"\n    repo_dir = os.path.dirname(os.path.abspath(__file__))\n\n    try:\n        command_subprocess = subprocess.Popen(\n            command,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            cwd=repo_dir,\n            universal_newlines=True\n        )\n    except OSError:\n        return None\n\n    return command_subprocess.communicate()[0]\n\n\n@lru_cache()\ndef get_git_changeset():\n    \"\"\"Returns a numeric identifier of the latest git changeset.\n\n    The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.\n    This value isn't guaranteed to be unique, but collisions are very unlikely,\n    so it's sufficient for generating the development version numbers.\n\n    >>> get_git_changeset()\n    '20150530132219'\n    \"\"\"\n    timestamp = _shell_command(\n        ['/usr/bin/git', 'log', '--pretty=format:%ct', '--quiet', '-1', 'HEAD']\n    )\n    try:\n        timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))\n    except ValueError:\n        return None\n    return timestamp.strftime('%Y%m%d%H%M%S')\n\n\n@lru_cache()\ndef get_git_branch():\n    \"\"\"Returns the current git branch.\n\n    >>> get_git_branch()\n    'feature/proper_version'\n    \"\"\"\n    branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q',\n                             'HEAD']).strip()\n    if not branch:\n        return None\n    return \"/\".join(branch.split(\"/\")[2:])\n\n\n@lru_cache()\ndef get_git_hash():\n    \"\"\"Returns the current git commit hash or None.\n\n    >>> get_git_hash()\n    'ad768e8'\n    \"\"\"\n    git_hash = _shell_command(\n        ['/usr/bin/git', 'rev-parse', '--verify', '--short', 'HEAD']\n    )\n    if git_hash:\n        return git_hash.strip()\n    return None\n\n\nif __name__ == \"__main__\":\n    from sys import argv\n    if len(argv) == 2:\n        if argv[1] == \"main\":\n            print(get_main_version())\n        elif argv[1] == \"major_minor\":\n            print(get_major_minor_version())\n        elif argv[1] == \"docs\":\n            print(get_docs_version())\n    else:\n        print(get_version())\n\n\ndef is_prerelease(version=None):\n    \"\"\"Is this a final release or not\"\"\"\n\n    return _get_candidate(get_complete_version(version)) != 'final'\n", "path": "pootle/core/utils/version.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n# Some functions are taken from or modelled on the version management in\n# Django.  Those are:\n# Copyright (c) Django Software Foundation and individual contributors.  All\n# rights reserved.\n\nfrom __future__ import print_function\n\nimport datetime\nimport os\nimport subprocess\n\ntry:\n    from django.utils.lru_cache import lru_cache\nexcept ImportError:\n    # Required for Python 2.7 support and when backported Django version is\n    # unavailable\n    def lru_cache():\n        def fake(func):\n            return func\n        return fake\n\nfrom pootle.constants import VERSION\n\n\nCANDIDATE_MARKERS = ('alpha', 'beta', 'rc', 'final')\n\n\ndef get_version(version=None):\n    \"\"\"Returns a PEP 440-compliant version number from VERSION.\n\n    The following examples show a progression from development through\n    pre-release to release and the resultant versions generated:\n\n    >>> get_version((2, 7, 1, 'alpha', 0))\n    '2.7.1.dev20150530132219'\n    >>> get_version((2, 7, 1, 'alpha', 1))\n    '2.7.1a1'\n    >>> get_version((2, 7, 1, 'beta', 1))\n    '2.7.1b1'\n    >>> get_version((2, 7, 1, 'rc', 2))\n    '2.7.1rc2'\n    >>> get_version((2, 7, 1, 'final', 0))\n    '2.7.1'\n    \"\"\"\n    version = get_complete_version(version)\n\n    # Now build the two parts of the version number:\n    # main = X.Y[.Z]\n    # sub = .devN - for pre-alpha releases\n    #     | {a|b|rc}N - for alpha, beta and rc releases\n\n    main = get_main_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    candidate = version[candidate_pos]\n    candidate_extra = version[candidate_pos+1]\n\n    sub = ''\n    if _is_development_candidate(version):\n        git_changeset = get_git_changeset()\n        if git_changeset:\n            sub = '.dev%s' % git_changeset\n        else:\n            sub = '.dev0'\n\n    elif candidate != 'final':\n        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}\n        sub = mapping[candidate] + str(candidate_extra)\n\n    return str(main + sub)\n\n\ndef _is_development_candidate(version):\n    \"\"\"Is this a pre-alpha release\n\n    >>> _is_development_candidate((2, 1, 0, 'alpha', 0))\n    True\n    >>> _is_development_candidate((2, 1, 0, 'beta', 1))\n    False\n    \"\"\"\n    candidate_pos = _get_candidate_pos(version)\n    candidate = version[candidate_pos]\n    candidate_extra = version[candidate_pos+1]\n    return candidate == 'alpha' and candidate_extra == 0\n\n\ndef _get_candidate_pos(version):\n    \"\"\"Returns the position of the candidate marker.\n\n    >>> _get_candidate_pos((1, 2, 0, 'alpha', 0))\n    3\n    \"\"\"\n    return [i for i, part in enumerate(version)\n            if part in CANDIDATE_MARKERS][0]\n\n\ndef _get_candidate(version):\n    \"\"\"Returns the candidate. One of alpha, beta, rc or final.\n\n    >>> _get_candidate((0, 1, 2, 'rc', 1))\n    'rc'\n    \"\"\"\n    return version[_get_candidate_pos(version)]\n\n\ndef _get_version_string(parts):\n    \"\"\"Returns an X.Y.Z version from the list of version parts.\n\n    >>> _get_version_string((1, 1, 0))\n    '1.1.0'\n    >>> _get_version_string((1, 1, 0, 1))\n    '1.1.0.1'\n    \"\"\"\n    return '.'.join(str(x) for x in parts)\n\n\ndef get_main_version(version=None):\n    \"\"\"Returns main version (X.Y[.Z]) from VERSION.\n\n    >>> get_main_version((1, 2, 3, 'alpha', 1))\n    '1.2.3'\n    \"\"\"\n    version = get_complete_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    return _get_version_string(version[:candidate_pos])\n\n\ndef get_major_minor_version(version=None):\n    \"\"\"Returns X.Y from VERSION.\n\n    >>> get_major_minor_version((1, 2, 3, 'final', 0))\n    '1.2'\n    \"\"\"\n    version = get_complete_version(version)\n    return _get_version_string(version[:2])\n\n\ndef get_complete_version(version=None):\n    \"\"\"Returns a tuple of the Pootle version. Or the supplied ``version``\n\n    >>> get_complete_version((1, 2, 3, 'alpha', 0))\n    (1, 2, 3, 'alpha', 0)\n    \"\"\"\n    if version is not None:\n        return version\n\n    return VERSION\n\n\ndef get_docs_version(version=None, positions=2):\n    \"\"\"Return the version used in documentation.\n\n    >>> get_docs_version((1, 2, 1, 'alpha', 0))\n    'dev'\n    >>> get_docs_version((1, 2, 1, 'rc', 2))\n    '1.2'\n    \"\"\"\n    version = get_complete_version(version)\n    candidate_pos = _get_candidate_pos(version)\n    if positions > candidate_pos:\n        positions = candidate_pos\n    if _is_development_candidate(version):\n        return 'dev'\n    return _get_version_string(version[:positions])\n\n\ndef get_rtd_version(version=None):\n    \"\"\"Return the docs version string reported in the RTD site.\"\"\"\n    version_str = get_docs_version(version=version, positions=2)\n    return (\n        'latest'\n        if version_str == 'dev'\n        else 'stable-%s.x' % (version_str, )\n    )\n\n\ndef _shell_command(command):\n    \"\"\"Return the first result of a shell ``command``\"\"\"\n    repo_dir = os.path.dirname(os.path.abspath(__file__))\n\n    try:\n        command_subprocess = subprocess.Popen(\n            command,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            cwd=repo_dir,\n            universal_newlines=True\n        )\n    except OSError:\n        return None\n\n    return command_subprocess.communicate()[0]\n\n\n@lru_cache()\ndef get_git_changeset():\n    \"\"\"Returns a numeric identifier of the latest git changeset.\n\n    The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.\n    This value isn't guaranteed to be unique, but collisions are very unlikely,\n    so it's sufficient for generating the development version numbers.\n\n    >>> get_git_changeset()\n    '20150530132219'\n    \"\"\"\n    timestamp = _shell_command(\n        ['/usr/bin/git', 'log', '--pretty=format:%ct', '--quiet', '-1', 'HEAD']\n    )\n    try:\n        timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))\n    except ValueError:\n        return None\n    return timestamp.strftime('%Y%m%d%H%M%S')\n\n\n@lru_cache()\ndef get_git_branch():\n    \"\"\"Returns the current git branch.\n\n    >>> get_git_branch()\n    'feature/proper_version'\n    \"\"\"\n    branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q',\n                             'HEAD'])\n    if not branch:\n        return None\n    return \"/\".join(branch.strip().split(\"/\")[2:])\n\n\n@lru_cache()\ndef get_git_hash():\n    \"\"\"Returns the current git commit hash or None.\n\n    >>> get_git_hash()\n    'ad768e8'\n    \"\"\"\n    git_hash = _shell_command(\n        ['/usr/bin/git', 'rev-parse', '--verify', '--short', 'HEAD']\n    )\n    if git_hash:\n        return git_hash.strip()\n    return None\n\n\nif __name__ == \"__main__\":\n    from sys import argv\n    if len(argv) == 2:\n        if argv[1] == \"main\":\n            print(get_main_version())\n        elif argv[1] == \"major_minor\":\n            print(get_major_minor_version())\n        elif argv[1] == \"docs\":\n            print(get_docs_version())\n    else:\n        print(get_version())\n\n\ndef is_prerelease(version=None):\n    \"\"\"Is this a final release or not\"\"\"\n\n    return _get_candidate(get_complete_version(version)) != 'final'\n", "path": "pootle/core/utils/version.py"}]}