From 60d2dd318f66563c3ee3bde950d7f53426530acc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 28 Feb 2010 00:12:47 -0500 Subject: [PATCH] Add new --clean option; this makes ikiwiki remove all built files in the destdir, as well as wrappers and the .ikiwiki directory. --- IkiWiki.pm | 7 +++++++ IkiWiki/Render.pm | 11 +++++++++++ Makefile.PL | 2 +- debian/changelog | 4 +++- doc/usage.mdwn | 8 ++++++++ ikiwiki.in | 12 +++++++++++- ikiwiki.spec | 2 +- 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 9df6c90d6..00eadfd98 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -409,6 +409,13 @@ sub getsetup () { safe => 0, rebuild => 0, }, + clean => { + type => "internal", + default => 0, + description => "running in clean mode", + safe => 0, + rebuild => 0, + }, refresh => { type => "internal", default => 0, diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 3ebb1a324..af24df155 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -683,6 +683,17 @@ sub refresh () { } } +sub clean_rendered { + lockwiki(); + loadindex(); + remove_unrendered(); + foreach my $page (keys %oldrenderedfiles) { + foreach my $file (@{$oldrenderedfiles{$page}}) { + prune($config{destdir}."/".$file); + } + } +} + sub commandline_render () { lockwiki(); loadindex(); diff --git a/Makefile.PL b/Makefile.PL index 462f7364d..52421a711 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -51,7 +51,7 @@ docwiki: ikiwiki.out $(PERL) -Iblib/lib $(extramodules) $(tflag) ikiwiki.out -libdir . -setup docwiki.setup -refresh extra_clean: - rm -rf html doc/.ikiwiki + $(PERL) -I. $(extramodules) $(tflag) ikiwiki.in -libdir . -setup docwiki.setup -clean rm -f *.man ikiwiki.out ikiwiki.setup plugins/*.pyc $(MAKE) -C po clean diff --git a/debian/changelog b/debian/changelog index 832bbaa85..3b92c598d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -ikiwiki (3.20100213) UNRELEASED; urgency=low +ikiwiki (3.20100228) UNRELEASED; urgency=low * comments: Display number of comments in comment action link. * Rebuild wikis on upgrade to this version to get the comment counts @@ -8,6 +8,8 @@ ikiwiki (3.20100213) UNRELEASED; urgency=low files/directories. * Fix admin openid detection in setup automator, and avoid prompting for a password. + * Add new --clean option; this makes ikiwiki remove all built + files in the destdir, as well as wrappers and the .ikiwiki directory. -- Joey Hess Sun, 14 Feb 2010 17:02:10 -0500 diff --git a/doc/usage.mdwn b/doc/usage.mdwn index e4808d4c2..a105d7e59 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -50,6 +50,14 @@ These options control the mode that ikiwiki operates in. If used with --setup --refresh, this makes it also update any configured wrappers. +* --clean + + This makes ikiwiki clean up by removing any files it denerated in the + `destination` directory, as well as any configured wrappers, and the + `.ikiwiki` state directory. This is mostly useful if you're running + ikiwiki in a Makefile to build documentation and want a corresponding + `clean` target. + * --cgi Enable [[CGI]] mode. In cgi mode ikiwiki runs as a cgi script, and diff --git a/ikiwiki.in b/ikiwiki.in index b8581d880..ae1251ff6 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -37,6 +37,7 @@ sub getconfig () { "syslog!" => \$config{syslog}, "rebuild!" => \$config{rebuild}, "refresh!" => \$config{refresh}, + "clean!" => \$config{clean}, "post-commit" => \$config{post_commit}, "render=s" => \$config{render}, "wrappers!" => \$config{genwrappers}, @@ -135,6 +136,7 @@ sub main () { if (@{$config{wrappers}} && ! $config{render} && ! $config{dumpsetup} && + ! $config{clean} && ((! $config{refresh} && ! $config{post_commit}) || $config{genwrappers})) { debug(gettext("generating wrappers..")); @@ -159,7 +161,7 @@ sub main () { # setup implies a wiki rebuild by default if (! $config{refresh} && ! $config{render} && - ! $config{post_commit}) { + ! $config{post_commit} && ! $config{clean}) { $config{rebuild}=1; } } @@ -190,6 +192,14 @@ sub main () { elsif ($config{post_commit} && ! commit_hook_enabled()) { # do nothing } + elsif ($config{clean}) { + require IkiWiki::Render; + foreach my $wrapper (@{$config{wrappers}}) { + prune($wrapper->{wrapper}); + } + clean_rendered(); + system("rm", "-rf", $config{wikistatedir}); + } else { if ($config{rebuild}) { debug(gettext("rebuilding wiki..")); diff --git a/ikiwiki.spec b/ikiwiki.spec index 865c9a325..1dba9f463 100644 --- a/ikiwiki.spec +++ b/ikiwiki.spec @@ -1,5 +1,5 @@ Name: ikiwiki -Version: 3.20100212 +Version: 3.20100228 Release: 1%{?dist} Summary: A wiki compiler