InDefero

Sign in or create your account | Project List | Help

InDefero Commit Details

Date:2009-06-19 21:10:37 (1 year 2 months ago)
Author:Loïc d'Anterroches
Commit:d6c0b7a6802c9e5d5ae6fd9cccc51a1b1ce8f1cd
Message:Added forge size statistics.

Files: src/IDF/Views/Admin.php (3 diffs)
src/IDF/templates/idf/gadmin/projects/index.html (1 diff)

Change Details

src/IDF/Views/Admin.php
6464        $list_display = array(
6565             'shortname' => __('Short Name'),
6666             'name' => __('Name'),
67             array('id', 'IDF_Views_Admin_projectSize', __('Repository Size')),
6768                              );
6869        $pag->configure($list_display, array(),
6970                        array('shortname'));
71        $pag->extra_classes = array('', '', 'right');
7072        $pag->items_per_page = 25;
7173        $pag->no_results_text = __('No projects were found.');
7274        $pag->setFromRequest($request);
...... 
7476                                               array(
7577                                                     'page_title' => $title,
7678                                                     'projects' => $pag,
79                                                     'size' => IDF_Views_Admin_getForgeSize(),
7780                                                     ),
7881                                               $request);
7982    }
...... 
283286    $img = ($item->$field) ? 'day' : 'night';
284287    $text = ($item->$field) ? __('Yes') : __('No');
285288    return sprintf('<img src="'.Pluf::f('url_media').'/idf/img/%s.png" alt="%s" /> ', $img, $text);
286}
289}
290
291/**
292 * Display the size of the project.
293 *
294 * @param string Field
295 * @param IDF_Project
296 * @return string
297 */
298function IDF_Views_Admin_projectSize($field, $project)
299{
300    $size = $project->getRepositorySize();
301    if ($size == -1) {
302        return '';
303    }
304    return Pluf_Utils::prettySize($size);
305}
306
307/**
308 * Get a forge size.
309 *
310 * @return array Associative array with the size of each element
311 */
312function IDF_Views_Admin_getForgeSize()
313{
314    $res = array();
315    $res['repositories'] = 0;
316    foreach (Pluf::factory('IDF_Project')->getList() as $prj) {
317        $size = $prj->getRepositorySize();
318        if ($size != -1) {
319            $res['repositories'] += $size;
320        }
321    }
322    $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -bs '
323        .escapeshellarg(Pluf::f('upload_path'));
324    $out = split(' ', shell_exec($cmd), 2);
325    $res['downloads'] = $out[0];
326    $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -bs '
327        .escapeshellarg(Pluf::f('upload_issue_path'));
328    $out = split(' ', shell_exec($cmd), 2);
329    $res['attachments'] = $out[0];
330    $res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'];
331    // TODO: now we need the db
332    return $res;
333}
334
335/**
336 * Get the database size as given by the database.
337 *
338 * @return int Database size
339 */
340function IDF_Views_Admin_getForgeDbSize()
341{
342
343    // MySQL: SHOW TABLE STATUS FROM database;
344    // then sum Data_length and Index_length for each table
345    // PostgreSQL:
346    // Directly stats the database file
347}
src/IDF/templates/idf/gadmin/projects/index.html
11{extends "idf/gadmin/projects/base.html"}
22
3{block docclass}yui-t2{assign $inIndex=true}{/block}
3{block docclass}yui-t3{assign $inIndex=true}{/block}
44
55{block body}
66{$projects.render}
77{/block}
88
9{block context}
10<div class="issue-submit-info">
11<ul>
12<li>{trans 'Repository size:'} {$size['repositories']|size}</li>
13<li>{trans 'Attachment size:'} {$size['attachments']|size}</li>
14<li>{trans 'Download size:'} {$size['downloads']|size}</li>
15<li>{trans 'Forge size:'} {$size['total']|size}</li>
16</ul>
17<p>{trans 'The forge size does not include the database space yet.'}</p>
18</div>
19{/block}
20
21

Archive Download the corresponding diff file

Branches:
dev
develop
master
newdiff
svn

Tags:
v1.0