Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

preferences and admin except repository settings

  • Loading branch information...
commit 3d4e509c5b4e922648f168c9896f91a73ea163c7 1 parent 2cc723c
Christophe Drevet authored Christophe Drevet committed
1  tracgitosis/__init__.py
View
@@ -1,2 +1,3 @@
#
from tracgitosisprefs import *
+from tracgitosisadmin import *
40 tracgitosis/templates/admin_tracgitosis_admin.html
View
@@ -0,0 +1,40 @@
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+ <xi:include href="admin.html" />
+ <head>
+ <title>Gitosis Admin Repository Settings</title>
+ </head>
+
+ <body>
+ <h2>Gitosis Admin Repository Settings</h2>
+
+ <form class="mod" id="modbasic" method="post" action="">
+ <fieldset>
+ <legend>gitosis-admin Repository</legend>
+ <div class="field">
+ <label>Admin Repository name:<br />
+ <input type="text" name="admin_repo" value="${admin.admin_repo}" />
+ </label>
+ </div>
+ <div class="field">
+ <label>User:<br />
+ <input type="text" name="user" value="${admin.user}" />
+ </label>
+ </div>
+ <div class="field">
+ <label>Server:<br />
+ <input type="text" name="server" size="48" value="${admin.server}" />
+ </label>
+ </div>
+ </fieldset>
+ <div class="buttons">
+ <input type="submit" value="Apply changes"/>
+ </div>
+ </form>
+ </body>
+
+</html>
35 tracgitosis/templates/admin_tracgitosis_repo.html
View
@@ -0,0 +1,35 @@
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+ <xi:include href="admin.html" />
+ <head>
+ <title>Gitosis Repository Settings</title>
+ </head>
+
+ <body>
+ <h2>Gitosis Repository Settings</h2>
+
+ <form class="mod" id="modbasic" method="post" action="">
+ <fieldset>
+ <legend>gitweb</legend>
+ <div class="field">
+ <label>Enable gitweb:
+ <input type="checkbox" name="gitweb" value="enabled" checked="${repo.gitweb or None}" />
+ </label>
+ </div>
+ <div class="field">
+ <label>Description:<br />
+ <input type="text" name="description" size="48" value="${repo.description}" />
+ </label>
+ </div>
+ </fieldset>
+ <div class="buttons">
+ <input type="submit" value="Apply changes"/>
+ </div>
+ </form>
+ </body>
+
+</html>
61 tracgitosis/tracgitosisadmin.py
View
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+
+from trac.config import PathOption
+from trac.admin.web_ui import *
+from trac.util.translation import _
+
+def _save_config(config, req, log):
+ """Try to save the config, and display either a success notice or a
+ failure warning.
+ """
+ try:
+ config.save()
+ add_notice(req, _('Your changes have been saved.'))
+ except Exception, e:
+ log.error('Error writing to trac.ini: %s', exception_to_unicode(e))
+ add_warning(req, _('Error writing to trac.ini, make sure it is '
+ 'writable by the web server. Your changes have '
+ 'not been saved.'))
+
+#def gitosis_set():
+
+class TracGitosisAdminPanel(Component):
+ implements(IAdminPanelProvider)
+
+ def get_admin_panels(self, req):
+ if 'TRAC_ADMIN' in req.perm:
+ yield ('tracgitosis', _('Trac Gitosis'), 'adminsettings', _('Admin Settings'))
+
+ def render_admin_panel(self, req, cat, page, path_info):
+ req.perm.require('TRAC_ADMIN')
+ if req.method == 'POST':
+ for option in ('admin_repo', 'user', 'server'):
+ self.config.set('tracgitosis', option, req.args.get(option))
+ _save_config(self.config, req, self.log)
+ req.redirect(req.href.admin(cat, page))
+ data = {}
+ for option in ('admin_repo', 'user', 'server'):
+ data[option] = self.config.get('tracgitosis', option)
+ return 'admin_tracgitosis_admin.html', {'admin': data}
+
+
+class TracGitosisAdminRepoPanel(Component):
+ implements(IAdminPanelProvider)
+
+ def get_admin_panels(self, req):
+ if 'TRAC_ADMIN' in req.perm:
+ yield ('tracgitosis', _('Trac Gitosis'), 'reposettings', _('Repository Settings'))
+
+ def render_admin_panel(self, req, cat, page, path_info):
+ req.perm.require('TRAC_ADMIN')
+ #if req.method == 'POST':
+ # for option in ('gitweb', 'description'):
+ # self.config.set('project', option, req.args.get(option))
+ # _save_config(self.config, req, self.log)
+ # req.redirect(req.href.admin(cat, page))
+ data = {
+ 'gitweb': True,
+ 'description': 'description'
+ }
+ return 'admin_tracgitosis_repo.html', {'repo': data}
+
89 tracgitosis/tracgitosisprefs.py
View
@@ -9,6 +9,7 @@
from trac.prefs.api import IPreferencePanelProvider
from trac.web.chrome import ITemplateProvider, add_notice, add_warning
from trac.util.translation import _
+from trac.config import Option
from subprocess import Popen, PIPE
import os
@@ -17,7 +18,22 @@ class TracGitosisPrefs(Component):
implements(IPreferencePanelProvider, ITemplateProvider)
- admrepo = 'gitosis-admin'
+
+ admrepo = Option(section='tracgitosis',
+ name='admin_repo',
+ default='gitosis-admin',
+ doc='gitosis-admin repository name')
+
+ gitosis_user = Option(section='tracgitosis',
+ name='user',
+ default='git',
+ doc='gitosis user name')
+
+ gitosis_server = Option(section='tracgitosis',
+ name='server',
+ default='localhost',
+ doc='gitosis server name')
+
### methods for IPreferencePanelProvider
@@ -36,28 +52,52 @@ def render_preference_panel(self, req, panel):
where `template` is the name of the template to use and `data` is the
data to be passed to the template.
"""
- print req
if req.method == 'POST':
- self.setsshkey(req)
+ self.setsshkey(req, req.session.sid, req.args.get('sshkey', '').strip())
req.redirect(req.href.prefs(panel or None))
- print '<pre>'+str(self)+'</pre>'
- status, message = self.init_admin()
+ status, message = self.init_admin(req)
data = {}
if status != 0:
message = 'return code: '+str(status)+'\nmessage:\n'+message
- data['message'] = message
- sshkey = self.getsshkey(req)
+ add_warning(req, _(message))
+ sshkey = self.getsshkey(req, req.session.sid)
data['username'] = req.session.sid
data['sshkey'] = sshkey
return 'prefs_tracgitosis.html', data
- def getsshkey(self, req):
+ def get_templates_dirs(self):
+ from pkg_resources import resource_filename
+ return [resource_filename(__name__, 'templates')]
+
+ def init_admin(self, req):
+ """ Initialisation du dépôt d'admin.
+
+ """
+ # on initialise le dépôt git s'il n'existe pas
+ status = 0
+ stdout = ''
+ stderr = ''
+ message = ''
+ if not os.path.exists(self.env.path+'/'+self.admrepo):
+ self.log.debug('cloning '+self.admrepo+' on '+self.gitosis_server+' with user '+self.gitosis_user)
+ cmd = ['git', 'clone', self.gitosis_user+'@'+self.gitosis_server+':'+self.admrepo]
+ proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=self.env.path)
+ stdout, stderr = proc.communicate()
+ status = proc.returncode
+ if status == 0:
+ message = stdout
+ else:
+ add_warning(req, _('Error while cloning gitosis-admin repository. Please check your settings and/or passphrase free connection to this repository for the user running trac (in most cases, the web server user)'))
+ message = stderr
+ return status, message
+
+ def getsshkey(self, req, username):
""" Read current ssh public key.
This function read the file keydir/<user>.pub in the local gitosis-admin working tree.
"""
- keyfile = self.env.path+'/'+self.admrepo+'/keydir/'+req.session.sid+'.pub'
+ keyfile = self.env.path+'/'+self.admrepo+'/keydir/'+username+'.pub'
if os.path.exists(keyfile):
f = open(keyfile, 'r')
pubkey = f.readline()
@@ -66,13 +106,13 @@ def getsshkey(self, req):
pubkey = ''
return pubkey
- def setsshkey(self, req):
+ def setsshkey(self, req, username, key):
""" Set ssh public key.
This function write the file keydir/<user>.pub in the local gitosis-admin working tree
with the given public key.
"""
- key = req.args.get('sshkey', '').strip()
+ #key = req.args.get('sshkey', '').strip()
# On vérifie si la clé a bien une syntaxe normale
import re
status = 0
@@ -80,7 +120,7 @@ def setsshkey(self, req):
status = 1
message = 'malformed key (must begin with \'ssh-rsa \' followed by a BASE64 encoded chain)'
if status == 0:
- relkeyfile = 'keydir/'+req.session.sid+'.pub'
+ relkeyfile = 'keydir/'+username+'.pub'
keyfile = self.env.path+'/'+self.admrepo+'/'+relkeyfile
f = open(keyfile, 'w')
f.write(key+'\n')
@@ -91,12 +131,8 @@ def setsshkey(self, req):
else:
add_warning(req, _('Error while saving your preferences. Message: '+message))
- def get_templates_dirs(self):
- from pkg_resources import resource_filename
- return [resource_filename(__name__, 'templates')]
-
def commitkey(self, file):
- """ Commit new SSH public key.
+ """ Commit and push a file
"""
stdout = ''
@@ -136,22 +172,3 @@ def commitkey(self, file):
message = stderr
return status, message
- def init_admin(self):
- """ Initialisation ou mise à jour du dépôt d'admin.
-
- """
- # on initialise le dépôt git s'il n'existe pas
- status = 0
- stdout = ''
- stderr = ''
- message = ''
- if not os.path.exists(self.env.path+'/'+self.admrepo):
- cmd = ['git', 'clone', 'gitosis:'+self.admrepo]
- proc = Popen(cmd, shell=False, stdin=None, stdout=PIPE, stderr=PIPE, cwd=self.env.path)
- stdout, stderr = proc.communicate()
- status = proc.returncode
- if status == 0:
- message = stdout
- else:
- message = stderr
- return status, message
Please sign in to comment.
Something went wrong with that request. Please try again.