Skip to content

Commit

Permalink
Added instance-patch section in Makefile to patch instance interprete…
Browse files Browse the repository at this point in the history
…r to run scripts (needed when front-page is not anonymously accessible)
  • Loading branch information
sgeulette committed Oct 22, 2021
1 parent 11b05ab commit 49995a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ vcn: ## Shows newer packages in checkversion-n.html
.PHONY: techdoc
techdoc: ## Builds technical docs
bin/sphinxbuilder

.PHONY: instance-patch
instance-patch: ## Patches instance interpreter to run scripts (needed when front-page is not anonymously accessible)
bin/python helper.py -f=patch_instance -i=$(instance)
53 changes: 53 additions & 0 deletions helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-

import os
pyu_path = os.path.realpath('parts/omelette/imio/pyutils')
import sys
sys.path[0:0] = ['/'.join(pyu_path.split('/')[:-2])]

from imio.pyutils.system import error
from imio.pyutils.system import read_file
from imio.pyutils.system import verbose

import argparse


def patch_instance(inst='instance-debug'):
idp = 'parts/{}/bin/interpreter'.format(inst)
if not os.path.exists(idp):
error("'{}' doesn't exist: cannot patch it".format(idp))
return False
lines = read_file(idp)
if 'ploneCustom.css' not in ''.join(lines):
sp = 0
for (i, line) in enumerate(lines):
if 'exec(_val)' in line:
nl = line.lstrip()
sp = len(line) - len(nl)
break
lines.insert(i, "{}{}".format(' ' * sp,
'_val = _val.replace("\'); from AccessControl.SpecialUsers import system '
'as user;", "/ploneCustom.css\'); from AccessControl.SpecialUsers import '
'system as user;")'))
verbose("=> Patching: '{}'".format(idp))
fh = open(idp, 'w')
fh.write('\n'.join(lines))
fh.close()
else:
verbose("=> Already patched: '{}'".format(idp))


functions = {'patch_instance': patch_instance}


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Call some helper function')
parser.add_argument('-f', '--function', dest='fct', help="Function to call",
choices=sorted(functions.keys()))
parser.add_argument('-i', '--instance', dest='inst', help="Instance to use")
ns = parser.parse_args()
if ns.fct:
kwargs = {}
if ns.inst:
kwargs['inst'] = ns.inst
functions[ns.fct](**kwargs)

0 comments on commit 49995a9

Please sign in to comment.