/hgconf/uname.py
Python | 42 lines | 23 code | 4 blank | 15 comment | 6 complexity | 7d2f128758cc8d1158ff73a23aa3ca41 MD5 | raw file
- # 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