/hgconf/webconf_gtk.py
https://bitbucket.org/sborho/hgconfig · Python · 115 lines · 93 code · 18 blank · 4 comment · 15 complexity · 4ff99d183900cebeeb3dd4dcf6ed9e82 MD5 · raw file
- # Webconf dialog
- from mercurial import util
- import os
- import iniparse
- try:
- import pygtk
- import gtk
- import gtk.glade
- pygtk.require("2.0")
- except:
- sys.exit(1)
- class WebConfDialogGtk:
- '''Simple dialog for accepting a username and scope'''
- def __init__(self, hgui, repo):
- self.hgui = hgui
- self.repo = repo
- # Set the Glade file
- p = os.path.dirname(os.path.abspath(__file__))
- self.gladefile = os.sep.join([p, "webconf_dialog.glade"])
- if not os.path.exists(self.gladefile): # MSI path layout
- self.gladefile = os.sep.join([p, '..', '..', '..',
- 'share', 'hgconf', 'webconf_dialog.glade'])
- self.wTree = gtk.glade.XML(self.gladefile)
-
- # Create our dictionary and connect it
- dic = { "on_okButton_clicked" : self.okButton_clicked,
- "on_cancelButton_clicked" : gtk.main_quit,
- "on_dialog_destroy" : gtk.main_quit }
- self.wTree.signal_autoconnect(dic)
- self.styleComboBox = self.wTree.get_widget('styleComboBox')
- self.styleTextEntry = self.styleComboBox.get_child()
- self.contactTextEntry = self.wTree.get_widget('contactTextEntry')
- self.descTextEntry = self.wTree.get_widget('descTextEntry')
- self.nameTextEntry = self.wTree.get_widget('nameTextEntry')
- self.zipCheckBox = self.wTree.get_widget('allowzipCheckBox')
- self.gzipCheckBox = self.wTree.get_widget('allowgzipCheckBox')
- self.bzip2CheckBox = self.wTree.get_widget('allowbzip2CheckBox')
- self.pushSSLCheckBox = self.wTree.get_widget('pushsslCheckBox')
- self.denyTextEntry = self.wTree.get_widget('denyTextEntry')
- self.allowTextEntry = self.wTree.get_widget('allowTextEntry')
- name = os.path.basename(repo.root)
- self.nameTextEntry.set_text(hgui.config("web", "name", name))
- self.descTextEntry.set_text(hgui.config("web", "description", "unknown"))
- self.contactTextEntry.set_text(hgui.config("web", "contact", "unknown"))
- style = hgui.config("web", "style", "default")
- if style == "default":
- self.styleComboBox.set_active(0)
- elif style == "gitweb":
- self.styleComboBox.set_active(1)
- elif style == "old":
- self.styleComboBox.set_active(2)
- allowarchive = hgui.config("web", "allow_archive", "")
- list = allowarchive.split(', ')
- allowbz2 = "bz2" in list
- allowgz = "gz" in list
- allowzip = "zip" in list
- self.bzip2CheckBox.set_active(allowbz2)
- self.gzipCheckBox.set_active(allowgz)
- self.zipCheckBox.set_active(allowzip)
- self.pushSSLCheckBox.set_active(hgui.configbool("web", "push_ssl", True))
- self.allowTextEntry.set_text(hgui.config("web", "allow_push", ""))
- self.denyTextEntry.set_text(hgui.config("web", "deny_push", ""))
- self.hgui = hgui
- self.repo = repo
- def okButton_clicked(self, state):
- 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 = self.nameTextEntry.get_text()
- ini.web.description = self.descTextEntry.get_text()
- ini.web.contact = self.contactTextEntry.get_text()
- archivelist = []
- if self.bzip2CheckBox.get_active(): archivelist.append('bz2')
- if self.gzipCheckBox.get_active(): archivelist.append('gz')
- if self.zipCheckBox.get_active(): archivelist.append('zip')
- ini.web.allow_archive = '.'.join(archivelist)
- if self.pushSSLCheckBox.get_active():
- ini.web.push_ssl = 'true'
- else:
- ini.web.push_ssl = 'false'
- ini.web.allow_push = self.allowTextEntry.get_text()
- ini.web.deny_push = self.denyTextEntry.get_text()
- if self.styleComboBox.get_active() == 0:
- ini.web.style = 'default'
- elif self.styleComboBox.get_active() == 1:
- ini.web.style = 'gitweb'
- elif self.styleComboBox.get_active() == 2:
- ini.web.style = 'old'
- f = open(fn, "w")
- f.write(str(ini))
- f.close()
- gtk.main_quit()