/[simile]/svn/index.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations)
Tue Oct 28 19:10:16 2008 UTC (11 years, 7 months ago) by dpavlin
File size: 6205 byte(s)
Unroll radio buttons into table by first letter of repository.

Much more readable and easier to navigate
1 dpavlin 14 #!/usr/bin/perl -w
2    
3     # svn2js.pl
4     #
5     # 10/05/08 16:15:38 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6    
7     use strict;
8     use XML::Simple;
9     use Data::Dump qw/dump/;
10     use JSON;
11 dpavlin 16 use CGI;
12 dpavlin 36 use File::Slurp;
13 dpavlin 14
14 dpavlin 17 my $debug = $ENV{'DEBUG'} || 0;
15 dpavlin 14
16 dpavlin 36 my $config_path = $0;
17     $config_path =~ s/.cgi/.js/;
18 dpavlin 48
19     my $hostname = `hostname -s`;
20     chomp($hostname);
21     $hostname .= '.js';
22     $config_path = $hostname if -e $hostname;
23    
24 dpavlin 36 my $config = from_json( read_file( $config_path ) );
25     my $repository_dir = $config->{repository_dir} || die "no repository_dir in $config_path";
26     my $svnweb = $config->{svnweb} || die "no svnweb in $config_path";
27 dpavlin 44 die "no js URLs to Exhibit API and/or plugins" unless $config->{js};
28 dpavlin 36
29 dpavlin 30 my $limit = 1000;
30 dpavlin 14
31 dpavlin 15 # for older JSON
32 dpavlin 16 #sub encode_json { objToJson( @_ ) }
33 dpavlin 15
34     sub path_strip {
35     my $path = shift;
36 dpavlin 30 # $path =~ $strip_branch;
37 dpavlin 15 return $path;
38     }
39    
40 dpavlin 16 opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!";
41     my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir);
42     closedir($dir);
43    
44     our $q = CGI->new;
45     my $repository = $q->param('repository');
46 dpavlin 30 $repository = (grep { m/^\Q$repository\E$/ } @repositories )[0] if $repository;
47 dpavlin 16
48 dpavlin 30 warn "q = ",dump( $q );
49     warn "# limit: ", $q->param('limit');
50    
51 dpavlin 16 sub select_repository {
52 dpavlin 30 my $onChange = qq{document.getElementById('current_repository').submit();};
53 dpavlin 43 # we want to activete javascript magic refresh after we hit submit for the first time, and not always
54     $onChange = '' unless $q->param('did_submit');
55 dpavlin 49 my $first_letter = substr($repositories[0],0,1);
56 dpavlin 30 return (
57     $q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ),
58     "From repository ",
59 dpavlin 46 $q->param('did_submit') ?
60     $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ) :
61 dpavlin 49 "<table><tr><th>$first_letter</th><td>" . join( '', map {
62     my $delimiter = '';
63     if ( substr($_,0,1) ne $first_letter ) {
64     $first_letter = substr($_,0,1);
65     $delimiter = "</td></tr>\n<tr><th>$first_letter</th><td>";
66     }
67     $delimiter . $q->radio_group( -name => 'repository', -values => [ $_ ] )
68     } @repositories ) . "<td></tr></table>",
69     #$q->radio_group( -name => 'repository', -values => [ map { "$_, " } @repositories ], -onChange => $onChange ), # , -linebreak => 'true' ),
70 dpavlin 30 " show ",
71     $q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ),
72 dpavlin 43 " revisions and ",
73 dpavlin 30 $q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ),
74 dpavlin 43 " ",
75 dpavlin 47 $q->submit(-value=>'in Exhibit'),
76     $q->hidden(-name=>'did_submit', -value=>1),
77 dpavlin 30 $q->end_form
78     );
79 dpavlin 16 }
80    
81     if ( ! $repository ) {
82     print $q->header,$q->start_html("Select repository"), select_repository;
83     exit;
84     } elsif ( ! $q->param('json') ) {
85     $repository ||= 'Select repository';
86     print $q->header, qq|
87     <html>
88     <head>
89     <title>$repository -- Exhibit SVN exhibit facet browsing</title>
90    
91     <link rel="exhibit/data"
92     type="application/json"
93 dpavlin 30 href="|, $q->url( -query => 1 ), qq|&json=1" />
94 dpavlin 16
95 dpavlin 44 |, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq|
96 dpavlin 16
97     </head>
98     <body>
99     <div style="float: right">
100     <a href="http://stud05.technikum-wien.at/~tw05n126/exhibit/log/log.html">based on</a>,
101     <a href="http://simile.mit.edu/exhibit/">exhibit</a></div>
102     |, select_repository, qq|
103     <table width="100%" style="font-size: 0.8em">
104     <tr valign="top">
105     <td rowspan="2" width="25%">
106     <div ex:role="facet" ex:facetClass="TextSearch" ex:facetLabel="Search"></div>
107    
108     <div ex:role="facet" ex:expression=".author" ex:facetLabel="Author"
109     ex:sortMode="count"></div>
110 dpavlin 30 |, $q->param('path') ?
111     qq|
112 dpavlin 16 <div ex:role="facet" ex:expression=".action" ex:facetLabel="Action"
113     ex:sortMode="count" ex:scroll="false"></div>
114 dpavlin 30 | : '',
115     qq|
116 dpavlin 16 <div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange"
117 dpavlin 30 ex:interval="20" ex:scroll="true"></div>
118     |, $q->param('path') ?
119     qq|
120 dpavlin 16 <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count"
121     ex:sortMode="count"></div>
122 dpavlin 30 | : '',
123     qq|
124 dpavlin 16 </td>
125     <td>
126    
127     <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Name"
128     ex:sortMode="value"></div>
129     </td>
130     </tr>
131     <tr valign="top">
132     <td ex:role="viewPanel">
133    
134     <div ex:role="view" ex:viewClass="Timeline" ex:start=".date"
135     ex:colorKey=".author"
136     ex:topBandUnit="week" ex:topBandPixelsPerUnit="200"
137     ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25"
138 dpavlin 30 ex:timelineHeight="550" />
139 dpavlin 16
140     <div ex:role="view" ex:viewClass="Tabular"
141 dpavlin 30 ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg"
142 dpavlin 16 />
143     </td>
144    
145     </tr>
146     </table>
147    
148     </body>
149     </html>
150     |;
151     exit;
152     }
153    
154 dpavlin 14 my $json = {
155     properties => {
156     revision => {
157     valueType => "number",
158     },
159     'google-code-svn-link' => {
160     valueType => "url"
161     }
162     },
163     items => [],
164     };
165    
166     my $log;
167     {
168 dpavlin 30 my $cmd = "svn log --xml --stop-on-copy -v --limit " . ( $q->param('limit') || $limit ) . " file://$repository_dir/$repository";
169     warn "cmd: $cmd\n";
170     open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!";
171 dpavlin 14 local $/ = undef;
172     $log = <$log_fh>;
173     close( $log_fh );
174     }
175    
176     my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
177    
178     warn dump( $xml ) if $debug;
179    
180     foreach my $e (@{$xml->{'logentry'}}) {
181    
182     foreach my $p (@{$e->{'paths'}->{'path'}}) {
183 dpavlin 15 my $path = delete( $p->{'content'} );
184     my $label = $e->{'revision'} . ' - ' . path_strip( $path );
185 dpavlin 14 my $item = {
186     type => 'Item',
187     id => $label,
188     label => $label,
189 dpavlin 16 uri => sprintf($svnweb, $repository, $e->{'revision'}),
190 dpavlin 15 path_full => $path,
191     path => path_strip( $path ),
192 dpavlin 14 };
193    
194 dpavlin 15 $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
195     $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
196 dpavlin 14
197     warn dump( $item ) if $debug;
198    
199     push @{ $json->{items} }, $item;
200    
201 dpavlin 30 last if ! $q->param('path');
202 dpavlin 14 }
203    
204     }
205    
206     print qq|Content-type: application/json\n\r\n\r|, encode_json( $json );
207    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26