/hgconf/webconf_qt.py
Python | 85 lines | 72 code | 11 blank | 2 comment | 12 complexity | 972a38f53c7722a3b5bf65a6b35b0f14 MD5 | raw file
- # Webconf dialog (Qt)
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from ui_webconf import Ui_WebConfDialog
- from mercurial import util
- import os
- import iniparse
- class WebConfDialogQt(QDialog):
- '''Simple dialog for accepting a username and scope'''
- def __init__(self, hgui, repo):
- QDialog.__init__(self)
- self.ui = Ui_WebConfDialog()
- self.ui.setupUi(self)
- name = os.path.basename(repo.root)
- self.ui.nameLineEdit.setText(hgui.config("web", "name", name))
- self.ui.descLineEdit.setText(hgui.config("web", "description", "unknown"))
- self.ui.contactLineEdit.setText(hgui.config("web", "contact", "unknown"))
- style = hgui.config("web", "style", "default")
- if style == "default":
- self.ui.styleComboBox.setCurrentIndex(0)
- elif style == "gitweb":
- self.ui.styleComboBox.setCurrentIndex(1)
- elif style == "old":
- self.ui.styleComboBox.setCurrentIndex(2)
- allowarchive = hgui.config("web", "allow_archive", "")
- list = allowarchive.split(', ')
- allowbz2 = "bz2" in list
- allowgz = "gz" in list
- allowzip = "zip" in list
- self.ui.bzip2CheckBox.setChecked(allowbz2)
- self.ui.gzipCheckBox.setChecked(allowgz)
- self.ui.zipCheckBox.setChecked(allowzip)
- self.ui.pushSSLCheckBox.setChecked(hgui.configbool("web", "push_ssl", True))
- self.ui.pushAllowLineEdit.setText(hgui.config("web", "allow_push", ""))
- self.ui.denyPushLineEdit.setText(hgui.config("web", "deny_push", ""))
- self.hgui = hgui
- self.repo = repo
- def accept(self):
- fn = os.sep.join([self.repo.root, '.hg', 'hgrc'])
- if not os.path.exists(fn):
- 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 'web' not in list(ini):
- ini.new_namespace('web')
- ini.web.name = str(self.ui.nameLineEdit.text())
- ini.web.description = str(self.ui.descLineEdit.text())
- ini.web.contact = str(self.ui.contactLineEdit.text())
- archivelist = []
- if self.ui.bzip2CheckBox.isChecked(): archivelist.append('bz2')
- if self.ui.gzipCheckBox.isChecked(): archivelist.append('gz')
- if self.ui.zipCheckBox.isChecked(): archivelist.append('zip')
- ini.web.allow_archive = '.'.join(archivelist)
- if self.ui.pushSSLCheckBox.isChecked():
- ini.web.push_ssl = 'true'
- else:
- ini.web.push_ssl = 'false'
- ini.web.allow_push = str(self.ui.pushAllowLineEdit.text())
- ini.web.deny_push = str(self.ui.denyPushLineEdit.text())
- if self.ui.styleComboBox.currentIndex() == 0:
- ini.web.style = 'default'
- elif self.ui.styleComboBox.currentIndex() == 1:
- ini.web.style = 'gitweb'
- elif self.ui.styleComboBox.currentIndex() == 2:
- ini.web.style = 'old'
- f = open(fn, "w")
- f.write(str(ini))
- f.close()
- QDialog.accept(self)