Indefero

Indefero Commit Details


Date:2010-08-28 18:10:08 (14 years 3 months ago)
Author:Thomas Keller
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:af3df142d409a6d51c1ab9a339952ace67c135f3
Parents: f2a9518b5cea049007701300f723fd874b1aca7a
Message:First attempt on a monotone plugin which creates a new database upon project creation and adds the new server to the running usher instance. If everything goes well, the usher instance is told to reload its configuration, so the new server / database is picked up and started automatically.

Changes:

File differences

src/IDF/Plugin/SyncMonotone.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 CĂ©ondo Ltd and contributors.
#
# InDefero 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.
#
# InDefero 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 St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* This classes is a plugin which allows to synchronise access rights
* between indefero and monotone usher setups.
*/
class IDF_Plugin_SyncMonotone
{
/**
* Entry point of the plugin.
*/
static public function entry($signal, &$params)
{
$plug = new IDF_Plugin_SyncMonotone();
switch ($signal) {
case 'IDF_Project::created':
$plug->processMonotoneCreate($params['project']);
break;
}
}
/**
* Run mtn init command to create the corresponding monotone
* repository and add the database to the configured usher instance
*
* @param IDF_Project
*/
function processMonotoneCreate($project)
{
if ($project->getConf()->getVal('scm') != 'mtn') {
return;
}
$repotempl = Pluf::f('mtn_repositories', false);
if ($repotempl === false) {
throw new IDF_Scm_Exception(
'"mtn_repositories" must be defined in your configuration file.'
);
}
$usher_config = Pluf::f('mtn_usher', array());
if (!array_key_exists('rcfile', $usher_config) ||
!is_writable($usher_config['rcfile'])) {
throw new IDF_Scm_Exception(
'"rcfile" in "mtn_usher" does not exist or is not writable.'
);
}
$shortname = $project->shortname;
$dbfile = sprintf($repotempl, $shortname);
if (file_exists($dbfile)) {
throw new IDF_Scm_Exception(sprintf(
__('The repository %s already exists.'), $dbfile
));
}
$return = 0;
$output = array();
$cmd = sprintf(
Pluf::f('mtn_path', 'mtn').' db init -d %s',
escapeshellarg($dbfile)
);
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$ll = exec($cmd, $output, $return);
if ($return != 0) {
throw new IDF_Scm_Exception(sprintf(
__('Could not create repository %s - please check '.
'your error log for details.'),
$dbfile
));
}
$usher_rc = file_get_contents($usher_config['rcfile']);
$parsed_config = array();
try {
$parsed_config = IDF_Scm_Monotone_BasicIO::parse($usher_rc);
}
catch (Exception $e) {
throw new IDF_Scm_Exception(sprintf(
__('Could not parse usher configuration in "%s": %s'),
$usher_config['rcfile'], $e->getMessage()
));
}
// ensure we haven't configured a server with this name already
foreach ($parsed_config as $stanzas)
{
foreach ($stanzas as $stanza_line)
{
if ($stanza_line['key'] == 'server' &&
$stanza_line['values'][0] == $shortname)
{
throw new IDF_Scm_Exception(sprintf(
__('usher configuration already contains a server '.
'entry named "%s"'),
$shortname
));
}
}
}
$new_server = array(
array('key' => 'server', 'values' => array($shortname)),
array('key' => 'local', 'values' => array('-d', $dbfile)),
);
$parsed_config[] = $new_server;
$usher_rc = IDF_Scm_Monotone_BasicIO::compile($parsed_config);
// FIXME: more sanity - what happens on failing writes?
$fp = fopen($usher_config['rcfile'], 'w');
fwrite($fp, $usher_rc);
fclose($fp);
IDF_Scm_Monotone_Usher::reload();
}
}
src/IDF/conf/idf.php-dist
147147
148148
149149
150
150
151
152
151153
152154
153
154
155
156
155
156
157
158
159
157160
158161
159162
#
# 'host' and 'port' must be set to the specific bits from usher's
# configured 'adminaddr', 'user' and 'pass' must match the values set for
# the configured 'userpass' combination
# the configured 'userpass' combination. The 'rcfile' variable must point
# to the full (writable) path of the usher configuration file which gets
# updated when new projects are added
#
#$cfg['mtn_usher'] = array(
# 'host' => 'localhost',
# 'port' => 12345,
# 'user' => 'admin',
# 'pass' => 'admin',
# 'host' => 'localhost',
# 'port' => 12345,
# 'user' => 'admin',
# 'pass' => 'admin',
# 'rcfile' => '/path/to/usher.conf',
#);
#
src/IDF/relations.php
4949
5050
5151
52
52
5353
54
54
5555
56
56
5757
58
58
5959
60
60
6161
6262
6363
6464
65
65
6666
67
67
6868
69
69
7070
71
71
7272
7373
7474
7575
76
76
7777
78
78
7979
80
80
8181
82
82
8383
84
84
8585
8686
8787
88
89
90
91
8892
89
93
9094
9195
9296
93
94
97
98
9599
96
97
100
101
98102
99103
# -- Standard plugins, they will run only if configured --
#
# Subversion synchronization
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
array('IDF_Plugin_SyncSvn', 'entry'));
Pluf_Signal::connect('IDF_Project::created',
Pluf_Signal::connect('IDF_Project::created',
array('IDF_Plugin_SyncSvn', 'entry'));
Pluf_Signal::connect('Pluf_User::passwordUpdated',
Pluf_Signal::connect('Pluf_User::passwordUpdated',
array('IDF_Plugin_SyncSvn', 'entry'));
Pluf_Signal::connect('IDF_Project::preDelete',
Pluf_Signal::connect('IDF_Project::preDelete',
array('IDF_Plugin_SyncSvn', 'entry'));
Pluf_Signal::connect('svnpostcommit.php::run',
Pluf_Signal::connect('svnpostcommit.php::run',
array('IDF_Plugin_SyncSvn', 'entry'));
#
# Mercurial synchronization
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
array('IDF_Plugin_SyncMercurial', 'entry'));
Pluf_Signal::connect('IDF_Project::created',
Pluf_Signal::connect('IDF_Project::created',
array('IDF_Plugin_SyncMercurial', 'entry'));
Pluf_Signal::connect('Pluf_User::passwordUpdated',
Pluf_Signal::connect('Pluf_User::passwordUpdated',
array('IDF_Plugin_SyncMercurial', 'entry'));
Pluf_Signal::connect('hgchangegroup.php::run',
Pluf_Signal::connect('hgchangegroup.php::run',
array('IDF_Plugin_SyncMercurial', 'entry'));
#
# Git synchronization
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
array('IDF_Plugin_SyncGit', 'entry'));
Pluf_Signal::connect('IDF_Key::postSave',
Pluf_Signal::connect('IDF_Key::postSave',
array('IDF_Plugin_SyncGit', 'entry'));
Pluf_Signal::connect('IDF_Project::created',
Pluf_Signal::connect('IDF_Project::created',
array('IDF_Plugin_SyncGit', 'entry'));
Pluf_Signal::connect('IDF_Key::preDelete',
Pluf_Signal::connect('IDF_Key::preDelete',
array('IDF_Plugin_SyncGit', 'entry'));
Pluf_Signal::connect('gitpostupdate.php::run',
Pluf_Signal::connect('gitpostupdate.php::run',
array('IDF_Plugin_SyncGit', 'entry'));
#
# monotone synchronization
Pluf_Signal::connect('IDF_Project::created',
array('IDF_Plugin_SyncMonotone', 'entry'));
#
# -- Processing of the webhook queue --
Pluf_Signal::connect('queuecron.php::run',
Pluf_Signal::connect('queuecron.php::run',
array('IDF_Queue', 'process'));
#
# Processing of a given webhook, the hook can be configured
# directly in the configuration file if a different solution
# Processing of a given webhook, the hook can be configured
# directly in the configuration file if a different solution
# is required.
Pluf_Signal::connect('IDF_Queue::processItem',
Pluf::f('idf_hook_process_item',
Pluf_Signal::connect('IDF_Queue::processItem',
Pluf::f('idf_hook_process_item',
array('IDF_Webhook', 'process')));
return $m;

Archive Download the corresponding diff file

Page rendered in 0.09075s using 13 queries.