/[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

Contents of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26