Commits

ejucovy committed 524e69e

start on 'create new repository' feature

Comments (0)

Files changed (3)

trac_gitolite/__init__.py

 from .conf_writer import GitoliteConfWriter
 from .perm_policy import GitolitePermissionPolicy
+from .repo_manager import GitoliteRepositoryManager
 from .user_manager import GitoliteUserManager

trac_gitolite/repo_manager.py

+import pkg_resources
+
+from trac.admin import IAdminPanelProvider
+from trac.core import *
+from trac.config import Option, BoolOption
+from trac.perm import IPermissionRequestor
+from trac.util.translation import _
+from trac.versioncontrol import DbRepositoryProvider
+from trac.web.chrome import ITemplateProvider
+from trac.web.chrome import add_notice, add_warning
+
+from trac_gitolite import utils
+
+class GitoliteRepositoryManager(Component):
+    implements(IPermissionRequestor, IAdminPanelProvider, ITemplateProvider)
+
+    gitolite_admin_reponame = Option('trac-gitolite', 'admin_reponame',
+                                     default="gitolite-admin")
+
+    def read_config(self):
+        repo = self.env.get_repository(reponame=self.gitolite_admin_reponame)
+        node = repo.get_node("conf/gitolite.conf")
+        fp = node.get_content()
+        return utils.read_config(fp)
+    
+    ## IPermissionRequestor methods
+
+    def get_permission_actions(self):
+        return [('VERSIONCONTROL_ADMIN', ['REPOSITORY_CREATE']),
+                'REPOSITORY_CREATE']
+
+    ## IAdminPanelProvider methods
+
+    def get_admin_panels(self, req):
+        if 'REPOSITORY_CREATE' in req.perm:
+            yield ('versioncontrol', _('Version Control'), 'gitolite', 
+                   _('Gitolite Repositories'))
+
+    def render_admin_panel(self, req, category, page, path_info):
+        req.perm.require('REPOSITORY_CREATE')
+
+        if req.method == 'POST':
+
+            req.redirect(req.href.admin(category, page))
+
+        data = {'repos': sorted(self.read_config())}
+        return 'admin_repository_gitolite.html', data
+
+    # ITemplateProvider methods
+
+    def get_htdocs_dirs(self):
+        return []
+
+    def get_templates_dirs(self):
+        return [pkg_resources.resource_filename('trac_gitolite', 'templates')]

trac_gitolite/templates/admin_repository_gitolite.html

+<!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/"
+      xmlns:i18n="http://genshi.edgewall.org/i18n">
+  <xi:include href="admin.html"/>
+  <head>
+    <title>Gitolite Repositories</title>
+  </head>
+
+  <body>
+    <h2>Manage Gitolite Repositories</h2>
+
+    <form enctype="multipart/form-data" class="addnew" method="post" action="">
+      <fieldset>
+	<legend>Create New Repository:</legend>
+	<div class="field">
+	  <label>Name:
+	    <input type="text" name="name" />
+	  </label>
+	</div>
+	<div class="buttons">
+	  <input type="submit" name="add_repo" value="Add" />
+	</div>
+      </fieldset>
+    </form>
+
+    <form method="post" action="">
+
+    <table class="listing">
+      <thead>
+	<tr>
+	  <th class="sel">&nbsp;</th>
+	  <th>Name</th>
+	</tr>
+      </thead>
+      <tbody>
+	<tr py:for="repo in repos">
+	  <td class="sel">
+	  </td>
+	  <td>
+	    $repo
+	  </td>
+	</tr>
+      </tbody>
+    </table>
+
+    <div class="buttons">
+    </div>
+
+    </form>
+  </body>
+
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.