# HG changeset patch # User Marcin Kuzminski # Date 1281053002 -7200 # Node ID b27d32cb315793e9cec63d8ff2f3f70616b0e103 # Parent a9814a642e11092b243ca01721254a04633a0ffc Implemented hooks system, Added repo size hook, and active flag on ui settings in the database to able to toggle them. diff -r a9814a642e11 -r b27d32cb3157 README.rst --- a/README.rst Fri Aug 06 01:52:17 2010 +0200 +++ b/README.rst Fri Aug 06 02:03:22 2010 +0200 @@ -9,17 +9,18 @@ - has it's own middleware to handle mercurial protocol request each request can be logged and authenticated + threaded performance unlikely to hgweb - full permissions per project read/write/admin access even on mercurial request -- mako templates let's you cusmotize look and feel of appplication. +- mako templates let's you cusmotize look and feel of application. - diffs annotations and source code all colored by pygments. - mercurial branch graph and yui-flot powered graphs - admin interface for performing user/permission managments as well as repository - managment. Additionall settings for mercurial web, (hooks editable from admin - panel !) + managment. +- Additionall settings for mercurial web, (hooks editable from admin + panel !) also paths,archive,remote messages - backup scripts can do backup of whole app and send it over scp to desired location - setup project descriptions and info inside built in db for easy, non file-system operations - added cache with invalidation on push/repo managment for high performance and - always upto date data. + always upto date data. - rss /atom feed customizable - based on pylons 1.0 / sqlalchemy 0.6 @@ -28,10 +29,12 @@ - code review based on hg-review (when it's stable) - git support (when vcs can handle it) - other cools stuff that i can figure out +- full text search of source codes - manage hg ui() per repo, add hooks settings, per repo, and not globally .. note:: - This software is still in beta mode. I don't guarantee that it'll work. + This software is still in beta mode. + I don't guarantee that it'll work correctly. ------------- diff -r a9814a642e11 -r b27d32cb3157 pylons_app/lib/db_manage.py --- a/pylons_app/lib/db_manage.py Fri Aug 06 01:52:17 2010 +0200 +++ b/pylons_app/lib/db_manage.py Fri Aug 06 02:03:22 2010 +0200 @@ -90,11 +90,16 @@ log.error('You entered wrong path') sys.exit() - hooks = HgAppUi() - hooks.ui_section = 'hooks' - hooks.ui_key = 'changegroup' - hooks.ui_value = 'hg update >&2' + hooks1 = HgAppUi() + hooks1.ui_section = 'hooks' + hooks1.ui_key = 'changegroup.update' + hooks1.ui_value = 'hg update >&2' + hooks2 = HgAppUi() + hooks2.ui_section = 'hooks' + hooks2.ui_key = 'changegroup.repo_size' + hooks2.ui_value = 'python:pylons_app.lib.hooks.repo_size' + web1 = HgAppUi() web1.ui_section = 'web' web1.ui_key = 'push_ssl' @@ -131,7 +136,8 @@ hgsettings2.app_settings_value = 'hg-app' try: - #self.sa.add(hooks) + self.sa.add(hooks1) + self.sa.add(hooks2) self.sa.add(web1) self.sa.add(web2) self.sa.add(web3) diff -r a9814a642e11 -r b27d32cb3157 pylons_app/lib/hooks.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/lib/hooks.py Fri Aug 06 02:03:22 2010 +0200 @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# encoding: utf-8 +# custom hooks for application +# Copyright (C) 2009-2010 Marcin Kuzminski +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 +# of the License or (at your opinion) any later version of the license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +""" +Created on Aug 6, 2010 + +@author: marcink +""" + +import sys +import os +from pylons_app.lib import helpers as h + +def repo_size(ui, repo, hooktype=None, **kwargs): + + if hooktype != 'changegroup': + return False + + size_hg, size_root = 0, 0 + for path, dirs, files in os.walk(repo.root): + if path.find('.hg') != -1: + for f in files: + size_hg += os.path.getsize(os.path.join(path, f)) + else: + for f in files: + size_root += os.path.getsize(os.path.join(path, f)) + + size_hg_f = h.format_byte_size(size_hg) + size_root_f = h.format_byte_size(size_root) + size_total_f = h.format_byte_size(size_root + size_hg) + sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \ + % (size_hg_f, size_root_f, size_total_f)) diff -r a9814a642e11 -r b27d32cb3157 pylons_app/lib/middleware/simplehg.py --- a/pylons_app/lib/middleware/simplehg.py Fri Aug 06 01:52:17 2010 +0200 +++ b/pylons_app/lib/middleware/simplehg.py Fri Aug 06 02:03:22 2010 +0200 @@ -17,6 +17,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +""" +Created on 2010-04-28 + +@author: marcink +SimpleHG middleware for handling mercurial protocol request (push/clone etc.) +It's implemented with basic auth function +""" from datetime import datetime from itertools import chain from mercurial.error import RepoError @@ -35,14 +42,6 @@ import os import pylons_app.lib.helpers as h import traceback - -""" -Created on 2010-04-28 - -@author: marcink -SimpleHG middleware for handling mercurial protocol request (push/clone etc.) -It's implemented with basic auth function -""" log = logging.getLogger(__name__) @@ -163,17 +162,6 @@ def __get_user(self, username): return get_user_cached(username) - - - def __get_size(self, repo_path, content_size): - size = int(content_size) - for path, dirs, files in os.walk(repo_path): - if path.find('.hg') == -1: - for f in files: - size += os.path.getsize(os.path.join(path, f)) - return size - return h.format_byte_size(size) - def __get_action(self, environ): """ Maps mercurial request commands into a pull or push command. diff -r a9814a642e11 -r b27d32cb3157 pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py Fri Aug 06 01:52:17 2010 +0200 +++ b/pylons_app/lib/utils.py Fri Aug 06 02:03:22 2010 +0200 @@ -169,8 +169,9 @@ elif read_from == 'db': hg_ui = get_hg_ui_cached() for ui_ in hg_ui: - log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value) - baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) + if ui_.ui_active: + log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value) + baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) return baseui diff -r a9814a642e11 -r b27d32cb3157 pylons_app/model/db.py --- a/pylons_app/model/db.py Fri Aug 06 01:52:17 2010 +0200 +++ b/pylons_app/model/db.py Fri Aug 06 02:03:22 2010 +0200 @@ -17,7 +17,9 @@ ui_section = Column("ui_section", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) ui_key = Column("ui_key", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) ui_value = Column("ui_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) - + ui_active = Column("ui_active", BOOLEAN(), nullable=True, unique=None, default=True) + + class User(Base): __tablename__ = 'users' __table_args__ = {'useexisting':True}