PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/hgconf/webconf_gtk.py

https://bitbucket.org/sborho/hgconfig
Python | 115 lines | 96 code | 15 blank | 4 comment | 14 complexity | 4ff99d183900cebeeb3dd4dcf6ed9e82 MD5 | raw file
  1. # Webconf dialog
  2. from mercurial import util
  3. import os
  4. import iniparse
  5. try:
  6. import pygtk
  7. import gtk
  8. import gtk.glade
  9. pygtk.require("2.0")
  10. except:
  11. sys.exit(1)
  12. class WebConfDialogGtk:
  13. '''Simple dialog for accepting a username and scope'''
  14. def __init__(self, hgui, repo):
  15. self.hgui = hgui
  16. self.repo = repo
  17. # Set the Glade file
  18. p = os.path.dirname(os.path.abspath(__file__))
  19. self.gladefile = os.sep.join([p, "webconf_dialog.glade"])
  20. if not os.path.exists(self.gladefile): # MSI path layout
  21. self.gladefile = os.sep.join([p, '..', '..', '..',
  22. 'share', 'hgconf', 'webconf_dialog.glade'])
  23. self.wTree = gtk.glade.XML(self.gladefile)
  24. # Create our dictionary and connect it
  25. dic = { "on_okButton_clicked" : self.okButton_clicked,
  26. "on_cancelButton_clicked" : gtk.main_quit,
  27. "on_dialog_destroy" : gtk.main_quit }
  28. self.wTree.signal_autoconnect(dic)
  29. self.styleComboBox = self.wTree.get_widget('styleComboBox')
  30. self.styleTextEntry = self.styleComboBox.get_child()
  31. self.contactTextEntry = self.wTree.get_widget('contactTextEntry')
  32. self.descTextEntry = self.wTree.get_widget('descTextEntry')
  33. self.nameTextEntry = self.wTree.get_widget('nameTextEntry')
  34. self.zipCheckBox = self.wTree.get_widget('allowzipCheckBox')
  35. self.gzipCheckBox = self.wTree.get_widget('allowgzipCheckBox')
  36. self.bzip2CheckBox = self.wTree.get_widget('allowbzip2CheckBox')
  37. self.pushSSLCheckBox = self.wTree.get_widget('pushsslCheckBox')
  38. self.denyTextEntry = self.wTree.get_widget('denyTextEntry')
  39. self.allowTextEntry = self.wTree.get_widget('allowTextEntry')
  40. name = os.path.basename(repo.root)
  41. self.nameTextEntry.set_text(hgui.config("web", "name", name))
  42. self.descTextEntry.set_text(hgui.config("web", "description", "unknown"))
  43. self.contactTextEntry.set_text(hgui.config("web", "contact", "unknown"))
  44. style = hgui.config("web", "style", "default")
  45. if style == "default":
  46. self.styleComboBox.set_active(0)
  47. elif style == "gitweb":
  48. self.styleComboBox.set_active(1)
  49. elif style == "old":
  50. self.styleComboBox.set_active(2)
  51. allowarchive = hgui.config("web", "allow_archive", "")
  52. list = allowarchive.split(', ')
  53. allowbz2 = "bz2" in list
  54. allowgz = "gz" in list
  55. allowzip = "zip" in list
  56. self.bzip2CheckBox.set_active(allowbz2)
  57. self.gzipCheckBox.set_active(allowgz)
  58. self.zipCheckBox.set_active(allowzip)
  59. self.pushSSLCheckBox.set_active(hgui.configbool("web", "push_ssl", True))
  60. self.allowTextEntry.set_text(hgui.config("web", "allow_push", ""))
  61. self.denyTextEntry.set_text(hgui.config("web", "deny_push", ""))
  62. self.hgui = hgui
  63. self.repo = repo
  64. def okButton_clicked(self, state):
  65. fn = os.sep.join([self.repo.root, '.hg', 'hgrc'])
  66. if not os.path.exists(fn):
  67. self.hgui.warn("Creating %s\n" % fn)
  68. f = open(fn, "w")
  69. f.write("# Generated by hg-config\n")
  70. f.close()
  71. ini = iniparse.INIConfig(file(fn))
  72. if 'web' not in list(ini):
  73. ini.new_namespace('web')
  74. ini.web.name = self.nameTextEntry.get_text()
  75. ini.web.description = self.descTextEntry.get_text()
  76. ini.web.contact = self.contactTextEntry.get_text()
  77. archivelist = []
  78. if self.bzip2CheckBox.get_active(): archivelist.append('bz2')
  79. if self.gzipCheckBox.get_active(): archivelist.append('gz')
  80. if self.zipCheckBox.get_active(): archivelist.append('zip')
  81. ini.web.allow_archive = '.'.join(archivelist)
  82. if self.pushSSLCheckBox.get_active():
  83. ini.web.push_ssl = 'true'
  84. else:
  85. ini.web.push_ssl = 'false'
  86. ini.web.allow_push = self.allowTextEntry.get_text()
  87. ini.web.deny_push = self.denyTextEntry.get_text()
  88. if self.styleComboBox.get_active() == 0:
  89. ini.web.style = 'default'
  90. elif self.styleComboBox.get_active() == 1:
  91. ini.web.style = 'gitweb'
  92. elif self.styleComboBox.get_active() == 2:
  93. ini.web.style = 'old'
  94. f = open(fn, "w")
  95. f.write(str(ini))
  96. f.close()
  97. gtk.main_quit()