~ubuntu-branches/ubuntu/quantal/python-django-compressor/quantal-201208160040

« back to all changes in this revision

Viewing changes to versiontools-1.9.1-py2.7.egg/versiontools/hg_support.py

debian/control: Add 'Provides: ${python:Provides}' to fix package
installation. (LP: #1036907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-"
2
 
# Copyright (C) 2011 enn.io UG (haftungsbeschränkt)
3
 
# Copyright (C) 2011-2012 Linaro Limited
4
 
#
5
 
# Author: Jannis Leidel <jannis@leidel.info>
6
 
# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
7
 
#
8
 
# This file is part of versiontools.
9
 
#
10
 
# versiontools is free software: you can redistribute it and/or modify
11
 
# it under the terms of the GNU Lesser General Public License version 3
12
 
# as published by the Free Software Foundation
13
 
#
14
 
# versiontools is distributed in the hope that it will be useful,
15
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
# GNU General Public License for more details.
18
 
#
19
 
# You should have received a copy of the GNU Lesser General Public License
20
 
# along with versiontools.  If not, see <http://www.gnu.org/licenses/>.
21
 
 
22
 
"""
23
 
.. _hg:
24
 
 
25
 
versiontools.hg_support
26
 
=======================
27
 
 
28
 
Mercurial (Hg) support for versiontools.
29
 
 
30
 
.. note::
31
 
 
32
 
    To work with Mercurial repositories you will need `Mercurial
33
 
    <http://mercurial.selenic.com/>`_. You can install it with pip or from the
34
 
    `mercurial` package on Ubuntu. 
35
 
"""
36
 
import logging
37
 
import sys
38
 
 
39
 
 
40
 
class HgIntegration(object):
41
 
    """
42
 
    Hg integration for versiontools
43
 
    """
44
 
    def __init__(self, repo):
45
 
        tip = repo.changectx('tip')
46
 
        self._revno = tip.rev()
47
 
        try:
48
 
            self._branch_nick = tip.branch()
49
 
        except Exception:
50
 
            self._branch_nick = None
51
 
 
52
 
    @property
53
 
    def revno(self):
54
 
        """
55
 
        Revision number of the branch
56
 
        """
57
 
        return self._revno
58
 
 
59
 
    @property
60
 
    def branch_nick(self):
61
 
        """
62
 
        Nickname of the branch
63
 
 
64
 
        .. versionadded:: 1.0.4
65
 
        """
66
 
        return self._branch_nick
67
 
 
68
 
    @classmethod
69
 
    def from_source_tree(cls, source_tree):
70
 
        """
71
 
        Initialize :class:`~versiontools.hg_support.HgIntegration` by
72
 
        pointing at the source tree.  Any file or directory inside the
73
 
        source tree may be used.
74
 
        """
75
 
        repo = None
76
 
        try:
77
 
            from mercurial.hg import repository
78
 
            from mercurial.ui import ui
79
 
            repo = repository(ui(), source_tree)
80
 
        except Exception:
81
 
            from versiontools import _get_exception_message
82
 
            message = _get_exception_message(*sys.exc_info())
83
 
            logging.debug("Unable to get branch revision because "
84
 
                          "directory %r is not a hg repo. Error: %s",
85
 
                          (source_tree, message))
86
 
        if repo:
87
 
            return cls(repo)