hgconfig /hgconf/uname.py

Language Python Lines 43
MD5 Hash 7d2f128758cc8d1158ff73a23aa3ca41 Estimated Cost $515 (why?)
Repository https://bitbucket.org/sborho/hgconfig View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Username precommit hook

from mercurial import util
import os

def hook(ui, repo, **args):
    """Check if a username is configured.

       This function is intended to run as a precommit hook.

       [hooks]
       precommit.username = python:hgconf.uname.hook

       If a username is found to be configured via an hgrc or
       the HGUSER environment variable, the commit is allowed
       to continue.  Else it launches a GUI dialog to allow the
       user to specify a username
    """
    user = os.environ.get("HGUSER") or ui.config("ui", "username")
    if user is not None:
        return 0

    try:
        # try Qt version first
        import PyQt4.QtGui
        from hgconf.uname_qt import UsernameDialogQt
        app = PyQt4.QtGui.QApplication([])
        dialog = UsernameDialogQt(ui, repo, False)
        dialog.show()
        app.exec_()
    except ImportError:
        # Fallback to GTK version
        import gtk
        from hgconf.uname_gtk import UsernameDialogGtk
        ud = UsernameDialogGtk(ui, repo, False)
        gtk.main()

    user = ui.config("ui", "username")
    if user is None:
        return 1 # Dialog did not set a username, do not allow commit
    else:
        return 0
Back to Top