Skip to content

Commit e2b6288

Browse files
committed
Create updateWeb.pl
1 parent 9d0f4fe commit e2b6288

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

updateWeb.pl

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use Getopt::Long;
5+
6+
7+
my $debug = 0;
8+
my $dryrun = 0;
9+
my $doPush;
10+
my $doCommit=1;
11+
my $message = "Update documents";
12+
my $help;
13+
my $useTemp;
14+
my $deleteTemp = 1;
15+
my $makeDoc = 0;
16+
my %samples;
17+
18+
GetOptions('push!'=>\$doPush,
19+
'commit!'=>\$doCommit,
20+
'dryrun' => \$dryrun,
21+
'message|m=s' => \$message,
22+
'makedoc!' => \$makeDoc,
23+
'help|h|?'=>\$help,
24+
'deleteTemp!' => \$deleteTemp,
25+
'createTempRepository' => \$useTemp);
26+
if ($dryrun) {
27+
$doPush = 0;
28+
$doCommit = 0;
29+
}
30+
31+
if ($doPush && !$doCommit) {
32+
print STDERR "If --push is specified, then commit must be enabled\n";
33+
}
34+
35+
if ($help) {
36+
print STDOUT "makeDocs.pl runs spl-make-doc in the current repository for all toolkits and samples,\n";
37+
print STDOUT "and then commits the doc updates to a second document repository (one set to gh-pages).\n";
38+
print STDOUT "Usage: makeDocs.pl [--commit|--nocommit] [--push|--nopush] [--message <msg>] <gh-pagesrepos>\n";
39+
exit 0;
40+
}
41+
if (scalar @ARGV != 1 && !$useTemp) {
42+
print STDERR "Usage: makeDocs.pl <pagesrepo>\n";
43+
exit 1;
44+
}
45+
if ($useTemp && $deleteTemp) {
46+
$doCommit or die "Must do a commit if making a temporary repository";
47+
$doPush or die "Must do a push if using a temporary repository";
48+
}
49+
my $pagesLocation = $ARGV[0];
50+
die "$pagesLocation not a valid directory" unless $useTemp || (-e $pagesLocation && -d $pagesLocation);
51+
52+
sub updateIndexHtml() {
53+
54+
my $infile = "$pagesLocation/index.html";
55+
my $outfile = "$pagesLocation/index.html.tmp";
56+
open(IN,"<$pagesLocation/index.html") or die "Could not open $infile";
57+
open(OUT,">$pagesLocation/index.html.tmp") or die "Could not open $outfile";
58+
while(<IN>) {
59+
if (/<!--\s*BEGIN SAMPLE LIST\s*-->/) {
60+
print OUT $_;
61+
my $foundEnd = 0;
62+
print OUT "<ul>\n";
63+
for my $app (keys %samples) {
64+
print OUT "<li><a href=\"$samples{$app}\">$app</a>\n";
65+
}
66+
print OUT "</ul>\n";
67+
while(<IN>) {
68+
if (/<!--\s*END SAMPLE LIST\s*-->/) {
69+
$foundEnd = 1;
70+
print OUT $_;
71+
last;
72+
}
73+
}
74+
die "Did not find END SAMPLE LIST" if !$foundEnd;
75+
}
76+
else {
77+
print OUT $_;
78+
}
79+
}
80+
81+
close OUT;
82+
close IN;
83+
system("cp $outfile $infile");
84+
system("cd $pagesLocation; git add index.html");
85+
}
86+
87+
sub lookForApp($$) {
88+
my ($dir,$exclude) = @_;
89+
$debug && print "lookForApp($dir,$exclude)\n";
90+
my @files = `ls $dir`;
91+
my $changes = 0;
92+
for my $f (@files) {
93+
chomp $f;
94+
my $fullName = "$dir/$f";
95+
$debug && print "Trying file $fullName\n";
96+
next if (defined $exclude && $dir =~ /$exclude/);
97+
next unless (-d "$fullName");
98+
if (-e "$fullName/doc/spldoc") {
99+
if ($fullName =~ /samples/) {
100+
$debug && print "$fullName is a sample\n";
101+
$samples{$f}="$fullName/doc/spldoc/html/index.html";
102+
}
103+
$debug && print "directory $fullName appears to have a documentation\n";
104+
if ($dryrun) {
105+
print "Would copy $fullName/doc to $pagesLocation\n";
106+
print "cp -r $fullName/doc $pagesLocation/$fullName\n";
107+
print "cd $pagesLocation; git add -A $fullName/doc\n";
108+
}
109+
else {
110+
system("mkdir -p $pagesLocation/$fullName");
111+
system("cp -r $fullName/doc $pagesLocation/$fullName");
112+
system("cd $pagesLocation; git add -A $fullName/doc");
113+
}
114+
$? >> 8 == 0 or die "Problem adding.";
115+
}
116+
else {
117+
$debug && print "no docs found in $fullName\n";
118+
lookForApp("$fullName");
119+
}
120+
}
121+
}
122+
123+
sub main() {
124+
if ($makeDoc == 1) {
125+
system("ant spldoc");
126+
}
127+
$? >> 8 == 0 or die "Could not build spl doc";
128+
# Make sure the branch is checked out in location given on the command
129+
130+
if ($useTemp) {
131+
my $line = `git remote show origin | grep Fetch`;
132+
$line =~ /Fetch URL:\s+(.*)$/;
133+
my $url = $1;
134+
$url =~ /github.com[:\/]\w+\/(.+)\.git$/;
135+
my $repoName = $1;
136+
137+
$pagesLocation = "/tmp/$repoName";
138+
die "Cannot create repository since $pagesLocation already exists" if (-e $pagesLocation);
139+
system("cd /tmp; git clone $url");
140+
}
141+
142+
system("cd $pagesLocation; git checkout gh-pages");
143+
$? >> 8 == 0 or die "Cannot set branch to gh-pages in $pagesLocation";
144+
# handle the toolkit; need a better way of specifying which toolkit.
145+
lookForApp(".","test");
146+
updateIndexHtml();
147+
my $changes = `cd $pagesLocation; git status -s | grep -v "^?" | wc -l`;
148+
chomp $changes;
149+
print "$changes files changed\n";
150+
if ($changes > 0) {
151+
if ($dryrun) {
152+
print "DryRun: $changes files changed\n";
153+
}
154+
elsif ($changes >0 && $doCommit) {
155+
system("cd $pagesLocation; git commit -a -m \"$message\"");
156+
if ($doPush) {
157+
system("cd $pagesLocation; git push origin gh-pages");
158+
}
159+
}
160+
}
161+
if ($useTemp && $deleteTemp) {
162+
if ($pagesLocation =~ /tmp/) {
163+
system("rm -rf $pagesLocation");
164+
}
165+
else {
166+
die "Unexpected temporary repository structure; not deleting $pagesLocation";
167+
}
168+
}
169+
}
170+
171+
main();

0 commit comments

Comments
 (0)