Mercurial > kallithea
diff rhodecode/lib/__init__.py @ 1541:70e646b2806a beta
fixes rhodecode upgrade problem that caused setuptool to crash on importing sqlalchemy models
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 11 Oct 2011 02:14:42 +0200 |
parents | 87ec80c280bb |
children | 752b0a7b7679 a9888895b60d |
line wrap: on
line diff
--- a/rhodecode/lib/__init__.py Tue Oct 11 01:08:23 2011 +0200 +++ b/rhodecode/lib/__init__.py Tue Oct 11 02:14:42 2011 +0200 @@ -23,6 +23,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os + def __get_lem(): from pygments import lexers from string import lower @@ -379,3 +381,24 @@ from rhodecode.lib.utils import EmptyChangeset cs = EmptyChangeset(requested_revision=rev) return cs + + +def get_current_revision(): + """ + Returns tuple of (number, id) from repository containing this package + or None if repository could not be found. + """ + + try: + from vcs import get_repo + from vcs.utils.helpers import get_scm + from vcs.exceptions import RepositoryError, VCSError + repopath = os.path.join(os.path.dirname(__file__), '..', '..') + scm = get_scm(repopath)[0] + repo = get_repo(path=repopath, alias=scm) + tip = repo.get_changeset() + return (tip.revision, tip.short_id) + except (ImportError, RepositoryError, VCSError), err: + print ("Cannot retrieve rhodecode's revision. Original error " + "was: %s" % err) + return None