diff options
Diffstat (limited to 'backend/resilient')
-rw-r--r-- | backend/resilient/__init__.py | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/backend/resilient/__init__.py b/backend/resilient/__init__.py index 424c73c..c42b5d1 100644 --- a/backend/resilient/__init__.py +++ b/backend/resilient/__init__.py @@ -1,7 +1,9 @@ import fileinput import os +import shlex import shutil import subprocess +import sys import tempfile import time import urllib @@ -9,13 +11,14 @@ import urllib __all__ = ["freenet"] backend_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) +root_path = os.path.normpath(os.path.join(backend_path, '..')) auth_path = os.path.join(backend_path, 'auth') dep_path = os.path.join(backend_path, 'dep') -html_path = os.path.normpath(os.path.join(backend_path, '../html')) -wiki_src_path = os.path.normpath(os.path.join(backend_path, '../wiki')) ikiwiki_setup_path = os.path.join(backend_path, 'ikiwiki.setup') -git_path = os.path.normpath(os.path.join(backend_path, '../.git')) +html_path = os.path.normpath(os.path.join(root_path, 'html')) +wiki_src_path = os.path.normpath(os.path.join(root_path, 'wiki')) +git_path = os.path.normpath(os.path.join(root_path, '.git')) ssh_config_path = os.path.join(auth_path, "ssh-config") @@ -36,9 +39,31 @@ class git: if not found: print("ERROR: git not found") exit(1) - else: - os.system("git submodule init") - os.system("git submodule update") + + os.system("git submodule init") + os.system("git submodule update") + + # http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git + # sets mtimes to last commit time, for ikiwiki 'last edited by' time + filelist = set() + for root, subdirs, files in os.walk(wiki_src_path): + for file in files: + filelist.add(os.path.relpath(os.path.join(root, file), root_path)) + mtime = 0 + gitobj = subprocess.Popen(shlex.split('git whatchanged --pretty=%at'), stdout=subprocess.PIPE) + for line in gitobj.stdout: + line = line.strip() + if not line: continue + if line.startswith(':'): + file = line.split('\t')[-1] + if file in filelist: + filelist.remove(file) + #print mtime, file + os.utime(os.path.join(root_path,file), (mtime, mtime)) + else: + mtime = long(line) + if not filelist: + break def __init__(self, remote, push_remote = ""): self.remote = remote @@ -80,7 +105,7 @@ class ikiwiki: shutil.rmtree(html_path) os.mkdir(html_path) - status = os.system("ikiwiki --rcs git --setup '%s' '%s' '%s'" % (ikiwiki_setup_path, wiki_src_path, html_path)) + status = os.system("ikiwiki --setup '%s' '%s' '%s'" % (ikiwiki_setup_path, wiki_src_path, html_path)) # workaround for ikistrap overwriting custom css files, which are included for freenet's filter os.system("git checkout -- '%s'/css" % html_path) |