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 @@
from __future__ import print_function
import os, errno
import os
import subprocess
import argparse
import shlex
from datetime import date
# run_apachedex.py <apachedex_executable> /srv/etc/output_folder script_name
......@@ -61,7 +60,7 @@ def build_command(apachedex_executable, output_file,
raise ValueError("log_list: no log files to analyse were provided")
if config:
argument_list.extend(shlex.split(config))
argument_list.append('@' + config)
argument_list.append('--error-detail')
argument_list += log_list
......@@ -74,7 +73,10 @@ def main():
parser.add_argument("output_folder", metavar="OUTPUT_FOLDER")
parser.add_argument("base_url", metavar="BASE_URL")
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()
config = args.configuration
......
......@@ -45,39 +45,12 @@ class TestApachedexCommand(unittest.TestCase):
command = build_command(self.apachedex,
'foo.html',
[self.acesslog1, self.acesslog2],
'--default foo')
'/path/to/config')
self.assertEqual(command, ['/bin/apachedex',
'--js-embed',
'--out', 'foo.html',
'--default', 'foo',
'@/path/to/config',
'--error-detail', self.acesslog1, self.acesslog2 ])
def test_complexCommand(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):
def test_raiseError(self):
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