new file pve-docs-mediawiki-import.in
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 10 Oct 2016 07:14:25 +0000 (09:14 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 10 Oct 2016 07:16:19 +0000 (09:16 +0200)
And use auto-generated data from link-refs.json.

Also avoid strange file names.

Makefile
asciidoc-pve.in
debian/tree/pve-docs-mediawiki/pve-docs-mediawiki-import [deleted file]
pve-docs-mediawiki-import.in [new file with mode: 0755]

index 87926bd..36a6377 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -169,16 +169,21 @@ asciidoc-pve: asciidoc-pve.in link-refs.json
        chmod +x asciidoc-pve.tmp
        mv asciidoc-pve.tmp asciidoc-pve
 
+pve-docs-mediawiki-import: pve-docs-mediawiki-import.in link-refs.json
+       cat pve-docs-mediawiki-import.in link-refs.json >  pve-docs-mediawiki-import.tmp
+       chmod +x pve-docs-mediawiki-import.tmp
+       mv pve-docs-mediawiki-import.tmp pve-docs-mediawiki-import
+
 test: asciidoc-pve
        ./asciidoc-pve compile-wiki-section pve-package-repos.adoc
        #./asciidoc-pve compile-wiki-chapter ha-manager.adoc
 
 WIKI_IMPORTS=                                                                  \
-       section-pve-usbstick-plain.html                                         \
-       section-getting-help-plain.html                                         \
-       section-pve-system-requirements-plain.html                              \
-       $(addsuffix -plain.html, $(addprefix sysadmin-, ${SYSADMIN_PARTS}))     \
-       $(addsuffix -plain.html, $(addprefix chapter-, ${CHAPTER_LIST}))        \
+       pve-usbstick-plain.html                                                 \
+       getting-help-plain.html                                                 \
+       pve-system-requirements-plain.html                                      \
+       $(addsuffix -plain.html, ${SYSADMIN_PARTS})                             \
+       $(addsuffix -plain.html, ${CHAPTER_LIST})                               \
        $(addsuffix .5-plain.html, ${CONFIG_LIST})                              \
        $(addsuffix -plain.html, $(addprefix pve-storage-, ${STORAGE_TYPES}))
 
@@ -203,23 +208,14 @@ all: index.html
 %-nwdiag.svg: %.nwdiag
        nwdiag -T svg $*.nwdiag -o $@;
 
-sysadmin-%-plain.html: asciidoc-pve %.adoc
-       ./asciidoc-pve compile-wiki-section -o $@ $*.adoc
-
-section-%-plain.html: asciidoc-pve %.adoc
-       ./asciidoc-pve compile-wiki-section -o $@ $*.adoc
+%-plain.html: asciidoc-pve %.adoc
+       ./asciidoc-pve compile-wiki -o $@ $*.adoc
 
-chapter-sysadmin.html chapter-sysadmin-plain.html: ${SYSADMIN_SOURCES}
+chapter-sysadmin.html sysadmin-plain.html: ${SYSADMIN_SOURCES}
 
 chapter-%.html: %.adoc ${PVE_COMMON_DOC_SOURCES}
        asciidoc ${ADOC_STDARG} -a toc -o $@ $*.adoc
 
-chapter-%-plain.html: %.adoc ${PVE_COMMON_DOC_SOURCES}
-       ./asciidoc-pve compile-wiki-chapter -o $@ $*.adoc
-
-pve-storage-%-plain.html: pve-storage-%.adoc ${PVE_COMMON_DOC_SOURCES}
-       ./asciidoc-pve compile-wiki-section -o $@ pve-storage-$*.adoc
-
 %.1.html: %.adoc %.1-synopsis.adoc ${PVE_COMMON_DOC_SOURCES}
        asciidoc ${ADOC_MAN1_HTML_ARGS} -o $@ $*.adoc
 
@@ -277,10 +273,11 @@ deb:
        rm -f ${GEN_DEB} ${DOC_DEB} ${MEDIAWIKI_DEB};
        make ${GEN_DEB} ${DOC_DEB} ${MEDIAWIKI_DEB};
 
-${GEN_DEB} ${DOC_DEB} ${MEDIAWIKI_DEB}: index.html ${INDEX_INCLUDES} ${WIKI_IMPORTS} ${API_VIEWER_SOURCES} ${GEN_DEB_SOURCES}
+${GEN_DEB} ${DOC_DEB} ${MEDIAWIKI_DEB}: index.html ${INDEX_INCLUDES} ${WIKI_IMPORTS} ${API_VIEWER_SOURCES} ${GEN_DEB_SOURCES} asciidoc-pve pve-docs-mediawiki-import
        rm -rf build
        mkdir build
        rsync -a debian/ build/debian
+       cp pve-docs-mediawiki-import build/debian/tree/pve-docs-mediawiki/pve-docs-mediawiki-import
        echo "git clone git://git.proxmox.com/git/pve-docs.git\\ngit checkout ${GITVERSION}" > build/debian/SOURCE
        # install files for pve-doc-generator package
        mkdir -p build/usr/share/${GEN_PACKAGE}
@@ -313,5 +310,5 @@ update: clean
        make all
 
 clean: 
-       rm -rf *.tmp.xml *.html *.pdf *.epub *.tmp *.1 *.5 *.8 *.deb *.changes build api-viewer/apidoc.js chapter-*.html chapter-*-plain.html chapter-*.html pve-admin-guide.chunked asciidoc-pve link-refs.json .asciidoc-pve-tmp_*
+       rm -rf *.tmp.xml *.html *.pdf *.epub *.tmp *.1 *.5 *.8 *.deb *.changes build api-viewer/apidoc.js chapter-*.html *-plain.html chapter-*.html pve-admin-guide.chunked asciidoc-pve link-refs.json .asciidoc-pve-tmp_* pve-docs-mediawiki-import
        find . -name '*~' -exec rm {} ';'
index 25bb4a0..2e92c6c 100644 (file)
@@ -162,11 +162,8 @@ sub compile_wiki {
 
     my $leveloffset = 0;
 
-    if ($clicmd eq 'compile-wiki-chapter') {
-       $leveloffset = 0;
-    } elsif ($clicmd eq 'compile-wiki-section') {
-       $leveloffset = -1;
-    }
+    my $doctype = $fileinfo->{doctype}->{$env}->{$infile} // 0;
+    $leveloffset = - $doctype;
 
     my $date = `date`;
     chomp $date;
@@ -211,8 +208,7 @@ sub compile_wiki {
        die "aciidoc error";
 }
 
-if ($clicmd eq 'compile-wiki-chapter' ||
-    $clicmd eq 'compile-wiki-section') {
+if ($clicmd eq 'compile-wiki') {
 
     eval { compile_wiki(); };
     my $err = $@;
diff --git a/debian/tree/pve-docs-mediawiki/pve-docs-mediawiki-import b/debian/tree/pve-docs-mediawiki/pve-docs-mediawiki-import
deleted file mode 100755 (executable)
index 0577b3c..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Data::Dumper;
-
-use IO::File;
-use File::Basename;
-use MediaWiki::API;
-
-my $config_fn = "/root/.pve-docs"; # format 'username:pw'
-
-my $fh = IO::File->new("$config_fn") || 
-    die "Please configure the mediawiki user/passswd in '$config_fn'\n";
-
-my $api_url = "http://localhost/mediawiki/api.php";
-
-my $config = <$fh>;
-chomp $config;
-
-my ($username, $passwd) = split(':', $config, 2);
-
-my $mw = MediaWiki::API->new();
-$mw->{config}->{api_url} = $api_url;
-
-# log in to the wiki
-$mw->login({ lgname => $username, lgpassword => $passwd })
-    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
-
-sub update_page {
-    my ($pagename, $include, $category) = @_;
-
-    print "update mediawiki page: $pagename\n";
-
-    my $ref = $mw->get_page( { title => $pagename } );
-    my $page =  $ref->{'*'} || '';
-
-    if ($page !~ m/^\{\{#pvedocs:.*\}\}\s*$/m) {
-       $page = "{{#pvedocs:$include}}\n$page";
-    } else {
-       $page =~ s/^\{\{#pvedocs:.*\}\}\s*$/\{\{#pvedocs:$include\}\}\n/m;
-    }
-
-    if ($category) {
-       my $catstr = "Category:$category";
-
-       if ($page !~ m/^\[\[$catstr\]\]\s*$/m) {
-           $page .= "\n[[$catstr]]\n";
-       }
-    }
-    
-    my $timestamp = $ref->{timestamp};
-    my $wcmd = {
-       action => 'edit',
-       title => $pagename,
-       basetimestamp => $timestamp, # to avoid edit conflicts
-       text => $page,
-    };
-
-    $mw->edit($wcmd) || 
-       die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
-}
-
-my $cat_refdoc = "Reference Documentation";
-
-my $docs = {
-    'chapter-ha-manager-plain.html' => {
-       title => "High Availability",
-       category => $cat_refdoc,
-    },
-    'chapter-pve-installation-plain.html' => {
-       title => "Installation",
-       category => $cat_refdoc,
-    },
-    'section-pve-usbstick-plain.html' => {
-       title => "Install from USB Stick",
-       category => $cat_refdoc,
-    },
-    'section-pve-system-requirements-plain.html' => {
-       title => "System Requirements",
-       category => $cat_refdoc,
-    },
-    'section-getting-help-plain.html' => {
-       title => "Getting Help",
-       category => $cat_refdoc,
-    },
-    'sysadmin-pve-network-plain.html' => {
-       title => "Network Configuration",
-       category => $cat_refdoc,
-    },
-    'sysadmin-pve-disk-health-monitoring-plain.html' => {
-       title => "Disk Health Monitoring",
-       category => $cat_refdoc,
-    },
-    'sysadmin-local-lvm-plain.html' => {
-       title => "Logical Volume Manager (LVM)",
-       category => $cat_refdoc,
-    },
-    'sysadmin-pve-package-repos-plain.html' => {
-       title => "Package Repositories",
-       category => $cat_refdoc,
-    },
-    'sysadmin-system-software-updates-plain.html' => {
-       title => "System Software Updates",
-       category => $cat_refdoc,
-    },
-    'chapter-sysadmin-plain.html' => {
-       title => "Host System Administration",
-       category => $cat_refdoc,
-    },
-    'chapter-pct-plain.html' => {
-       title => "Linux Container",
-       category => $cat_refdoc,
-    },
-    'chapter-pmxcfs-plain.html' => {
-       title => "Proxmox Cluster File System (pmxcfs)",
-       category => $cat_refdoc,
-    },
-    'chapter-pve-bibliography-plain.html' => {
-       title => "Bibliography",
-       category => $cat_refdoc,
-    },
-    'chapter-pvecm-plain.html' => {
-       title => "Cluster Manager",
-       category => $cat_refdoc,
-    },
-    'chapter-pve-faq-plain.html' => {
-       title => "FAQ",
-       category => $cat_refdoc,
-    },
-    'chapter-pve-firewall-plain.html' => {
-       title => "Firewall",
-       category => $cat_refdoc,
-    },
-    'chapter-pvesm-plain.html' => {
-       title => "Storage",
-       category => $cat_refdoc,
-    },
-    'chapter-pveum-plain.html' => {
-       title => "User Management",
-       category => $cat_refdoc,
-    },
-    'chapter-qm-plain.html' => {
-       title => "Qemu/KVM Virtual Machines",
-       category => $cat_refdoc,
-    },
-    'chapter-vzdump-plain.html' => {
-       title => "Backup and Restore",
-       category => $cat_refdoc,
-    },
-    'qm.conf.5-plain.html' => {
-       title => "Manual: vm.conf",
-       category => $cat_refdoc,
-    },
-    'pct.conf.5-plain.html' => {
-       title => "Manual: pct.conf",
-       category => $cat_refdoc,
-    },
-    'datacenter.cfg.5-plain.html' => {
-       title => "Manual: datacenter.cfg",
-       category => $cat_refdoc,
-    },
-    # Storage Plugins
-    'pve-storage-dir-plain.html' => {
-       title => "Storage: Directory",
-       category => $cat_refdoc,
-    },
-    'pve-storage-glusterfs-plain.html' => {
-       title => "Storage: GlusterFS",
-       category => $cat_refdoc,
-    },
-    'pve-storage-iscsidirect-plain.html' => {
-       title => "Storage: User Mode iSCSI",
-       category => $cat_refdoc,
-    },
-    'pve-storage-iscsi-plain.html' => {
-       title => "Storage: iSCSI",
-       category => $cat_refdoc,
-    },
-    'pve-storage-lvm-plain.html' => {
-       title => "Storage: LVM",
-       category => $cat_refdoc,
-    },
-    'pve-storage-lvmthin-plain.html' => {
-       title => "Storage: LVM Thin",
-       category => $cat_refdoc,
-    },
-    'pve-storage-nfs-plain.html' => {
-       title => "Storage: NFS",
-       category => $cat_refdoc,
-    },
-    'pve-storage-rbd-plain.html' => {
-       title => "Storage: RBD",
-       category => $cat_refdoc,
-    },
-    'pve-storage-zfspool-plain.html' => {
-       title => "Storage: ZFS",
-       category => $cat_refdoc,
-    },
-};
-
-#update_page("testpage1", $filename, $d->{category});
-
-foreach my $filename (keys %$docs) {
-    my $path = "/usr/share/pve-docs/$filename";
-    die "no such file '$path'" if ! -f $path;
-    my $d = $docs->{$filename};
-    update_page($d->{title}, $filename, $d->{category});
-}
-
-# also update 'Get support' page, because this is used since a long
-# time and is referenced from outside
-update_page("Get support", 'sysadmin-getting-help-plain.html', 'HOWTO');
diff --git a/pve-docs-mediawiki-import.in b/pve-docs-mediawiki-import.in
new file mode 100755 (executable)
index 0000000..4a2736c
--- /dev/null
@@ -0,0 +1,235 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use IO::File;
+use File::Basename;
+use MediaWiki::API;
+
+use JSON;
+
+my $data_str = "";
+while (<main::DATA>) { $data_str .= $_; }
+
+my $fileinfo = decode_json($data_str);
+
+my $config_fn = "/root/.pve-docs"; # format 'username:pw'
+
+my $fh = IO::File->new("$config_fn") || 
+    die "Please configure the mediawiki user/passswd in '$config_fn'\n";
+
+my $api_url = "http://localhost/mediawiki/api.php";
+
+my $config = <$fh>;
+chomp $config;
+
+my ($username, $passwd) = split(':', $config, 2);
+
+my $mw = MediaWiki::API->new();
+$mw->{config}->{api_url} = $api_url;
+
+# log in to the wiki
+$mw->login({ lgname => $username, lgpassword => $passwd })
+    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+
+sub update_page {
+    my ($pagename, $include, $category) = @_;
+
+    print "update mediawiki page: $pagename\n";
+
+    my $ref = $mw->get_page( { title => $pagename } );
+    my $page =  $ref->{'*'} || '';
+
+    if ($page !~ m/^\{\{#pvedocs:.*\}\}\s*$/m) {
+       $page = "{{#pvedocs:$include}}\n$page";
+    } else {
+       $page =~ s/^\{\{#pvedocs:.*\}\}\s*$/\{\{#pvedocs:$include\}\}\n/m;
+    }
+
+    if ($category) {
+       my $catstr = "Category:$category";
+
+       if ($page !~ m/^\[\[$catstr\]\]\s*$/m) {
+           $page .= "\n[[$catstr]]\n";
+       }
+    }
+    
+    my $timestamp = $ref->{timestamp};
+    my $wcmd = {
+       action => 'edit',
+       title => $pagename,
+       basetimestamp => $timestamp, # to avoid edit conflicts
+       text => $page,
+    };
+
+    $mw->edit($wcmd) || 
+       die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+}
+
+my $cat_refdoc = "Reference Documentation";
+
+my $docs_old = {
+    'ha-manager-plain.html' => {
+       title => "High Availability",
+       category => $cat_refdoc,
+    },
+    'pve-installation-plain.html' => {
+       title => "Installation",
+       category => $cat_refdoc,
+    },
+    'pve-usbstick-plain.html' => {
+       title => "Install from USB Stick",
+       category => $cat_refdoc,
+    },
+    'pve-system-requirements-plain.html' => {
+       title => "System Requirements",
+       category => $cat_refdoc,
+    },
+    'getting-help-plain.html' => {
+       title => "Getting Help",
+       category => $cat_refdoc,
+    },
+    'pve-network-plain.html' => {
+       title => "Network Configuration",
+       category => $cat_refdoc,
+    },
+    'pve-disk-health-monitoring-plain.html' => {
+       title => "Disk Health Monitoring",
+       category => $cat_refdoc,
+    },
+    'local-lvm-plain.html' => {
+       title => "Logical Volume Manager (LVM)",
+       category => $cat_refdoc,
+    },
+    'pve-package-repos-plain.html' => {
+       title => "Package Repositories",
+       category => $cat_refdoc,
+    },
+    'system-software-updates-plain.html' => {
+       title => "System Software Updates",
+       category => $cat_refdoc,
+    },
+    'sysadmin-plain.html' => {
+       title => "Host System Administration",
+       category => $cat_refdoc,
+    },
+    'pct-plain.html' => {
+       title => "Linux Container",
+       category => $cat_refdoc,
+    },
+    'pmxcfs-plain.html' => {
+       title => "Proxmox Cluster File System (pmxcfs)",
+       category => $cat_refdoc,
+    },
+    'pve-bibliography-plain.html' => {
+       title => "Bibliography",
+       category => $cat_refdoc,
+    },
+    'pvecm-plain.html' => {
+       title => "Cluster Manager",
+       category => $cat_refdoc,
+    },
+    'pve-faq-plain.html' => {
+       title => "FAQ",
+       category => $cat_refdoc,
+    },
+    'pve-firewall-plain.html' => {
+       title => "Firewall",
+       category => $cat_refdoc,
+    },
+    'pvesm-plain.html' => {
+       title => "Storage",
+       category => $cat_refdoc,
+    },
+    'pveum-plain.html' => {
+       title => "User Management",
+       category => $cat_refdoc,
+    },
+    'qm-plain.html' => {
+       title => "Qemu/KVM Virtual Machines",
+       category => $cat_refdoc,
+    },
+    'vzdump-plain.html' => {
+       title => "Backup and Restore",
+       category => $cat_refdoc,
+    },
+    'qm.conf.5-plain.html' => {
+       title => "Manual: vm.conf",
+       category => $cat_refdoc,
+    },
+    'pct.conf.5-plain.html' => {
+       title => "Manual: pct.conf",
+       category => $cat_refdoc,
+    },
+    'datacenter.cfg.5-plain.html' => {
+       title => "Manual: datacenter.cfg",
+       category => $cat_refdoc,
+    },
+    # Storage Plugins
+    'pve-storage-dir-plain.html' => {
+       title => "Storage: Directory",
+       category => $cat_refdoc,
+    },
+    'pve-storage-glusterfs-plain.html' => {
+       title => "Storage: GlusterFS",
+       category => $cat_refdoc,
+    },
+    'pve-storage-iscsidirect-plain.html' => {
+       title => "Storage: User Mode iSCSI",
+       category => $cat_refdoc,
+    },
+    'pve-storage-iscsi-plain.html' => {
+       title => "Storage: iSCSI",
+       category => $cat_refdoc,
+    },
+    'pve-storage-lvm-plain.html' => {
+       title => "Storage: LVM",
+       category => $cat_refdoc,
+    },
+    'pve-storage-lvmthin-plain.html' => {
+       title => "Storage: LVM Thin",
+       category => $cat_refdoc,
+    },
+    'pve-storage-nfs-plain.html' => {
+       title => "Storage: NFS",
+       category => $cat_refdoc,
+    },
+    'pve-storage-rbd-plain.html' => {
+       title => "Storage: RBD",
+       category => $cat_refdoc,
+    },
+    'pve-storage-zfspool-plain.html' => {
+       title => "Storage: ZFS",
+       category => $cat_refdoc,
+    },
+};
+
+my $wiki_man5_pages = {
+    'datacenter.cfg.adoc' => 1,
+    'qm.conf.adoc' => 1,
+    'pct.conf.adoc' => 1,
+};
+
+my $docs = {};
+foreach my $source (sort keys %{$fileinfo->{toplevel}->{wiki}}) {
+    my $title = $fileinfo->{titles}->{wiki}->{$source};
+    my $doctype = $fileinfo->{doctype}->{wiki}->{$source};
+
+    my $suffix = $wiki_man5_pages->{$source} ? '.5-plain.html' : '-plain.html';
+    my $filename = $source;
+    $filename =~ s/\.adoc//;
+    $filename .= $suffix;
+
+    my $path = "/usr/share/pve-docs/$filename";
+    die "no such file '$path'" if ! -f $path;
+    
+    update_page($title, $filename, category => $cat_refdoc);
+}
+
+# also update 'Get support' page, because this is used since a long
+# time and is referenced from outside
+update_page("Get support", 'getting-help-plain.html', 'HOWTO');
+
+__END__