Commit cc153a6e authored by Jérome Perrin's avatar Jérome Perrin

apachedex: expect apachedex options to be passed as a file

Arguments passed to apachedex are complex, they contain quotes, backslashes,
spaces and they are propagated through several levels of buildout profiles
and scripts.
Simplify all this by relying on argparse ability of passing arguments from
a file. Users of this tool are now expected to generate a config file and
specify the path of this config file as an arguments.
parent e1b77dae
...@@ -29,10 +29,9 @@ ...@@ -29,10 +29,9 @@
from __future__ import print_function from __future__ import print_function
import os, errno import os
import subprocess import subprocess
import argparse import argparse
import shlex
from datetime import date from datetime import date
# run_apachedex.py <apachedex_executable> /srv/etc/output_folder script_name # run_apachedex.py <apachedex_executable> /srv/etc/output_folder script_name
...@@ -61,7 +60,7 @@ def build_command(apachedex_executable, output_file, ...@@ -61,7 +60,7 @@ def build_command(apachedex_executable, output_file,
raise ValueError("log_list: no log files to analyse were provided") raise ValueError("log_list: no log files to analyse were provided")
if config: if config:
argument_list.extend(shlex.split(config)) argument_list.append('@' + config)
argument_list.append('--error-detail') argument_list.append('--error-detail')
argument_list += log_list argument_list += log_list
...@@ -74,7 +73,10 @@ def main(): ...@@ -74,7 +73,10 @@ def main():
parser.add_argument("output_folder", metavar="OUTPUT_FOLDER") parser.add_argument("output_folder", metavar="OUTPUT_FOLDER")
parser.add_argument("base_url", metavar="BASE_URL") parser.add_argument("base_url", metavar="BASE_URL")
parser.add_argument("--apache-log-list", nargs='*') parser.add_argument("--apache-log-list", nargs='*')
parser.add_argument("--configuration") parser.add_argument(
"--configuration",
help="file containing apachedex command line arguments",
)
args = parser.parse_args() args = parser.parse_args()
config = args.configuration config = args.configuration
......
...@@ -45,39 +45,12 @@ class TestApachedexCommand(unittest.TestCase): ...@@ -45,39 +45,12 @@ class TestApachedexCommand(unittest.TestCase):
command = build_command(self.apachedex, command = build_command(self.apachedex,
'foo.html', 'foo.html',
[self.acesslog1, self.acesslog2], [self.acesslog1, self.acesslog2],
'--default foo') '/path/to/config')
self.assertEqual(command, ['/bin/apachedex', self.assertEqual(command, ['/bin/apachedex',
'--js-embed', '--js-embed',
'--out', 'foo.html', '--out', 'foo.html',
'--default', 'foo', '@/path/to/config',
'--error-detail', self.acesslog1, self.acesslog2 ]) '--error-detail', self.acesslog1, self.acesslog2 ])
def test_complexCommand(self): def test_raiseError(self):
command = build_command(self.apachedex,
'bar.html',
[self.acesslog1, self.acesslog2],
'--base bar foo --default foo')
self.assertEqual(command, ['/bin/apachedex',
'--js-embed',
'--out', 'bar.html',
'--base', 'bar', 'foo',
'--default', 'foo',
'--error-detail', self.acesslog1, self.acesslog2 ])
def test_complexCommandEscape(self):
command = build_command(self.apachedex,
'bar.html',
[self.acesslog1, self.acesslog2],
'--base "foo bar"')
self.assertEqual(command, ['/bin/apachedex',
'--js-embed',
'--out', 'bar.html',
'--base', 'foo bar',
'--error-detail', self.acesslog1, self.acesslog2 ])
def test_raiseErro(self):
self.assertRaises(ValueError, build_command, self.apachedex, 'foo.html', []) self.assertRaises(ValueError, build_command, self.apachedex, 'foo.html', [])
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment