# # # add_file "mtn_benchmark/namespace.py" # content [7ed41a035d05413041ec9a07b30d523a22454d9e] # # patch "mtn_benchmark/cmdline.py" # from [dd2f3a48bc0c2e1cee6dcabf8bcf3e0077aead16] # to [e3984bf55a163e82c7f7125b456d9c2a46ff9829] # # patch "mtn_benchmark/mtn.py" # from [aa8fcab72d8ca83a372a68f0dcfac57eb10cfb51] # to [773ecd0cb44dd07077bf972e0bd38ed2e33e8e5f] # ============================================================ --- mtn_benchmark/namespace.py 7ed41a035d05413041ec9a07b30d523a22454d9e +++ mtn_benchmark/namespace.py 7ed41a035d05413041ec9a07b30d523a22454d9e @@ -0,0 +1,14 @@ +# This module is used to define the namespace in which command line +# descriptors are evaluated. +# +# It has to be a module, because "import *" is only allowed at module level. + +from mtn_benchmark.util import * +from mtn_benchmark.mtn import * +from mtn_benchmark.benchmarks import * +from mtn_benchmark.instrumenters import * +from mtn_benchmark.repo import * + + +def _get_namespace_(): + return globals() ============================================================ --- mtn_benchmark/cmdline.py dd2f3a48bc0c2e1cee6dcabf8bcf3e0077aead16 +++ mtn_benchmark/cmdline.py e3984bf55a163e82c7f7125b456d9c2a46ff9829 @@ -1,27 +1,14 @@ import optparse +import os +import os.path +import shutil import mtn_benchmark.driver import mtn_benchmark.mtn import mtn_benchmark.util +import mtn_benchmark.namespace +import mtn_benchmark.instrumenters -def namespace(): - "Returns the namespace for eval'ing descriptors" - from mtn_benchmark.util import * - from mtn_benchmark.mtn import * - from mtn_benchmark.benchmarks import * - from mtn_benchmark.instrumenters import * - from mtn_benchmark.repo import * - - return locals() - -# $ benchmark scratch results -v 'mtn=Mtn("mtn")' \ -# -b 'pull=PullBenchmark(ExistingRepo("/home/njs/blahblah"))' \ -# -i 'time=TimingInstrumenter(2)' -# -# --debug / -d -# --clear-cache / -c -# --mtn / -m - class InvalidDescriptor(Exception): pass @@ -32,15 +19,15 @@ return name, code def eval_descriptor_code(code): - return eval(code, {}, dict(namespace())) + return eval(code, dict(mtn_benchmark.namespace._get_namespace_()), {}) def process_descriptors(l, output, error, munger=eval_descriptor_code): if l: for arg in l: - name, value = eval_descriptor(arg) + name, value = split_descriptor(arg) if output.has_key(name): error("Name %s used twice" % name) - output[name] = value + output[name] = munger(value) def main(cmd, args): parser = optparse.OptionParser(usage="usage: %prog SCRATCH-DIR RESULTS-DIR") @@ -79,12 +66,17 @@ if options.force: shutil.rmtree(scratch, True) shutil.rmtree(results, True) + else: + if os.path.exists(scratch): + parser.error("Scratch dir already exists") + if os.path.exists(results): + parser.error("Results dir already exists") testables = {} process_descriptors(options.vcses, testables, parser.error) def path_to_mtn(path): return mtn_benchmark.mtn.Mtn(path) - process_descriptors(options.mtns, testables, parser.err, path_to_mtn) + process_descriptors(options.mtns, testables, parser.error, path_to_mtn) if not testables: parser.error("Need at least one VCS to benchmark") @@ -97,13 +89,13 @@ process_descriptors(options.instrumenters, instrumenters, parser.error) if not instrumenters: print "No instrumenters given, using default 'time' instrumenter" - instrumenters["time"] = TimingInstrumenter() + instrumenters["time"] = mtn_benchmark.instrumenters.TimingInstrumenter() cache_clearer = mtn_benchmark.util.CacheClearer(options.clear_cache) driver = mtn_benchmark.driver.Driver(scratch, results, testables, benchmarks, instrumenters, - debug, cache_clearer) + options.debug, cache_clearer) driver.run() ============================================================ --- mtn_benchmark/mtn.py aa8fcab72d8ca83a372a68f0dcfac57eb10cfb51 +++ mtn_benchmark/mtn.py 773ecd0cb44dd07077bf972e0bd38ed2e33e8e5f @@ -1,4 +1,5 @@ import os +import os.path import shutil import time @@ -6,7 +7,7 @@ class Mtn(object): def __init__(self, path): - self.path = path + self.path = os.path.abspath(path) def new(self, instrumenter): return InstrumentedMtn(self.path, instrumenter)