put media files to output dir instead of directly overwriting dokuwiki target dir

This commit is contained in:
Elan Ruusamäe 2012-09-17 23:56:40 +02:00
parent 800196e92d
commit 65786931b9
2 changed files with 23 additions and 13 deletions

View file

@ -17,20 +17,22 @@ require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php'; require_once DOKU_INC.'inc/common.php';
require_once DOKU_INC.'inc/cliopts.php'; require_once DOKU_INC.'inc/cliopts.php';
function strip_datadir($fn) { function strip_dir($dir, $fn) {
global $conf; global $conf;
return end(explode($conf['datadir'].'/', $fn, 2)); return end(explode($dir.'/', $fn, 2));
} }
$fn = $conf['mediadir'].'/'.utf8_encodeFN($id);
switch ($argv[1]) { switch ($argv[1]) {
case 'cleanID': case 'cleanID':
echo cleanID($argv[2]); echo cleanID($argv[2]);
break; break;
case 'wikiFN': case 'wikiFN':
echo strip_datadir(wikiFN($argv[2])); echo strip_dir($conf['datadir'], wikiFN($argv[2]));
break; break;
case 'mediaFn': case 'mediaFN':
echo mediaFn($argv[2]); echo strip_dir($conf['mediadir'], mediaFN($argv[2]));
break; break;
case 'getNS': case 'getNS':
echo getNS($argv[2]); echo getNS($argv[2]);

View file

@ -10,7 +10,7 @@
import sys, os, os.path, re import sys, os, os.path, re
import getopt import getopt
from shutil import copyfile, copystat from shutil import copyfile, copystat
from os import listdir from os import listdir, mkdir
from os.path import isdir, basename from os.path import isdir, basename
from doku import DokuWiki from doku import DokuWiki
from moinformat import moin2doku from moinformat import moin2doku
@ -31,6 +31,14 @@ def check_dirs(moin_pages_dir, output_dir):
print >> sys.stderr, "Output directory doesn't exist!" print >> sys.stderr, "Output directory doesn't exist!"
sys.exit(1) sys.exit(1)
pagedir = os.path.join(output_dir, 'pages')
if not isdir(pagedir):
mkdir(pagedir)
mediadir = os.path.join(output_dir, 'media')
if not isdir(mediadir):
mkdir(mediadir)
def get_path_names(moin_pages_dir, basenames = False): def get_path_names(moin_pages_dir, basenames = False):
items = listdir(moin_pages_dir) items = listdir(moin_pages_dir)
pathnames = [] pathnames = []
@ -90,18 +98,18 @@ def get_current_revision(pagedir):
# pagedir = MoinMoin page dir # pagedir = MoinMoin page dir
# ns = DokuWiki namespace where attachments to copy # ns = DokuWiki namespace where attachments to copy
def copy_attachments(pagedir, ns): def copy_attachments(pagedir, ns):
dir = os.path.join(pagedir, 'attachments') srcdir = os.path.join(pagedir, 'attachments')
if not isdir(dir): if not isdir(srcdir):
return return
attachment_dir = dw.mediaFn(ns) attachment_dir = os.path.join(output_dir, 'media', dw.mediaFN(ns))
if not isdir(attachment_dir): if not isdir(attachment_dir):
os.makedirs(attachment_dir); os.makedirs(attachment_dir);
attachments = listdir(dir) attachments = listdir(srcdir)
for attachment in attachments: for attachment in attachments:
src = os.path.join(dir, attachment) src = os.path.join(srcdir, attachment)
dst = dw.mediaFn(dw.cleanID("%s/%s" % (ns, attachment))) dst = os.path.join(output_dir, 'media', dw.mediaFN(dw.cleanID("%s/%s" % (ns, attachment))))
copyfile(src, dst) copyfile(src, dst)
copystat(src, dst) copystat(src, dst)
@ -247,7 +255,7 @@ def convertfile(pagedir, overwrite = False):
# content = convert_markup(pagename, content) # content = convert_markup(pagename, content)
content = moin2doku(pagename, content) content = moin2doku(pagename, content)
out_file = os.path.join(output_dir, dw.wikiFN(pagename)) out_file = os.path.join(output_dir, 'pages', dw.wikiFN(pagename))
print "dokuname: [%s]" % out_file print "dokuname: [%s]" % out_file
try: try:
writefile(out_file, content, overwrite = overwrite) writefile(out_file, content, overwrite = overwrite)