[Fusionforge-commits] r7995 - in trunk/gforge: common/include cronjobs packaging/install plugins/scmbzr/common plugins/scmcpold/common plugins/scmcvs/common
Roland Mas
lolando at libremir.placard.fr.eu.org
Thu Aug 27 15:41:47 CEST 2009
Author: lolando
Date: 2009-08-27 15:41:47 +0200 (Thu, 27 Aug 2009)
New Revision: 7995
Added:
trunk/gforge/cronjobs/gather_scm_stats.php
Modified:
trunk/gforge/common/include/SCMPlugin.class.php
trunk/gforge/cronjobs/create_scm_repos.php
trunk/gforge/packaging/install/common
trunk/gforge/plugins/scmbzr/common/BzrPlugin.class.php
trunk/gforge/plugins/scmcpold/common/CpoldPlugin.class.php
trunk/gforge/plugins/scmcvs/common/CVSPlugin.class.php
Log:
Moved CVS stats gathering into a hook
Modified: trunk/gforge/common/include/SCMPlugin.class.php
===================================================================
--- trunk/gforge/common/include/SCMPlugin.class.php 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/common/include/SCMPlugin.class.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -31,18 +31,25 @@
*/
function SCMPlugin () {
$this->Plugin() ;
+ $this->hooks[] = 'scm_plugin';
$this->hooks[] = 'scm_page';
$this->hooks[] = 'scm_admin_update';
$this->hooks[] = 'scm_admin_page';
$this->hooks[] = 'scm_stats';
- $this->hooks[] = 'scm_createrepo';
- $this->hooks[] = 'scm_plugin';
+ $this->hooks[] = 'scm_create_repo';
+ # Other common hooks that can be enabled per plugin:
+ # scm_generate_snapshots
+ # scm_gather_stats
}
function CallHook ($hookname, $params) {
global $HTML ;
switch ($hookname) {
+ case 'scm_plugin':
+ $scm_plugins=& $params['scm_plugins'];
+ $scm_plugins[]=$this->name;
+ break;
case 'scm_page':
$this->getPage ($params) ;
break ;
@@ -55,13 +62,15 @@
case 'scm_stats':
$this->echoShortStats ($params) ;
break;
- case 'scm_createrepo':
+ case 'scm_create_repo':
$this->createOrUpdateRepo ($params) ;
break;
- case 'scm_plugin':
- $scm_plugins=& $params['scm_plugins'];
- $scm_plugins[]=$this->name;
+ case 'scm_generate_snapshots': // Optional
+ $this->generateSnapshots ($params) ;
break;
+ case 'scm_gather_stats': // Optional
+ $this->gatherStats ($params) ;
+ break;
default:
// Forgot something
}
Modified: trunk/gforge/cronjobs/create_scm_repos.php
===================================================================
--- trunk/gforge/cronjobs/create_scm_repos.php 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/cronjobs/create_scm_repos.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -45,6 +45,12 @@
while ($data = db_fetch_array ($res)) {
$hook_params = array ('group_id' => $data['group_id']) ;
- plugin_hook ('scm_createrepo', $hook_params) ;
+ plugin_hook ('scm_create_repo', $hook_params) ;
}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
?>
Added: trunk/gforge/cronjobs/gather_scm_stats.php
===================================================================
--- trunk/gforge/cronjobs/gather_scm_stats.php (rev 0)
+++ trunk/gforge/cronjobs/gather_scm_stats.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -0,0 +1,60 @@
+#! /usr/bin/php5 -f
+<?php
+/**
+ * FusionForge source control management
+ *
+ * Copyright 2009, Roland Mas
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge 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; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+require_once '/usr/share/gforge/www/env.inc.php';
+require_once $gfwww.'include/squal_pre.php';
+require_once $gfcommon.'include/cron_utils.php';
+
+// Plugins subsystem
+require_once $gfcommon.'include/Plugin.class.php' ;
+require_once $gfcommon.'include/PluginManager.class.php' ;
+
+// SCM-specific plugins subsystem
+require_once $gfcommon.'include/SCMPlugin.class.php' ;
+
+setup_plugin_manager () ;
+
+$res = db_query_params ('SELECT group_id FROM groups WHERE status=$1 AND use_scm=1 ORDER BY group_id DESC',
+ array ('A'));
+if (!$res) {
+ $this->setError('Unable to get list of projects using SCM: '.db_error());
+ return false;
+}
+
+while ($data = db_fetch_array ($res)) {
+ $hook_params = array ('group_id' => $data['group_id'],
+ 'mode' => 'day',
+ 'year' => date ('Y', time () - 43200),
+ 'month' => date ('n', time () - 43200),
+ 'day' => date ('j', time () - 43200)) ;
+ plugin_hook ('scm_gather_stats', $hook_params) ;
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
Property changes on: trunk/gforge/cronjobs/gather_scm_stats.php
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/gforge/packaging/install/common
===================================================================
--- trunk/gforge/packaging/install/common 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/packaging/install/common 2009-08-27 13:41:47 UTC (rev 7995)
@@ -20,4 +20,5 @@
#
common usr/share/gforge/
cronjobs/create_scm_repos.php usr/share/gforge/cronjobs/
+cronjobs/gather_scm_stats.php usr/share/gforge/cronjobs/
locales/* usr/share/locale/
Modified: trunk/gforge/plugins/scmbzr/common/BzrPlugin.class.php
===================================================================
--- trunk/gforge/plugins/scmbzr/common/BzrPlugin.class.php 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/plugins/scmbzr/common/BzrPlugin.class.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -98,7 +98,8 @@
}
if (!$repo_exists) {
- system ("bzr init-repo --no-trees $repo") ;
+ system ("mkdir -p $repo") ;
+ system ("bzr init-repo --no-trees $repo >/dev/null") ;
}
system ("chgrp -R $unix_group $repo") ;
Modified: trunk/gforge/plugins/scmcpold/common/CpoldPlugin.class.php
===================================================================
--- trunk/gforge/plugins/scmcpold/common/CpoldPlugin.class.php 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/plugins/scmcpold/common/CpoldPlugin.class.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -27,6 +27,7 @@
$this->SCMPlugin () ;
$this->name = 'scmcpold';
$this->text = 'CPOLD';
+ $this->hooks[] = 'scm_cpold_do_nothing' ;
require_once $gfconfig.'plugins/scmcpold/config.php' ;
@@ -37,6 +38,18 @@
$this->register () ;
}
+ function CallHook ($hookname, $params) {
+ global $HTML;
+
+ switch ($hookname) {
+ case 'scm_cpold_do_nothing':
+ // Do nothing
+ break;
+ default:
+ parent::CallHook ($hookname, $params) ;
+ }
+ }
+
function getDefaultServer() {
return $this->default_cpold_server ;
}
Modified: trunk/gforge/plugins/scmcvs/common/CVSPlugin.class.php
===================================================================
--- trunk/gforge/plugins/scmcvs/common/CVSPlugin.class.php 2009-08-27 13:41:36 UTC (rev 7994)
+++ trunk/gforge/plugins/scmcvs/common/CVSPlugin.class.php 2009-08-27 13:41:47 UTC (rev 7995)
@@ -28,7 +28,8 @@
$this->SCMPlugin () ;
$this->name = 'scmcvs';
$this->text = 'CVS';
- $this->hooks[] = 'scm_snapshots_and_tarballs' ;
+ $this->hooks[] = 'scm_generate_snapshots' ;
+ $this->hooks[] = 'scm_gather_stats' ;
require_once $GLOBALS['gfconfig'].'plugins/scmcvs/config.php' ;
@@ -38,8 +39,6 @@
} else {
$this->cvs_root = "/cvsroot";
}
- //$this->default_cvs_server = $default_cvs_server ;
- //$this->this_server = $this_server ;
$this->enabled_by_default = $enabled_by_default ;
$this->register () ;
@@ -141,18 +140,6 @@
return $b ;
}
- function CallHook ($hookname, $params) {
- global $HTML;
-
- switch ($hookname) {
- case 'scm_snapshots_and_tarballs':
- $this->generateSnapshots ($params) ;
- break;
- default:
- parent::CallHook ($hookname, $params) ;
- }
- }
-
function echoShortStats ($params) {
$project = $this->checkParams ($params) ;
if (!$project) {
@@ -207,13 +194,146 @@
}
}
+ function gatherStats ($params) {
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
+ }
+
+ if ($params['mode'] == 'day') {
+ db_begin();
+
+ $year = $params ('year') ;
+ $month = $params ('month') ;
+ $day = $params ('day') ;
+ $month_string = sprintf( "%04d%02d", $year, $month );
+ $day_begin = gmmktime( 0, 0, 0, $month, $day, $year);
+ $day_end = $day_begin + 86400;
+
+ $repo = $this->cvs_root . '/' . $project->getUnixName() ;
+ if (!is_dir ($repo) || !is_dir ("$repo/CVSROOT")) {
+ db_rollback () ;
+ return false ;
+ }
+
+ $cvs_co = 0;
+ $cvs_commit = 0;
+ $cvs_add = 0;
+ $usr_commit = array();
+ $usr_add = array();
+
+ $hist_file_path = $repo.'/CVSROOT/history';
+ if (!file_exists($hist_file_path)
+ || !is_readable($hist_file_path)
+ || filesize($hist_file_path) == 0) {
+ db_rollback () ;
+ return false ;
+ }
+
+ $hist_file =& fopen( $hist_file_path, 'r' );
+ if ( ! $hist_file ) {
+ db_rollback () ;
+ return false ;
+ }
+
+ // cleaning stats_cvs_* table for the current day
+ $res = db_query_params ('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
+ array ($month_string,
+ $day,
+ $project->getID())) ;
+ if(!$res) {
+ db_rollback () ;
+ return false ;
+ }
+
+ $res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
+ array ($month_string,
+ $day,
+ $project->getID())) ;
+ if(!$res) {
+ db_rollback () ;
+ return false ;
+ }
+
+
+ // analyzing history file
+ while (!feof($hist_file)) {
+ $hist_line = fgets($hist_file, 1024);
+ if ( preg_match( '/^\s*$/', $hist_line ) ) {
+ continue;
+ }
+ list( $cvstime,$user,$curdir,$module,$rev,$file ) = explode( '|', $hist_line );
+
+ $type = substr($cvstime, 0, 1);
+ $time_parsed = hexdec( substr($cvstime, 1, 8) );
+
+ if ( ($time_parsed > $day_begin) && ($time_parsed < $day_end) ) {
+ if ( $type == 'M' ) {
+ $cvs_commit++;
+ if(!isset($usr_commit[$user])) $usr_commit[$user] = 0;
+ $usr_commit[$user]++;
+ } elseif ( $type == 'A' ) {
+ $cvs_add++;
+ if(!isset($usr_add[$user])) $usr_add[$user] = 0;
+ $usr_add[$user]++;
+ } elseif ( $type == 'O' || $type == 'E' ) {
+ $cvs_co++;
+ // ignoring checkouts on a per-user
+ }
+ } elseif ( $time_parsed > $day_end ) {
+ break;
+ }
+ }
+ fclose( $hist_file );
+
+ // inserting group results in stats_cvs_groups
+ if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+ array ($month_string,
+ $day,
+ $group_id,
+ $cvs_co,
+ $cvs_commit,
+ $cvs_add))) {
+ db_rollback () ;
+ return false ;
+ }
+
+ // building the user list
+ $user_list = array_unique( array_merge( array_keys( $usr_add ), array_keys( $usr_commit ) ) );
+
+ foreach ( $user_list as $user ) {
+ // trying to get user id from user name
+ $user_res = db_query_params ('SELECT user_id FROM users WHERE user_name=$1',
+ array ($user)) ;
+ if ( $user_row = db_fetch_array($user_res) ) {
+ $user_id = $user_row[0];
+ } else {
+ continue;
+ }
+
+ if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+ array ($month_string,
+ $day,
+ $group_id,
+ $user_id,
+ $usr_commit{$user} ? $usr_commit{$user} : 0,
+ $usr_add{$user} ? $usr_add{$user} : 0))) {
+ db_rollback () ;
+ return false ;
+ }
+
+ }
+ }
+ db_commit();
+ }
+
function generateSnapshots ($params) {
$project = $this->checkParams ($params) ;
if (!$project) {
return false ;
}
- $group_name = $project->getUnixName();
+ $group_name = $project->getUnixName() ;
$snapshot = $sys_scm_snapshots_path.'/'.$group_name.'-scm-latest.tar.gz';
$tarball = $sys_scm_tarballs_path.'/'.$group_name.'-scmroot.tar.gz';
More information about the Fusionforge-commits
mailing list