summaryrefslogtreecommitdiff
path: root/ql-ikiwiki-publish
diff options
context:
space:
mode:
Diffstat (limited to 'ql-ikiwiki-publish')
-rwxr-xr-xql-ikiwiki-publish46
1 files changed, 29 insertions, 17 deletions
diff --git a/ql-ikiwiki-publish b/ql-ikiwiki-publish
index bfdc06c..6745f69 100755
--- a/ql-ikiwiki-publish
+++ b/ql-ikiwiki-publish
@@ -86,12 +86,12 @@ def process_uml_includes(mdwnpath, mdwndir):
f.write(re.sub('(?m)^' + inc[0], link, content))
-def process_uml(T, dirname='.', ignore=['.git', '.ikiwiki']):
- for topdir, dirs, files in os.walk(os.path.abspath(dirname), topdown=True):
- # Filter dirs by modifying the list in-place,
- # as described in os.walk documentation.
- dirs[:] = [d for d in dirs if d not in ignore]
+def process_uml(S, T, dirname='.', ignore=['.git*', '.ikiwiki']):
+ shutil.copytree(
+ os.path.abspath('.'), S, ignore=shutil.ignore_patterns(*ignore)
+ )
+ for topdir, dirs, files in os.walk(S, topdown=True):
for filename in fnmatch.filter(files, '*.mdwn'):
mdwnpath = os.path.join(topdir, filename)
@@ -99,16 +99,18 @@ def process_uml(T, dirname='.', ignore=['.git', '.ikiwiki']):
process_uml_includes(mdwnpath, topdir)
-def mangle_setup(src, dest, html):
+def mangle_setup(src, dest, html, mdwn):
with open(src) as f:
text = f.read()
lines = [
line
for line in text.splitlines()
- if not line.startswith('destdir:')
+ if (not line.startswith('srcdir:')
+ or not line.startswith('destdir:'))
]
+ lines.append('srcdir: {}'.format(mdwn))
lines.append('destdir: {}'.format(html))
mangled = ''.join(line + '\n' for line in lines)
@@ -117,25 +119,35 @@ def mangle_setup(src, dest, html):
f.write(mangled)
-def run_ikiwiki(T):
+def run_ikiwiki(S, T, locally=False):
setup = os.path.join(T, 'ikiwiki.setup')
html = os.path.join(T, 'html')
- mangle_setup('ikiwiki.setup', setup, html)
+ mangle_setup('ikiwiki.setup', setup, html, S)
subprocess.check_call(['ikiwiki', '--setup', setup, '--gettime'])
- subprocess.check_call(
- ['rsync', '-ahHSvs', '--delete', html + '/.', rsync_target])
+ if not locally:
+ subprocess.check_call(
+ ['rsync', '-ahHSvs', '--delete', html + '/.', rsync_target])
-static_http = sys.argv[1]
-dirname = sys.argv[2]
-rsync_target = 'static@{}:/srv/http/{}/.'.format(static_http, dirname)
+rsync_target = None
+if len(sys.argv) == 3:
+ static_http = sys.argv[1]
+ dirname = sys.argv[2]
+ rsync_target = 'static@{}:/srv/http/{}/.'.format(static_http, dirname)
+
+S = '.publish'
T = tempfile.mkdtemp()
try:
- process_uml(T)
- run_ikiwiki(T)
+ process_uml(S, T)
+ run_ikiwiki(S, T, locally=rsync_target is None)
except BaseException as e:
+ shutil.rmtree(S)
shutil.rmtree(T)
raise
else:
- shutil.rmtree(T)
+ shutil.rmtree(S)
+ if rsync_target is None:
+ print("Open wiki: firefox %s/html/index.html" % T)
+ else:
+ shutil.rmtree(T)