[haizea-commit] r436 - in trunk: bin src/haizea src/haizea/cli src/haizea/common
haizea-commit at mailman.cs.uchicago.edu
haizea-commit at mailman.cs.uchicago.edu
Wed Jul 16 09:57:39 CDT 2008
Author: borja
Date: 2008-07-16 09:57:39 -0500 (Wed, 16 Jul 2008)
New Revision: 436
Added:
trunk/src/haizea/cli/
trunk/src/haizea/cli/__init__.py
trunk/src/haizea/cli/commands.py
Removed:
trunk/src/haizea/clients.py
Modified:
trunk/bin/haizea
trunk/bin/haizea-generate-configs
trunk/bin/haizea-generate-scripts
trunk/src/haizea/common/utils.py
Log:
Reorganized CLI code
Modified: trunk/bin/haizea
===================================================================
--- trunk/bin/haizea 2008-07-15 20:57:20 UTC (rev 435)
+++ trunk/bin/haizea 2008-07-16 14:57:39 UTC (rev 436)
@@ -1,6 +1,6 @@
#!/usr/bin/python
-from haizea import clients
+from haizea.cli import commands
import sys
try:
import psyco
@@ -8,5 +8,4 @@
except:
pass
-c = clients.Haizea()
-c.run(sys.argv)
\ No newline at end of file
+commands.haizea(sys.argv)
\ No newline at end of file
Modified: trunk/bin/haizea-generate-configs
===================================================================
--- trunk/bin/haizea-generate-configs 2008-07-15 20:57:20 UTC (rev 435)
+++ trunk/bin/haizea-generate-configs 2008-07-16 14:57:39 UTC (rev 436)
@@ -1,7 +1,6 @@
#!/usr/bin/python
-from haizea import clients
+from haizea.cli import commands
import sys
-c = clients.GenConfigs()
-c.run(sys.argv)
\ No newline at end of file
+commands.haizea_generate_configs(sys.argv)
\ No newline at end of file
Modified: trunk/bin/haizea-generate-scripts
===================================================================
--- trunk/bin/haizea-generate-scripts 2008-07-15 20:57:20 UTC (rev 435)
+++ trunk/bin/haizea-generate-scripts 2008-07-16 14:57:39 UTC (rev 436)
@@ -1,7 +1,6 @@
#!/usr/bin/python
-from haizea import clients
+from haizea.cli import commands
import sys
-c = clients.genScript()
-c.run(sys.argv)
\ No newline at end of file
+commands.haizea_generate_scripts(sys.argv)
\ No newline at end of file
Added: trunk/src/haizea/cli/__init__.py
===================================================================
Added: trunk/src/haizea/cli/commands.py
===================================================================
--- trunk/src/haizea/cli/commands.py (rev 0)
+++ trunk/src/haizea/cli/commands.py 2008-07-16 14:57:39 UTC (rev 436)
@@ -0,0 +1,135 @@
+# -------------------------------------------------------------------------- #
+# Copyright 2006-2008, University of Chicago #
+# Copyright 2008, Distributed Systems Architecture Group, Universidad #
+# Complutense de Madrid (dsa-research.org) #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); you may #
+# not use this file except in compliance with the License. You may obtain #
+# a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+# -------------------------------------------------------------------------- #
+
+from haizea.resourcemanager.rm import ResourceManager
+from haizea.traces.generators import generateTrace, generateImages
+from haizea.common.utils import gen_traceinj_name
+from haizea.common.config import RMConfig, RMMultiConfig, TraceConfig, ImageConfig
+import os.path
+import optparse
+
+def haizea(argv):
+ p = OptionParser()
+ p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
+
+ opt, args = p.parse_args(argv)
+
+ configfile=opt.conf
+ config = RMConfig.fromFile(configfile)
+
+ rm = ResourceManager(config)
+
+ rm.start()
+
+def haizea_generate_configs(argv):
+ p = OptionParser()
+ p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
+ p.add_option(Option("-d", "--dir", action="store", type="string", dest="dir", required=True))
+
+ opt, args = p.parse_args(argv)
+
+ configfile=opt.conf
+ multiconfig = RMMultiConfig.fromFile(configfile)
+
+ dir = opt.dir
+
+ configs = multiconfig.getConfigs()
+
+ etcdir = os.path.abspath(dir)
+ if not os.path.exists(etcdir):
+ os.makedirs(etcdir)
+
+ for c in configs:
+ profile = c.getProfile()
+ tracefile = c.getTracefile()
+ injfile = c.getInjectfile()
+ datadir = c.getDataDir()
+ name = gen_traceinj_name(tracefile, injfile)
+ configfile = etcdir + "/%s_%s.conf" % (profile, name)
+ fc = open(configfile, "w")
+ c.config.write(fc)
+ fc.close()
+
+def haizea_generate_scripts(argv):
+ p = OptionParser()
+ p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
+ p.add_option(Option("-t", "--template", action="store", type="string", dest="template", required=True))
+ p.add_option(Option("-d", "--confdir", action="store", type="string", dest="confdir", required=True))
+ p.add_option(Option("-m", "--only-missing", action="store_true", dest="onlymissing"))
+
+ opt, args = p.parse_args(argv)
+
+ configfile=opt.conf
+ multiconfig = RMMultiConfig.fromFile(configfile)
+
+ try:
+ from mako.template import Template
+ except:
+ print "You need Mako Templates for Python to run this command."
+ print "You can download them at http://www.makotemplates.org/"
+ exit(1)
+
+ configs = multiconfig.getConfigsToRun()
+
+ etcdir = os.path.abspath(opt.confdir)
+ if not os.path.exists(etcdir):
+ os.makedirs(etcdir)
+
+ templatedata = []
+ for c in configs:
+ profile = c.getProfile()
+ tracefile = c.getTracefile()
+ injfile = c.getInjectfile()
+ datadir = c.getDataDir()
+ name = gen_traceinj_name(tracefile, injfile)
+ if not opt.onlymissing or not os.path.exists(datadir):
+ configfile = etcdir + "/%s_%s.conf" % (profile, name)
+ templatedata.append((profile, name, configfile))
+
+ template = Template(filename=opt.template)
+ print template.render(configs=templatedata, etcdir=etcdir)
+
+
+class OptionParser (optparse.OptionParser):
+ def _init_parsing_state (self):
+ optparse.OptionParser._init_parsing_state(self)
+ self.option_seen = {}
+
+ def check_values (self, values, args):
+ for option in self.option_list:
+ if (isinstance(option, Option) and
+ option.required and
+ not self.option_seen.has_key(option)):
+ self.error("%s not supplied" % option)
+ return (values, args)
+
+class Option (optparse.Option):
+ ATTRS = optparse.Option.ATTRS + ['required']
+
+ def _check_required (self):
+ if self.required and not self.takes_value():
+ raise optparse.OptionError(
+ "required flag set for option that doesn't take a value",
+ self)
+
+ # Make sure _check_required() is called from the constructor!
+ CHECK_METHODS = optparse.Option.CHECK_METHODS + [_check_required]
+
+ def process (self, opt, value, values, parser):
+ optparse.Option.process(self, opt, value, values, parser)
+ parser.option_seen[self] = 1
\ No newline at end of file
Deleted: trunk/src/haizea/clients.py
===================================================================
--- trunk/src/haizea/clients.py 2008-07-15 20:57:20 UTC (rev 435)
+++ trunk/src/haizea/clients.py 2008-07-16 14:57:39 UTC (rev 436)
@@ -1,170 +0,0 @@
-# -------------------------------------------------------------------------- #
-# Copyright 2006-2008, University of Chicago #
-# Copyright 2008, Distributed Systems Architecture Group, Universidad #
-# Complutense de Madrid (dsa-research.org) #
-# #
-# Licensed under the Apache License, Version 2.0 (the "License"); you may #
-# not use this file except in compliance with the License. You may obtain #
-# a copy of the License at #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# Unless required by applicable law or agreed to in writing, software #
-# distributed under the License is distributed on an "AS IS" BASIS, #
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
-# See the License for the specific language governing permissions and #
-# limitations under the License. #
-# -------------------------------------------------------------------------- #
-
-from haizea.resourcemanager.rm import ResourceManager
-from haizea.traces.generators import generateTrace, generateImages
-from haizea.common.utils import Option, OptionParser, genTraceInjName
-from haizea.common.config import RMConfig, RMMultiConfig, TraceConfig, ImageConfig
-import os.path
-
-class Haizea(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
-
- opt, args = p.parse_args(argv)
-
- configfile=opt.conf
- config = RMConfig.fromFile(configfile)
-
- rm = ResourceManager(config)
-
- rm.start()
-
-class GenConfigs(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
- p.add_option(Option("-d", "--dir", action="store", type="string", dest="dir", required=True))
-
- opt, args = p.parse_args(argv)
-
- configfile=opt.conf
- multiconfig = RMMultiConfig.fromFile(configfile)
-
- dir = opt.dir
-
- configs = multiconfig.getConfigs()
-
- etcdir = os.path.abspath(dir)
- if not os.path.exists(etcdir):
- os.makedirs(etcdir)
-
- for c in configs:
- profile = c.getProfile()
- tracefile = c.getTracefile()
- injfile = c.getInjectfile()
- datadir = c.getDataDir()
- name = genTraceInjName(tracefile, injfile)
- configfile = etcdir + "/%s_%s.conf" % (profile, name)
- fc = open(configfile, "w")
- c.config.write(fc)
- fc.close()
-
-class genScript(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
- p.add_option(Option("-t", "--template", action="store", type="string", dest="template", required=True))
- p.add_option(Option("-d", "--confdir", action="store", type="string", dest="confdir", required=True))
- p.add_option(Option("-m", "--only-missing", action="store_true", dest="onlymissing"))
-
- opt, args = p.parse_args(argv)
-
- configfile=opt.conf
- multiconfig = RMMultiConfig.fromFile(configfile)
-
- try:
- from mako.template import Template
- except:
- print "You need Mako Templates for Python to run this command."
- print "You can download them at http://www.makotemplates.org/"
- exit(1)
-
- configs = multiconfig.getConfigsToRun()
-
- etcdir = os.path.abspath(opt.confdir)
- if not os.path.exists(etcdir):
- os.makedirs(etcdir)
-
- templatedata = []
- for c in configs:
- profile = c.getProfile()
- tracefile = c.getTracefile()
- injfile = c.getInjectfile()
- datadir = c.getDataDir()
- name = genTraceInjName(tracefile, injfile)
- if not opt.onlymissing or not os.path.exists(datadir):
- configfile = etcdir + "/%s_%s.conf" % (profile, name)
- templatedata.append((profile, name, configfile))
-
- template = Template(filename=opt.template)
- print template.render(configs=templatedata, etcdir=etcdir)
-
-
-class TraceGenerator(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
- p.add_option(Option("-f", "--tracefile", action="store", type="string", dest="tracefile", required=True))
- p.add_option(Option("-g", "--guaranteeavg", action="store_true", dest="guaranteeavg"))
-
- opt, args = p.parse_args(argv)
-
- configfile=opt.conf
- config = TraceConfig.fromFile(configfile)
-
- tracefile = opt.tracefile
-
- generateTrace(config, tracefile, opt.guaranteeavg)
-
-
-class ImageGenerator(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-c", "--conf", action="store", type="string", dest="conf", required=True))
- p.add_option(Option("-f", "--imagefile", action="store", type="string", dest="imagefile", required=True))
-
- opt, args = p.parse_args(argv)
-
- configfile=opt.conf
- config = ImageConfig.fromFile(configfile)
-
- imagefile = opt.imagefile
-
- generateImages(config, imagefile)
-
-
-class InjectionAnalyzer(object):
- def __init__(self):
- pass
-
- def run(self, argv):
- p = OptionParser()
- p.add_option(Option("-f", "--injectionfile", action="store", type="string", dest="injectionfile", required=True))
-
- opt, args = p.parse_args(argv)
-
- injectionfile = opt.injectionfile
-
- #analyzeARLeaseInjection(injectionfile)
\ No newline at end of file
Modified: trunk/src/haizea/common/utils.py
===================================================================
--- trunk/src/haizea/common/utils.py 2008-07-15 20:57:20 UTC (rev 435)
+++ trunk/src/haizea/common/utils.py 2008-07-16 14:57:39 UTC (rev 436)
@@ -16,43 +16,11 @@
# limitations under the License. #
# -------------------------------------------------------------------------- #
-import optparse
from mx import DateTime
from math import ceil, floor
from cPickle import dump, HIGHEST_PROTOCOL
-class Option (optparse.Option):
- ATTRS = optparse.Option.ATTRS + ['required']
-
- def _check_required (self):
- if self.required and not self.takes_value():
- raise optparse.OptionError(
- "required flag set for option that doesn't take a value",
- self)
-
- # Make sure _check_required() is called from the constructor!
- CHECK_METHODS = optparse.Option.CHECK_METHODS + [_check_required]
-
- def process (self, opt, value, values, parser):
- optparse.Option.process(self, opt, value, values, parser)
- parser.option_seen[self] = 1
-
-
-class OptionParser (optparse.OptionParser):
-
- def _init_parsing_state (self):
- optparse.OptionParser._init_parsing_state(self)
- self.option_seen = {}
-
- def check_values (self, values, args):
- for option in self.option_list:
- if (isinstance(option, Option) and
- option.required and
- not self.option_seen.has_key(option)):
- self.error("%s not supplied" % option)
- return (values, args)
-
-def genTraceInjName(tracefile, injectedfile):
+def gen_traceinj_name(tracefile, injectedfile):
tracename=tracefile.split("/")[-1].split(".")[0]
if injectedfile != None:
@@ -64,7 +32,7 @@
return name
def genDataDirName(profile, tracefile, injectedfile):
- name = genTraceInjName(tracefile, injectedfile)
+ name = gen_traceinj_name(tracefile, injectedfile)
return profile + "/" + name + "/"
def roundDateTimeDelta(d):
More information about the Haizea-commit
mailing list