hgconfig /hgconf/uname_qt.py

Language Python Lines 97
MD5 Hash 2f7942dc26102824f7df734680bec52f Estimated Cost $1,880 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Username dialog (Qt)
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from mercurial import util
from ui_uname import Ui_Dialog
import os, socket
import iniparse

class UsernameDialogQt(QDialog):
    '''Simple dialog for accepting a username and scope'''
    def __init__(self, hgui, repo, tolocal):
        QDialog.__init__(self)
        self.hgui = hgui
        self.repo = repo
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        # Get current username or decent default guess
        try:
            user = os.environ.get("HGUSER") or \
                self.hgui.config("ui", "username") or \
                os.environ.get("EMAIL") or \
                '%s@%s' % (util.getuser(), socket.getfqdn())
        except KeyError:
            user = ''

        # If no localrepo is provided, disable that option
        if not repo:
            self.ui.localRadioButton.setEnabled(False)
        elif tolocal:
            self.ui.localRadioButton.setChecked(True)

        settings = QSettings('vcs', 'hgconfig')
        settings.beginGroup('uname')
        self.unamehist = []
        size = settings.beginReadArray('history')
        for i in xrange(0, size):
            settings.setArrayIndex(i)
            self.unamehist.append(settings.value('text').toString())
        settings.endArray()
        settings.endGroup()

        if user and user not in self.unamehist:
            self.unamehist.append(user)

        for name in self.unamehist:
            self.ui.usernameComboBox.insertItem(0, name)
        self.ui.usernameComboBox.setCurrentIndex(0)

    def accept(self):
        local = self.ui.localRadioButton.isChecked()
        username = str(self.ui.usernameComboBox.currentText())

        if username in self.unamehist:
            self.unamehist.remove(username)
        self.unamehist.append(username)

        settings = QSettings('vcs', 'hgconfig')
        settings.beginGroup('uname')
        settings.beginWriteArray('history')
        for i, name in enumerate(self.unamehist):
            settings.setArrayIndex(i)
            settings.setValue("text", QVariant(name))
        settings.endArray()
        settings.endGroup()
        settings.sync()

        if local:
            path = [os.sep.join([self.repo.root, '.hg', 'hgrc'])]
        else:
            path = util.user_rcpath()

        for fn in path:
            if os.path.exists(fn):
                break
        else:
            fn = path[0]
            self.hgui.warn("Creating %s\n" % fn)
            f = open(fn, "w")
            f.write("# Generated by hg-config\n")
            f.close()

        ini = iniparse.INIConfig(file(fn))
        if 'ui' not in list(ini):
            ini.new_namespace('ui')
        if 'hooks' not in list(ini):
            ini.new_namespace('hooks')
        ini['ui']['username'] = username
        ini['hooks']['precommit.username'] = ''
        f = open(fn, "w")
        f.write(str(ini))
        f.close()

        # set username for this commit
        self.hgui.setconfig("ui", "username", username)
        QDialog.accept(self)
Back to Top