if(..): --> if ..:
sigh.
This commit is contained in:
parent
c2056dae76
commit
51af36e000
@ -50,21 +50,21 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
||||
|
||||
def getboolean(self, section, option):
|
||||
value = self.get(section, option)
|
||||
if(value == None):
|
||||
if value == None:
|
||||
#not there so don't let the parent blowup
|
||||
return IgnoreMissingConfigParser.DEF_BOOLEAN
|
||||
return ConfigParser.RawConfigParser.getboolean(self, section, option)
|
||||
|
||||
def getfloat(self, section, option):
|
||||
value = self.get(section, option)
|
||||
if(value == None):
|
||||
if value == None:
|
||||
#not there so don't let the parent blowup
|
||||
return IgnoreMissingConfigParser.DEF_FLOAT
|
||||
return ConfigParser.RawConfigParser.getfloat(self, section, option)
|
||||
|
||||
def getint(self, section, option):
|
||||
value = self.get(section, option)
|
||||
if(value == None):
|
||||
if value == None:
|
||||
#not there so don't let the parent blowup
|
||||
return IgnoreMissingConfigParser.DEF_INT
|
||||
return ConfigParser.RawConfigParser.getint(self, section, option)
|
||||
@ -81,18 +81,18 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
|
||||
return "/".join([str(section), str(option)])
|
||||
|
||||
def _resolve_special(self, section, option, value_gotten):
|
||||
if(value_gotten and len(value_gotten)):
|
||||
if(section == 'passwords'):
|
||||
if value_gotten and len(value_gotten):
|
||||
if section == 'passwords':
|
||||
#ensure we store it as a password
|
||||
key = self._makekey(section, option)
|
||||
self.pws[key] = value_gotten
|
||||
return value_gotten
|
||||
if(section == 'host' and option == 'ip'):
|
||||
if section == 'host' and option == 'ip':
|
||||
LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.")
|
||||
host_ip = utils.get_host_ip()
|
||||
LOG.debug("Determined host ip to be: \"%s\"" % (host_ip))
|
||||
return host_ip
|
||||
elif(section == 'passwords'):
|
||||
elif section == 'passwords':
|
||||
key = self._makekey(section, option)
|
||||
LOG.debug("Being forced to ask for password for \"%s\" since the configuration/environment value is empty.", key)
|
||||
pw = sh.password(PW_TMPL % (key))
|
||||
@ -104,7 +104,7 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
|
||||
def get(self, section, option):
|
||||
key = self._makekey(section, option)
|
||||
value = None
|
||||
if(key in self.configs_fetched):
|
||||
if key in self.configs_fetched:
|
||||
value = self.configs_fetched.get(key)
|
||||
LOG.debug("Fetched cached value \"%s\" for param \"%s\"" % (value, key))
|
||||
else:
|
||||
@ -116,7 +116,7 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
|
||||
return value
|
||||
|
||||
def _extract_default(self, default_value):
|
||||
if(not SUB_MATCH.search(default_value)):
|
||||
if not SUB_MATCH.search(default_value):
|
||||
return default_value
|
||||
|
||||
LOG.debug("Performing simple replacement on %s", default_value)
|
||||
@ -132,18 +132,18 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
|
||||
def _get_special(self, section, option):
|
||||
key = self._makekey(section, option)
|
||||
parent_val = ConfigParser.RawConfigParser.get(self, section, option)
|
||||
if(parent_val == None):
|
||||
if parent_val == None:
|
||||
#parent didn't have anything, we are unable to do anything with it then
|
||||
return None
|
||||
extracted_val = None
|
||||
mtch = ENV_PAT.match(parent_val)
|
||||
if(mtch):
|
||||
if mtch:
|
||||
env_key = mtch.group(1).strip()
|
||||
def_val = mtch.group(2)
|
||||
if(len(def_val) == 0 and len(env_key) == 0):
|
||||
if len(def_val) == 0 and len(env_key) == 0:
|
||||
msg = "Invalid bash-like value \"%s\" for \"%s\"" % (parent_val, key)
|
||||
raise excp.BadParamException(msg)
|
||||
if(len(env_key) == 0 or env.get_key(env_key) == None):
|
||||
if len(env_key) == 0 or env.get_key(env_key) == None:
|
||||
LOG.debug("Extracting default value from config provided default value \"%s\" for \"%s\"" % (def_val, key))
|
||||
actual_def_val = self._extract_default(def_val)
|
||||
LOG.debug("Using config provided default value \"%s\" for \"%s\" (no environment key)" % (actual_def_val, key))
|
||||
@ -163,28 +163,28 @@ class EnvConfigParser(ConfigParser.RawConfigParser):
|
||||
port = self.get("db", "port")
|
||||
pw = self.get("passwords", "sql")
|
||||
#check the dsn cache
|
||||
if(dbname in self.db_dsns):
|
||||
if dbname in self.db_dsns:
|
||||
return self.db_dsns[dbname]
|
||||
#form the dsn (from components we have...)
|
||||
#dsn = "<driver>://<username>:<password>@<host>:<port>/<database>"
|
||||
if(not host):
|
||||
if not host:
|
||||
msg = "Unable to fetch a database dsn - no host found"
|
||||
raise excp.BadParamException(msg)
|
||||
driver = self.get("db", "type")
|
||||
if(not driver):
|
||||
if not driver:
|
||||
msg = "Unable to fetch a database dsn - no driver type found"
|
||||
raise excp.BadParamException(msg)
|
||||
dsn = driver + "://"
|
||||
if(user):
|
||||
if user:
|
||||
dsn += user
|
||||
if(pw):
|
||||
if pw:
|
||||
dsn += ":" + pw
|
||||
if(user or pw):
|
||||
if user or pw:
|
||||
dsn += "@"
|
||||
dsn += host
|
||||
if(port):
|
||||
if port:
|
||||
dsn += ":" + port
|
||||
if(dbname):
|
||||
if dbname:
|
||||
dsn += "/" + dbname
|
||||
else:
|
||||
dsn += "/"
|
||||
|
@ -67,12 +67,12 @@ class PkgInstallComponent(ComponentBase):
|
||||
am_downloaded = 0
|
||||
for location_info in locations:
|
||||
uri = location_info.get("uri")
|
||||
if(not uri):
|
||||
if not uri:
|
||||
continue
|
||||
branch = location_info.get("branch")
|
||||
subdir = location_info.get("subdir")
|
||||
target_loc = None
|
||||
if(subdir and len(subdir)):
|
||||
if subdir and len(subdir):
|
||||
target_loc = sh.joinpths(base_dir, subdir)
|
||||
else:
|
||||
target_loc = base_dir
|
||||
@ -94,7 +94,7 @@ class PkgInstallComponent(ComponentBase):
|
||||
|
||||
def install(self):
|
||||
pkgs = self.get_pkglist()
|
||||
if(len(pkgs)):
|
||||
if len(pkgs):
|
||||
pkgnames = sorted(pkgs.keys())
|
||||
LOG.info("Installing packages (%s)." % (", ".join(pkgnames)))
|
||||
self.packager.install_batch(pkgs)
|
||||
@ -105,14 +105,14 @@ class PkgInstallComponent(ComponentBase):
|
||||
|
||||
def pre_install(self):
|
||||
pkgs = utils.get_pkg_list(self.distro, self.component_name)
|
||||
if(len(pkgs)):
|
||||
if len(pkgs):
|
||||
mp = self._get_param_map(None)
|
||||
self.packager.pre_install(pkgs, mp)
|
||||
return self.tracedir
|
||||
|
||||
def post_install(self):
|
||||
pkgs = utils.get_pkg_list(self.distro, self.component_name)
|
||||
if(len(pkgs)):
|
||||
if len(pkgs):
|
||||
mp = self._get_param_map(None)
|
||||
self.packager.post_install(pkgs, mp)
|
||||
return self.tracedir
|
||||
@ -131,7 +131,7 @@ class PkgInstallComponent(ComponentBase):
|
||||
|
||||
def _configure_files(self):
|
||||
configs = self._get_config_files()
|
||||
if(len(configs)):
|
||||
if len(configs):
|
||||
LOG.info("Configuring %s files" % (len(configs)))
|
||||
for fn in configs:
|
||||
#get the params and where it should come from and where it should go
|
||||
@ -174,16 +174,16 @@ class PythonInstallComponent(PkgInstallComponent):
|
||||
def _install_pips(self):
|
||||
#install any need pip items
|
||||
pips = utils.get_pip_list(self.distro, self.component_name)
|
||||
if(len(pips)):
|
||||
if len(pips):
|
||||
LOG.info("Setting up %s pips (%s)" % (len(pips), ", ".join(pips.keys())))
|
||||
pip.install(pips)
|
||||
for name in pips.keys():
|
||||
self.tracewriter.pip_install(name, pips.get(name))
|
||||
|
||||
def _format_stderr_out(self, stderr, stdout):
|
||||
if(stdout == None):
|
||||
if stdout == None:
|
||||
stdout = ''
|
||||
if(stderr == None):
|
||||
if stderr == None:
|
||||
stderr = ''
|
||||
combined = ["===STDOUT===", str(stdout), "===STDERR===", str(stderr)]
|
||||
return utils.joinlinesep(*combined)
|
||||
@ -194,7 +194,7 @@ class PythonInstallComponent(PkgInstallComponent):
|
||||
def _install_python_setups(self):
|
||||
#setup any python directories
|
||||
pydirs = self._get_python_directories()
|
||||
if(len(pydirs)):
|
||||
if len(pydirs):
|
||||
actual_dirs = list()
|
||||
for pydir_info in pydirs:
|
||||
working_dir = pydir_info.get('work_dir', self.appdir)
|
||||
@ -203,7 +203,7 @@ class PythonInstallComponent(PkgInstallComponent):
|
||||
self.tracewriter.make_dir(self.tracedir)
|
||||
for pydir_info in pydirs:
|
||||
name = pydir_info.get("name")
|
||||
if(not name):
|
||||
if not name:
|
||||
#TODO should we raise an exception here?
|
||||
continue
|
||||
working_dir = pydir_info.get('work_dir', self.appdir)
|
||||
@ -233,10 +233,10 @@ class PkgUninstallComponent(ComponentBase):
|
||||
|
||||
def _unconfigure_files(self):
|
||||
cfgfiles = self.tracereader.files_configured()
|
||||
if(len(cfgfiles)):
|
||||
if len(cfgfiles):
|
||||
LOG.info("Removing %s configuration files (%s)" % (len(cfgfiles), ", ".join(cfgfiles)))
|
||||
for fn in cfgfiles:
|
||||
if(len(fn)):
|
||||
if len(fn):
|
||||
sh.unlink(fn)
|
||||
|
||||
def uninstall(self):
|
||||
@ -246,22 +246,22 @@ class PkgUninstallComponent(ComponentBase):
|
||||
|
||||
def _uninstall_pkgs(self):
|
||||
pkgsfull = self.tracereader.packages_installed()
|
||||
if(len(pkgsfull)):
|
||||
if len(pkgsfull):
|
||||
LOG.info("Potentially removing %s packages (%s)" % (len(pkgsfull), ", ".join(sorted(pkgsfull.keys()))))
|
||||
which_removed = self.packager.remove_batch(pkgsfull)
|
||||
LOG.info("Actually removed %s packages (%s)" % (len(which_removed), ", ".join(sorted(which_removed))))
|
||||
|
||||
def _uninstall_touched_files(self):
|
||||
filestouched = self.tracereader.files_touched()
|
||||
if(len(filestouched)):
|
||||
if len(filestouched):
|
||||
LOG.info("Removing %s touched files (%s)" % (len(filestouched), ", ".join(filestouched)))
|
||||
for fn in filestouched:
|
||||
if(len(fn)):
|
||||
if len(fn):
|
||||
sh.unlink(fn)
|
||||
|
||||
def _uninstall_dirs(self):
|
||||
dirsmade = self.tracereader.dirs_made()
|
||||
if(len(dirsmade)):
|
||||
if len(dirsmade):
|
||||
LOG.info("Removing %s created directories (%s)" % (len(dirsmade), ", ".join(dirsmade)))
|
||||
for dirname in dirsmade:
|
||||
sh.deldir(dirname)
|
||||
@ -280,13 +280,13 @@ class PythonUninstallComponent(PkgUninstallComponent):
|
||||
|
||||
def _uninstall_pips(self):
|
||||
pips = self.tracereader.pips_installed()
|
||||
if(len(pips)):
|
||||
if len(pips):
|
||||
LOG.info("Uninstalling %s pips" % (len(pips)))
|
||||
pip.uninstall(pips)
|
||||
|
||||
def _uninstall_python(self):
|
||||
pylisting = self.tracereader.py_listing()
|
||||
if(len(pylisting)):
|
||||
if len(pylisting):
|
||||
LOG.info("Uninstalling %s python setups" % (len(pylisting)))
|
||||
for entry in pylisting:
|
||||
where = entry.get('where')
|
||||
@ -314,19 +314,19 @@ class ProgramRuntime(ComponentBase):
|
||||
self.check_installed_pkgs = kargs.get("check_installed_pkgs", True)
|
||||
|
||||
def _getstartercls(self, start_mode):
|
||||
if(start_mode not in ProgramRuntime.STARTER_CLS_MAPPING):
|
||||
if start_mode not in ProgramRuntime.STARTER_CLS_MAPPING:
|
||||
raise NotImplementedError("Can not yet start %s mode" % (start_mode))
|
||||
return ProgramRuntime.STARTER_CLS_MAPPING.get(start_mode)
|
||||
|
||||
def _getstoppercls(self, stop_mode):
|
||||
if(stop_mode not in ProgramRuntime.STOPPER_CLS_MAPPING):
|
||||
if stop_mode not in ProgramRuntime.STOPPER_CLS_MAPPING:
|
||||
raise NotImplementedError("Can not yet stop %s mode" % (stop_mode))
|
||||
return ProgramRuntime.STOPPER_CLS_MAPPING.get(stop_mode)
|
||||
|
||||
def _was_installed(self):
|
||||
if(not self.check_installed_pkgs):
|
||||
if not self.check_installed_pkgs:
|
||||
return True
|
||||
if(len(self.tracereader.packages_installed())):
|
||||
if len(self.tracereader.packages_installed()):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -349,7 +349,7 @@ class ProgramRuntime(ComponentBase):
|
||||
|
||||
def start(self):
|
||||
#ensure it was installed
|
||||
if(not self._was_installed()):
|
||||
if not self._was_installed():
|
||||
msg = "Can not start %s since it was not installed" % (self.component_name)
|
||||
raise excp.StartException(msg)
|
||||
#select how we are going to start it
|
||||
@ -367,7 +367,7 @@ class ProgramRuntime(ComponentBase):
|
||||
#adjust the program options now that we have real locations
|
||||
params = self._get_param_map(app_name)
|
||||
program_opts = self._get_app_options(app_name)
|
||||
if(params and program_opts):
|
||||
if params and program_opts:
|
||||
adjusted_opts = list()
|
||||
for opt in program_opts:
|
||||
adjusted_opts.append(utils.param_replace(opt, params))
|
||||
@ -376,7 +376,7 @@ class ProgramRuntime(ComponentBase):
|
||||
#start it with the given settings
|
||||
fn = starter.start(app_name, app_pth, *program_opts, app_dir=app_dir, \
|
||||
trace_dir=self.tracedir)
|
||||
if(fn):
|
||||
if fn:
|
||||
fns.append(fn)
|
||||
LOG.info("Started %s, details are in %s" % (app_name, fn))
|
||||
#this trace is used to locate details about what to stop
|
||||
@ -387,7 +387,7 @@ class ProgramRuntime(ComponentBase):
|
||||
|
||||
def stop(self):
|
||||
#ensure it was installed
|
||||
if(not self._was_installed()):
|
||||
if not self._was_installed():
|
||||
msg = "Can not stop %s since it was not installed" % (self.component_name)
|
||||
raise excp.StopException(msg)
|
||||
#we can only stop what has a started trace
|
||||
@ -398,19 +398,19 @@ class ProgramRuntime(ComponentBase):
|
||||
fn = mp.get('trace_fn')
|
||||
name = mp.get('name')
|
||||
#missing some key info, skip it
|
||||
if(fn == None or name == None):
|
||||
if fn == None or name == None:
|
||||
continue
|
||||
#figure out which class will stop it
|
||||
contents = tr.parse_fn(fn)
|
||||
killcls = None
|
||||
runtype = None
|
||||
for (cmd, action) in contents:
|
||||
if(cmd == "TYPE"):
|
||||
if cmd == "TYPE":
|
||||
runtype = action
|
||||
killcls = self._getstoppercls(runtype)
|
||||
break
|
||||
#did we find a class that can do it?
|
||||
if(killcls):
|
||||
if killcls:
|
||||
#we can try to stop it
|
||||
LOG.info("Stopping %s of run type %s" % (name, runtype))
|
||||
#create an instance of the killer class and attempt to stop
|
||||
@ -421,7 +421,7 @@ class ProgramRuntime(ComponentBase):
|
||||
#TODO raise error??
|
||||
pass
|
||||
#if we got rid of them all get rid of the trace
|
||||
if(killedam == len(start_traces)):
|
||||
if killedam == len(start_traces):
|
||||
fn = self.starttracereader.trace_fn
|
||||
LOG.info("Deleting trace file %s" % (fn))
|
||||
sh.unlink(fn)
|
||||
@ -446,10 +446,10 @@ class PythonRuntime(ProgramRuntime):
|
||||
|
||||
def _was_installed(self):
|
||||
parent_result = ProgramRuntime._was_installed(self)
|
||||
if(not parent_result):
|
||||
if not parent_result:
|
||||
return False
|
||||
python_installed = self.tracereader.py_listing()
|
||||
if(len(python_installed) == 0):
|
||||
if len(python_installed) == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
@ -81,7 +81,7 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
#extra actions to ensure we are granted access
|
||||
dbtype = self.cfg.get("db", "type")
|
||||
dbactions = DB_ACTIONS.get(dbtype)
|
||||
if(dbactions and dbactions.get('grant_all')):
|
||||
if dbactions and dbactions.get('grant_all'):
|
||||
#update the DB to give user 'USER'@'%' full control of the all databases:
|
||||
grant_cmd = dbactions.get('grant_all')
|
||||
params = self._get_param_map(None)
|
||||
@ -94,9 +94,9 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
#since python escapes this to much...
|
||||
utils.execute_template(*cmds, params=params, shell=True)
|
||||
#special mysql actions
|
||||
if(dbactions and dbtype == MYSQL):
|
||||
if dbactions and dbtype == MYSQL:
|
||||
cmd = dbactions.get('host_adjust')
|
||||
if(cmd):
|
||||
if cmd:
|
||||
sh.execute(*cmd, run_as_root=True, shell=True)
|
||||
#restart it to make sure all good
|
||||
self.runtime.restart()
|
||||
@ -110,19 +110,19 @@ class DBRuntime(comp.EmptyRuntime):
|
||||
|
||||
def _gettypeactions(self, act, exception_cls):
|
||||
pkgsinstalled = self.tracereader.packages_installed()
|
||||
if(len(pkgsinstalled) == 0):
|
||||
if len(pkgsinstalled) == 0:
|
||||
msg = "Can not %s %s since it was not installed" % (act, TYPE)
|
||||
raise exception_cls(msg)
|
||||
#figure out how to do it
|
||||
dbtype = self.cfg.get("db", "type")
|
||||
typeactions = DB_ACTIONS.get(dbtype)
|
||||
if(typeactions == None or not typeactions.get(act)):
|
||||
if typeactions == None or not typeactions.get(act):
|
||||
msg = BASE_ERROR % (act, dbtype)
|
||||
raise NotImplementedError(msg)
|
||||
return typeactions.get(act)
|
||||
|
||||
def start(self):
|
||||
if(self.status() == comp.STATUS_STOPPED):
|
||||
if self.status() == comp.STATUS_STOPPED:
|
||||
startcmd = self._gettypeactions('start', excp.StartException)
|
||||
sh.execute(*startcmd, run_as_root=True)
|
||||
return 1
|
||||
@ -130,7 +130,7 @@ class DBRuntime(comp.EmptyRuntime):
|
||||
return 0
|
||||
|
||||
def stop(self):
|
||||
if(self.status() == comp.STATUS_STARTED):
|
||||
if self.status() == comp.STATUS_STARTED:
|
||||
stopcmd = self._gettypeactions('stop', excp.StopException)
|
||||
sh.execute(*stopcmd, run_as_root=True)
|
||||
return 1
|
||||
@ -145,9 +145,9 @@ class DBRuntime(comp.EmptyRuntime):
|
||||
def status(self):
|
||||
statuscmd = self._gettypeactions('status', excp.StatusException)
|
||||
(sysout, _) = sh.execute(*statuscmd)
|
||||
if(sysout.find("start/running") != -1):
|
||||
if sysout.find("start/running") != -1:
|
||||
return comp.STATUS_STARTED
|
||||
elif(sysout.find("stop/waiting") != -1):
|
||||
elif sysout.find("stop/waiting") != -1:
|
||||
return comp.STATUS_STOPPED
|
||||
else:
|
||||
return comp.STATUS_UNKNOWN
|
||||
@ -156,7 +156,7 @@ class DBRuntime(comp.EmptyRuntime):
|
||||
def drop_db(cfg, dbname):
|
||||
dbtype = cfg.get("db", "type")
|
||||
dbactions = DB_ACTIONS.get(dbtype)
|
||||
if(dbactions and dbactions.get('drop_db')):
|
||||
if dbactions and dbactions.get('drop_db'):
|
||||
dropcmd = dbactions.get('drop_db')
|
||||
params = dict()
|
||||
params['PASSWORD'] = cfg.get("passwords", "sql")
|
||||
@ -176,7 +176,7 @@ def drop_db(cfg, dbname):
|
||||
def create_db(cfg, dbname):
|
||||
dbtype = cfg.get("db", "type")
|
||||
dbactions = DB_ACTIONS.get(dbtype)
|
||||
if(dbactions and dbactions.get('create_db')):
|
||||
if dbactions and dbactions.get('create_db'):
|
||||
createcmd = dbactions.get('create_db')
|
||||
params = dict()
|
||||
params['PASSWORD'] = cfg.get("passwords", "sql")
|
||||
|
@ -79,7 +79,7 @@ class GlanceRuntime(comp.PythonRuntime):
|
||||
|
||||
def post_start(self):
|
||||
comp.PythonRuntime.post_start(self)
|
||||
if(IMG_START in self.component_opts):
|
||||
if IMG_START in self.component_opts:
|
||||
#install any images that need activating...
|
||||
creator.ImageCreationService(self.cfg).install()
|
||||
|
||||
@ -113,7 +113,7 @@ class GlanceInstaller(comp.PythonInstallComponent):
|
||||
db.create_db(self.cfg, DB_NAME)
|
||||
|
||||
def _config_adjust(self, contents, name):
|
||||
if(name not in CONFIGS):
|
||||
if name not in CONFIGS:
|
||||
return contents
|
||||
#use config parser and
|
||||
#then extract known configs that
|
||||
@ -121,36 +121,36 @@ class GlanceInstaller(comp.PythonInstallComponent):
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config.readfp(stream)
|
||||
if(config.getboolean('image_cache_enabled', CFG_SECTION)):
|
||||
if config.getboolean('image_cache_enabled', CFG_SECTION):
|
||||
cache_dir = config.get("image_cache_datadir", CFG_SECTION)
|
||||
if(cache_dir):
|
||||
if cache_dir:
|
||||
LOG.info("Ensuring image cache data directory %s exists "\
|
||||
"(and is empty)" % (cache_dir))
|
||||
#destroy then recreate the image cache directory
|
||||
sh.deldir(cache_dir)
|
||||
self.tracewriter.make_dir(cache_dir)
|
||||
if(config.get('default_store', CFG_SECTION) == 'file'):
|
||||
if config.get('default_store', CFG_SECTION) == 'file':
|
||||
file_dir = config.get('filesystem_store_datadir', CFG_SECTION)
|
||||
if(file_dir):
|
||||
if file_dir:
|
||||
LOG.info("Ensuring file system store directory %s exists and is empty" % (file_dir))
|
||||
#delete existing images
|
||||
#and recreate the image directory
|
||||
sh.deldir(file_dir)
|
||||
self.tracewriter.make_dir(file_dir)
|
||||
log_filename = config.get('log_file', CFG_SECTION)
|
||||
if(log_filename):
|
||||
if log_filename:
|
||||
LOG.info("Ensuring log file %s exists and is empty" % (log_filename))
|
||||
log_dir = sh.dirname(log_filename)
|
||||
if(log_dir):
|
||||
if log_dir:
|
||||
LOG.info("Ensuring log directory %s exists" % (log_dir))
|
||||
self.tracewriter.make_dir(log_dir)
|
||||
#destroy then recreate it (the log file)
|
||||
sh.unlink(log_filename)
|
||||
sh.touch_file(log_filename)
|
||||
self.tracewriter.file_touched(log_filename)
|
||||
if(config.getboolean('delayed_delete', CFG_SECTION)):
|
||||
if config.getboolean('delayed_delete', CFG_SECTION):
|
||||
data_dir = config.get('scrubber_datadir', CFG_SECTION)
|
||||
if(data_dir):
|
||||
if data_dir:
|
||||
LOG.info("Ensuring scrubber data dir %s exists and is empty" % (data_dir))
|
||||
#destroy then recreate the scrubber data directory
|
||||
sh.deldir(data_dir)
|
||||
|
@ -64,9 +64,9 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
return places
|
||||
|
||||
def _get_target_config_name(self, config_name):
|
||||
if(config_name == HORIZON_PY_CONF):
|
||||
if config_name == HORIZON_PY_CONF:
|
||||
return sh.joinpths(self.dash_dir, *HORIZON_PY_CONF_TGT)
|
||||
elif(config_name == HORIZON_APACHE_CONF):
|
||||
elif config_name == HORIZON_APACHE_CONF:
|
||||
#this may require sudo of the whole program to be able to write here.
|
||||
return sh.joinpths(*HORIZON_APACHE_TGT)
|
||||
else:
|
||||
@ -103,7 +103,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
#Horizon currently imports quantum even if you aren't using it.
|
||||
#Instead of installing quantum we can create a simple module
|
||||
#that will pass the initial imports.
|
||||
if(settings.QUANTUM in self.instances):
|
||||
if settings.QUANTUM in self.instances:
|
||||
return
|
||||
else:
|
||||
#Make the fake quantum
|
||||
@ -122,7 +122,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
def _get_apache_user(self):
|
||||
#TODO will this be the right user?
|
||||
user = self.cfg.get('horizon', 'apache_user')
|
||||
if(not user):
|
||||
if not user:
|
||||
user = sh.getuser()
|
||||
return user
|
||||
|
||||
@ -130,7 +130,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
|
||||
#this dict will be used to fill in the configuration
|
||||
#params with actual values
|
||||
mp = dict()
|
||||
if(config_fn == HORIZON_APACHE_CONF):
|
||||
if config_fn == HORIZON_APACHE_CONF:
|
||||
mp['USER'] = self._get_apache_user()
|
||||
mp['HORIZON_DIR'] = self.appdir
|
||||
else:
|
||||
|
@ -105,7 +105,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
||||
sh.execute(*setup_cmd, env_overrides=env)
|
||||
|
||||
def _config_adjust(self, contents, name):
|
||||
if(name not in CONFIGS):
|
||||
if name not in CONFIGS:
|
||||
return contents
|
||||
#use config parser and
|
||||
#then extract known configs that
|
||||
@ -114,10 +114,10 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config.readfp(stream)
|
||||
log_filename = config.get('log_file', CFG_SECTION)
|
||||
if(log_filename):
|
||||
if log_filename:
|
||||
LOG.info("Ensuring log file %s exists and is empty" % (log_filename))
|
||||
log_dir = sh.dirname(log_filename)
|
||||
if(log_dir):
|
||||
if log_dir:
|
||||
LOG.info("Ensuring log directory %s exists" % (log_dir))
|
||||
self.tracewriter.make_dir(log_dir)
|
||||
#destroy then recreate it (the log file)
|
||||
@ -132,13 +132,13 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
||||
#these be used to fill in the configuration/cmds +
|
||||
#params with actual values
|
||||
mp = dict()
|
||||
if(config_fn == ROOT_CONF):
|
||||
if config_fn == ROOT_CONF:
|
||||
host_ip = self.cfg.get('host', 'ip')
|
||||
mp['DEST'] = self.appdir
|
||||
mp['SQL_CONN'] = self.cfg.get_dbdsn(DB_NAME)
|
||||
mp['SERVICE_HOST'] = host_ip
|
||||
mp['ADMIN_HOST'] = host_ip
|
||||
elif(config_fn == MANAGE_DATA_CONF):
|
||||
elif config_fn == MANAGE_DATA_CONF:
|
||||
host_ip = self.cfg.get('host', 'ip')
|
||||
mp['ADMIN_PASSWORD'] = self.cfg.get('passwords', 'horizon_keystone_admin')
|
||||
mp['SERVICE_HOST'] = host_ip
|
||||
@ -173,13 +173,13 @@ def get_shared_params(cfg):
|
||||
mp = dict()
|
||||
host_ip = cfg.get('host', 'ip')
|
||||
keystone_auth_host = cfg.get('keystone', 'keystone_auth_host')
|
||||
if(not keystone_auth_host):
|
||||
if not keystone_auth_host:
|
||||
keystone_auth_host = host_ip
|
||||
mp['KEYSTONE_AUTH_HOST'] = keystone_auth_host
|
||||
mp['KEYSTONE_AUTH_PORT'] = cfg.get('keystone', 'keystone_auth_port')
|
||||
mp['KEYSTONE_AUTH_PROTOCOL'] = cfg.get('keystone', 'keystone_auth_protocol')
|
||||
keystone_service_host = cfg.get('keystone', 'keystone_service_host')
|
||||
if(not keystone_service_host):
|
||||
if not keystone_service_host:
|
||||
keystone_service_host = host_ip
|
||||
mp['KEYSTONE_SERVICE_HOST'] = keystone_service_host
|
||||
mp['KEYSTONE_SERVICE_PORT'] = cfg.get('keystone', 'keystone_service_port')
|
||||
|
@ -70,7 +70,7 @@ class NoVNCRuntime(comp.ProgramRuntime):
|
||||
|
||||
def _get_param_map(self, app_name):
|
||||
root_params = comp.ProgramRuntime._get_param_map(self, app_name)
|
||||
if(app_name == VNC_PROXY_APP and settings.NOVA in self.instances):
|
||||
if app_name == VNC_PROXY_APP and settings.NOVA in self.instances:
|
||||
nova_runtime = self.instances.get(settings.NOVA)
|
||||
root_params['NOVA_CONF'] = sh.joinpths(nova_runtime.cfgdir, nova.API_CONF)
|
||||
return root_params
|
||||
|
@ -64,7 +64,7 @@ class RabbitRuntime(comp.EmptyRuntime):
|
||||
self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
|
||||
|
||||
def start(self):
|
||||
if(self.status() == comp.STATUS_STOPPED):
|
||||
if self.status() == comp.STATUS_STOPPED:
|
||||
self._run_cmd(START_CMD)
|
||||
return 1
|
||||
else:
|
||||
@ -72,7 +72,7 @@ class RabbitRuntime(comp.EmptyRuntime):
|
||||
|
||||
def status(self):
|
||||
pkgsinstalled = self.tracereader.packages_installed()
|
||||
if(len(pkgsinstalled) == 0):
|
||||
if len(pkgsinstalled) == 0:
|
||||
msg = "Can not check the status of %s since it was not installed" % (TYPE)
|
||||
raise excp.StatusException(msg)
|
||||
#this has got to be the worst status output
|
||||
@ -80,15 +80,15 @@ class RabbitRuntime(comp.EmptyRuntime):
|
||||
(sysout, _) = sh.execute(*STATUS_CMD,
|
||||
run_as_root=True,
|
||||
check_exit_code=False)
|
||||
if(sysout.find('nodedown') != -1 or sysout.find("unable to connect to node") != -1):
|
||||
if sysout.find('nodedown') != -1 or sysout.find("unable to connect to node") != -1:
|
||||
return comp.STATUS_STOPPED
|
||||
elif(sysout.find('running_applications') != -1):
|
||||
elif sysout.find('running_applications') != -1:
|
||||
return comp.STATUS_STARTED
|
||||
else:
|
||||
return comp.STATUS_UNKNOWN
|
||||
|
||||
def _run_cmd(self, cmd):
|
||||
if(self.distro == settings.UBUNTU11):
|
||||
if self.distro == settings.UBUNTU11:
|
||||
#this seems to fix one of the bugs with rabbit mq starting and stopping
|
||||
#not cool, possibly connected to the following bugs:
|
||||
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
|
||||
@ -104,7 +104,7 @@ class RabbitRuntime(comp.EmptyRuntime):
|
||||
return 1
|
||||
|
||||
def stop(self):
|
||||
if(self.status() == comp.STATUS_STARTED):
|
||||
if self.status() == comp.STATUS_STARTED:
|
||||
self._run_cmd(STOP_CMD)
|
||||
return 1
|
||||
else:
|
||||
|
@ -32,7 +32,7 @@ def _gitdownload(storewhere, uri, branch=None):
|
||||
LOG.info("Downloading from %s to %s" % (uri, storewhere))
|
||||
cmd = ["git", "clone"] + [uri, storewhere]
|
||||
sh.execute(*cmd)
|
||||
if(branch and branch != GIT_MASTER_BRANCH):
|
||||
if branch and branch != GIT_MASTER_BRANCH:
|
||||
LOG.info("Adjusting git branch to %s" % (branch))
|
||||
cmd = ['git', 'checkout'] + [branch]
|
||||
sh.execute(*cmd, cwd=storewhere)
|
||||
@ -42,8 +42,8 @@ def _gitdownload(storewhere, uri, branch=None):
|
||||
def download(storewhere, uri, branch=None):
|
||||
#figure out which type
|
||||
up = urlparse(uri)
|
||||
if(up and up.scheme.lower() == "git" or
|
||||
EXT_REG.match(up.path)):
|
||||
if up and up.scheme.lower() == "git" or
|
||||
EXT_REG.match(up.path):
|
||||
return _gitdownload(storewhere, uri, branch)
|
||||
else:
|
||||
msg = "Currently we do not know how to download %s" % (uri)
|
||||
|
@ -22,7 +22,7 @@ LOG = logging.getLogger("devstack.environment")
|
||||
|
||||
|
||||
def _str2bool(value_str):
|
||||
if(value_str.lower().strip() in TRUE_VALUES):
|
||||
if value_str.lower().strip() in TRUE_VALUES:
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -34,7 +34,7 @@ def get():
|
||||
def get_key(key, default_value=None):
|
||||
LOG.debug("Looking up environment variable \"%s\"" % (key))
|
||||
value = get().get(key)
|
||||
if(value == None):
|
||||
if value == None:
|
||||
LOG.debug("Could not find anything in environment variable \"%s\"" % (key))
|
||||
value = default_value
|
||||
else:
|
||||
@ -44,6 +44,6 @@ def get_key(key, default_value=None):
|
||||
|
||||
def get_bool(key, default_value=False):
|
||||
value = get_key(key, None)
|
||||
if(value == None):
|
||||
if value == None:
|
||||
return default_value
|
||||
return _str2bool(value)
|
||||
|
@ -204,17 +204,17 @@ class ImageCreationService:
|
||||
try:
|
||||
token = self.cfg.get("passwords", "service_token")
|
||||
flat_urls = self.cfg.get('img', 'image_urls')
|
||||
if(flat_urls):
|
||||
if flat_urls:
|
||||
expanded_urls = [x.strip() for x in flat_urls.split(',')]
|
||||
for url in expanded_urls:
|
||||
if(url):
|
||||
if url:
|
||||
urls.append(url)
|
||||
except(ConfigParser.Error):
|
||||
LOG.info("No image configuration keys found, skipping glance image install")
|
||||
|
||||
#install them in glance
|
||||
am_installed = 0
|
||||
if(urls):
|
||||
if urls:
|
||||
LOG.info("Attempting to download & extract and upload (%s) images." % (", ".join(urls)))
|
||||
for url in urls:
|
||||
try:
|
||||
|
@ -29,15 +29,15 @@ class TermFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
lvl = record.levelno
|
||||
lvlname = record.levelname
|
||||
if(lvl == logging.DEBUG):
|
||||
if lvl == logging.DEBUG:
|
||||
lvlname = colored(lvlname, 'blue')
|
||||
elif(lvl == logging.INFO):
|
||||
elif lvl == logging.INFO:
|
||||
lvlname = colored(lvlname, 'cyan')
|
||||
elif(lvl == logging.WARNING):
|
||||
elif lvl == logging.WARNING:
|
||||
lvlname = colored(lvlname, 'yellow')
|
||||
elif(lvl == logging.ERROR):
|
||||
elif lvl == logging.ERROR:
|
||||
lvlname = colored(lvlname, 'red')
|
||||
elif(lvl == logging.CRITICAL):
|
||||
elif lvl == logging.CRITICAL:
|
||||
lvlname = colored(lvlname, 'red')
|
||||
record.msg = colored(record.msg, attrs=['bold', 'blink'])
|
||||
record.levelname = lvlname
|
||||
@ -55,9 +55,9 @@ class TermHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
lvl = record.levelno
|
||||
msg = self.format(record)
|
||||
if(len(msg)):
|
||||
if len(msg):
|
||||
TermHandler.STREAM.write(msg + TermHandler.NL)
|
||||
if(TermHandler.DO_FLUSH):
|
||||
if TermHandler.DO_FLUSH:
|
||||
TermHandler.STREAM.flush()
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ def parse():
|
||||
output['action'] = options.action
|
||||
output['list_deps'] = options.list_deps
|
||||
output['force'] = options.force
|
||||
if(options.ensure_deps):
|
||||
if options.ensure_deps:
|
||||
output['ignore_deps'] = False
|
||||
else:
|
||||
output['ignore_deps'] = True
|
||||
|
@ -35,7 +35,7 @@ class Packager(object):
|
||||
for name in pkgnames:
|
||||
packageinfo = pkgs.get(name)
|
||||
preinstallcmds = packageinfo.get(settings.PRE_INSTALL)
|
||||
if(preinstallcmds and len(preinstallcmds)):
|
||||
if preinstallcmds and len(preinstallcmds):
|
||||
LOG.info("Running pre-install commands for package %s." % (name))
|
||||
utils.execute_template(*preinstallcmds, params=installparams)
|
||||
|
||||
@ -44,6 +44,6 @@ class Packager(object):
|
||||
for name in pkgnames:
|
||||
packageinfo = pkgs.get(name)
|
||||
postinstallcmds = packageinfo.get(settings.POST_INSTALL)
|
||||
if(postinstallcmds and len(postinstallcmds)):
|
||||
if postinstallcmds and len(postinstallcmds):
|
||||
LOG.info("Running post-install commands for package %s." % (name))
|
||||
utils.execute_template(*postinstallcmds, params=installparams)
|
||||
|
@ -48,7 +48,7 @@ class AptPackager(pack.Packager):
|
||||
return VERSION_TEMPL % (name, version)
|
||||
|
||||
def _format_pkg(self, name, version):
|
||||
if(version and len(version)):
|
||||
if version and len(version):
|
||||
cmd = self._format_version(name, version)
|
||||
else:
|
||||
cmd = name
|
||||
@ -68,16 +68,16 @@ class AptPackager(pack.Packager):
|
||||
for name in pkgnames:
|
||||
info = pkgs.get(name) or {}
|
||||
removable = info.get('removable', True)
|
||||
if(not removable):
|
||||
if not removable:
|
||||
continue
|
||||
if(self._pkg_remove_special(name, info)):
|
||||
if self._pkg_remove_special(name, info):
|
||||
which_removed.append(name)
|
||||
continue
|
||||
pkg_full = self._format_pkg(name, info.get("version"))
|
||||
if(pkg_full):
|
||||
if pkg_full:
|
||||
cmds.append(pkg_full)
|
||||
which_removed.append(name)
|
||||
if(len(cmds)):
|
||||
if len(cmds):
|
||||
cmd = APT_GET + APT_DO_REMOVE + cmds
|
||||
self._execute_apt(cmd)
|
||||
#clean them out
|
||||
@ -91,17 +91,17 @@ class AptPackager(pack.Packager):
|
||||
cmds = []
|
||||
for name in pkgnames:
|
||||
info = pkgs.get(name) or {}
|
||||
if(self._pkg_install_special(name, info)):
|
||||
if self._pkg_install_special(name, info):
|
||||
continue
|
||||
pkg_full = self._format_pkg(name, info.get("version"))
|
||||
cmds.append(pkg_full)
|
||||
#install them
|
||||
if(len(cmds)):
|
||||
if len(cmds):
|
||||
cmd = APT_GET + APT_INSTALL + cmds
|
||||
self._execute_apt(cmd)
|
||||
|
||||
def _pkg_remove_special(self, name, pkginfo):
|
||||
if(name == 'rabbitmq-server' and self.distro == settings.UBUNTU11):
|
||||
if name == 'rabbitmq-server' and self.distro == settings.UBUNTU11:
|
||||
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
|
||||
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878600
|
||||
LOG.info("Handling special remove of %s." % (name))
|
||||
@ -117,7 +117,7 @@ class AptPackager(pack.Packager):
|
||||
return False
|
||||
|
||||
def _pkg_install_special(self, name, pkginfo):
|
||||
if(name == 'rabbitmq-server' and self.distro == settings.UBUNTU11):
|
||||
if name == 'rabbitmq-server' and self.distro == settings.UBUNTU11:
|
||||
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
|
||||
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878600
|
||||
LOG.info("Handling special install of %s." % (name))
|
||||
|
@ -35,7 +35,7 @@ class YumPackager(pack.Packager):
|
||||
pack.Packager.__init__(self, distro)
|
||||
|
||||
def _format_pkg_name(self, name, version):
|
||||
if(version != None and len(version)):
|
||||
if version != None and len(version):
|
||||
return VERSION_TEMPL % (name, version)
|
||||
else:
|
||||
return name
|
||||
@ -56,12 +56,12 @@ class YumPackager(pack.Packager):
|
||||
pkg_full_names = list()
|
||||
for name in pkg_names:
|
||||
info = pkgs.get(name) or {}
|
||||
if(self._install_special(name, info)):
|
||||
if self._install_special(name, info):
|
||||
continue
|
||||
full_pkg_name = self._format_pkg_name(name, info.get("version"))
|
||||
if(full_pkg_name):
|
||||
if full_pkg_name:
|
||||
pkg_full_names.append(full_pkg_name)
|
||||
if(len(pkg_full_names)):
|
||||
if len(pkg_full_names):
|
||||
cmd = YUM_CMD + YUM_INSTALL + pkg_full_names
|
||||
self._execute_yum(cmd)
|
||||
|
||||
@ -72,16 +72,16 @@ class YumPackager(pack.Packager):
|
||||
for name in pkg_names:
|
||||
info = pkgs.get(name) or {}
|
||||
removable = info.get('removable', True)
|
||||
if(not removable):
|
||||
if not removable:
|
||||
continue
|
||||
if(self._remove_special(name, info)):
|
||||
if self._remove_special(name, info):
|
||||
which_removed.append(name)
|
||||
continue
|
||||
full_pkg_name = self._format_pkg_name(name, info.get("version"))
|
||||
if(full_pkg_name):
|
||||
if full_pkg_name:
|
||||
pkg_full_names.append(full_pkg_name)
|
||||
which_removed.append(name)
|
||||
if(len(pkg_full_names)):
|
||||
if len(pkg_full_names):
|
||||
cmd = YUM_CMD + YUM_REMOVE + pkg_full_names
|
||||
self._execute_yum(cmd)
|
||||
return which_removed
|
||||
|
@ -25,26 +25,26 @@ UNINSTALL_CMD = ['pip', 'uninstall']
|
||||
|
||||
|
||||
def install(pips):
|
||||
if(not pips or len(pips) == 0):
|
||||
if not pips or len(pips) == 0:
|
||||
return
|
||||
actions = list()
|
||||
pipnames = sorted(pips.keys())
|
||||
for name in pipnames:
|
||||
pipfull = name
|
||||
pipinfo = pips.get(name)
|
||||
if(pipinfo and pipinfo.get('version')):
|
||||
if pipinfo and pipinfo.get('version'):
|
||||
version = str(pipinfo.get('version'))
|
||||
if(len(version)):
|
||||
if len(version):
|
||||
pipfull = pipfull + "==" + version
|
||||
actions.append(pipfull)
|
||||
if(len(actions)):
|
||||
if len(actions):
|
||||
LOG.info("Installing python packages [%s]" % (", ".join(actions)))
|
||||
cmd = INSTALL_CMD + actions
|
||||
sh.execute(*cmd, run_as_root=True)
|
||||
|
||||
|
||||
def uninstall(pips):
|
||||
if(not pips or len(pips) == 0):
|
||||
if not pips or len(pips) == 0:
|
||||
return
|
||||
pipnames = sorted(pips.keys())
|
||||
LOG.info("Uninstalling python packages [%s]" % (", ".join(pipnames)))
|
||||
@ -55,7 +55,7 @@ def uninstall(pips):
|
||||
cmd = UNINSTALL_CMD + [name]
|
||||
sh.execute(*cmd, run_as_root=True)
|
||||
except excp.ProcessExecutionError:
|
||||
if(skip_errors):
|
||||
if skip_errors:
|
||||
LOG.exception("Ignoring execution error that occured when uninstalling %s!" % (name))
|
||||
else:
|
||||
raise
|
||||
|
@ -117,10 +117,10 @@ _ACTION_CLASSES = {
|
||||
|
||||
|
||||
def _clean_action(action):
|
||||
if(action == None):
|
||||
if action == None:
|
||||
return None
|
||||
action = action.strip().lower()
|
||||
if(not (action in settings.ACTIONS)):
|
||||
if not (action in settings.ACTIONS):
|
||||
return None
|
||||
return action
|
||||
|
||||
@ -132,18 +132,18 @@ def _get_pkg_manager(distro):
|
||||
|
||||
def _get_action_cls(action_name, component_name):
|
||||
action_cls_map = _ACTION_CLASSES.get(action_name)
|
||||
if(not action_cls_map):
|
||||
if not action_cls_map:
|
||||
return None
|
||||
return action_cls_map.get(component_name)
|
||||
|
||||
|
||||
def _check_root(action, rootdir):
|
||||
if(rootdir == None or len(rootdir) == 0):
|
||||
if rootdir == None or len(rootdir) == 0:
|
||||
return False
|
||||
if(action == settings.INSTALL):
|
||||
if(sh.isdir(rootdir)):
|
||||
if action == settings.INSTALL:
|
||||
if sh.isdir(rootdir):
|
||||
dir_list = sh.listdir(rootdir)
|
||||
if(len(dir_list) > 0):
|
||||
if len(dir_list) > 0:
|
||||
LOG.error("Root directory [%s] already exists (and it's not empty)! "\
|
||||
"Please remove it or uninstall components!" % (rootdir))
|
||||
return False
|
||||
@ -151,16 +151,16 @@ def _check_root(action, rootdir):
|
||||
|
||||
|
||||
def _pre_run(action_name, **kargs):
|
||||
if(action_name == settings.INSTALL):
|
||||
if action_name == settings.INSTALL:
|
||||
root_dir = kargs.get("root_dir")
|
||||
if(root_dir):
|
||||
if root_dir:
|
||||
sh.mkdir(root_dir)
|
||||
|
||||
|
||||
def _post_run(action_name, **kargs):
|
||||
if(action_name == settings.UNINSTALL):
|
||||
if action_name == settings.UNINSTALL:
|
||||
root_dir = kargs.get("root_dir")
|
||||
if(root_dir):
|
||||
if root_dir:
|
||||
sh.rmdir(root_dir)
|
||||
|
||||
|
||||
@ -179,23 +179,23 @@ def _print_cfgs(config_obj, action):
|
||||
passwords_gotten = config_obj.pws
|
||||
full_cfgs = config_obj.configs_fetched
|
||||
db_dsns = config_obj.db_dsns
|
||||
if(len(passwords_gotten) or len(full_cfgs) or len(db_dsns)):
|
||||
if len(passwords_gotten) or len(full_cfgs) or len(db_dsns):
|
||||
LOG.info("After action (%s) your settings are:" % (action))
|
||||
if(len(passwords_gotten)):
|
||||
if len(passwords_gotten):
|
||||
LOG.info("Passwords:")
|
||||
map_print(passwords_gotten)
|
||||
if(len(full_cfgs)):
|
||||
if len(full_cfgs):
|
||||
#TODO
|
||||
#better way to do this?? (ie a list difference?)
|
||||
filtered_mp = dict()
|
||||
for key in full_cfgs.keys():
|
||||
if(key in passwords_gotten):
|
||||
if key in passwords_gotten:
|
||||
continue
|
||||
filtered_mp[key] = full_cfgs.get(key)
|
||||
if(len(filtered_mp)):
|
||||
if len(filtered_mp):
|
||||
LOG.info("Configs:")
|
||||
map_print(filtered_mp)
|
||||
if(len(db_dsns)):
|
||||
if len(db_dsns):
|
||||
LOG.info("Data source names:")
|
||||
map_print(db_dsns)
|
||||
|
||||
@ -213,7 +213,7 @@ def _install(component_name, instance):
|
||||
instance.install()
|
||||
LOG.info("Post-installing %s." % (component_name))
|
||||
trace = instance.post_install()
|
||||
if(trace):
|
||||
if trace:
|
||||
LOG.info("Finished install of %s - check %s for traces of what happened." % (component_name, trace))
|
||||
else:
|
||||
LOG.info("Finished install of %s" % (component_name))
|
||||
@ -227,7 +227,7 @@ def _stop(component_name, instance, skip_notrace):
|
||||
LOG.info("Stopped %s items." % (stop_amount))
|
||||
LOG.info("Finished stop of %s" % (component_name))
|
||||
except excp.NoTraceException, e:
|
||||
if(skip_notrace):
|
||||
if skip_notrace:
|
||||
LOG.info("Passing on stopping %s since no trace file was found." % (component_name))
|
||||
else:
|
||||
raise
|
||||
@ -240,9 +240,9 @@ def _start(component_name, instance):
|
||||
start_info = instance.start()
|
||||
LOG.info("Post-starting %s." % (component_name))
|
||||
instance.post_start()
|
||||
if(type(start_info) == list):
|
||||
if type(start_info) == list:
|
||||
LOG.info("Check [%s] for traces of what happened." % (", ".join(start_info)))
|
||||
elif(type(start_info) == int):
|
||||
elif type(start_info) == int:
|
||||
LOG.info("Started %s applications." % (start_info))
|
||||
start_info = None
|
||||
LOG.info("Finished start of %s." % (component_name))
|
||||
@ -256,7 +256,7 @@ def _uninstall(component_name, instance, skip_notrace):
|
||||
LOG.info("Uninstalling %s." % (component_name))
|
||||
instance.uninstall()
|
||||
except excp.NoTraceException, e:
|
||||
if(skip_notrace):
|
||||
if skip_notrace:
|
||||
LOG.info("Passing on uninstalling %s since no trace file was found." % (component_name))
|
||||
else:
|
||||
raise
|
||||
@ -273,7 +273,7 @@ def _get_config():
|
||||
def _run_components(action_name, component_order, components, distro, root_dir, program_args):
|
||||
LOG.info("Will %s [%s] (in that order) using root directory \"%s\"" % (action_name, ", ".join(component_order), root_dir))
|
||||
non_components = set(components.keys()).difference(set(component_order))
|
||||
if(non_components):
|
||||
if non_components:
|
||||
LOG.info("Using reference components [%s]" % (", ".join(sorted(non_components))))
|
||||
pkg_manager = _get_pkg_manager(distro)
|
||||
config = _get_config()
|
||||
@ -295,23 +295,23 @@ def _run_components(action_name, component_order, components, distro, root_dir,
|
||||
#this instance was just made
|
||||
instance = all_instances.get(component)
|
||||
#activate the correct function for the given action
|
||||
if(action_name == settings.INSTALL):
|
||||
if action_name == settings.INSTALL:
|
||||
install_result = _install(component, instance)
|
||||
if install_result:
|
||||
if type(install_result) == list:
|
||||
results += install_result
|
||||
else:
|
||||
results.append(str(install_result))
|
||||
elif(action_name == settings.STOP):
|
||||
elif action_name == settings.STOP:
|
||||
_stop(component, instance, program_args.get('force', False))
|
||||
elif(action_name == settings.START):
|
||||
elif action_name == settings.START:
|
||||
start_result = _start(component, instance)
|
||||
if start_result:
|
||||
if type(start_result) == list:
|
||||
results += start_result
|
||||
else:
|
||||
results.append(str(start_result))
|
||||
elif(action_name == settings.UNINSTALL):
|
||||
elif action_name == settings.UNINSTALL:
|
||||
_uninstall(component, instance, program_args.get('force', False))
|
||||
else:
|
||||
#TODO throw?
|
||||
@ -325,30 +325,30 @@ def _run_components(action_name, component_order, components, distro, root_dir,
|
||||
|
||||
def _run_action(args):
|
||||
components = settings.parse_components(args.pop("components"))
|
||||
if(len(components) == 0):
|
||||
if len(components) == 0:
|
||||
LOG.error("No components specified!")
|
||||
return False
|
||||
action = _clean_action(args.pop("action"))
|
||||
if(not action):
|
||||
if not action:
|
||||
LOG.error("No valid action specified!")
|
||||
return False
|
||||
rootdir = args.pop("dir")
|
||||
if(not _check_root(action, rootdir)):
|
||||
if not _check_root(action, rootdir):
|
||||
LOG.error("No valid root directory specified!")
|
||||
return False
|
||||
#ensure os/distro is known
|
||||
(distro, platform) = utils.determine_distro()
|
||||
if(distro == None):
|
||||
if distro == None:
|
||||
LOG.error("Unsupported platform: %s" % (platform))
|
||||
return False
|
||||
#start it
|
||||
utils.welcome(_WELCOME_MAP.get(action))
|
||||
#need to figure out dependencies for components (if any)
|
||||
ignore_deps = args.pop('ignore_deps', False)
|
||||
if(not ignore_deps):
|
||||
if not ignore_deps:
|
||||
new_components = settings.resolve_dependencies(components.keys())
|
||||
component_diff = new_components.difference(components.keys())
|
||||
if(len(component_diff)):
|
||||
if len(component_diff):
|
||||
LOG.info("Having to activate dependent components: [%s]" % (", ".join(component_diff)))
|
||||
for new_component in component_diff:
|
||||
components[new_component] = list()
|
||||
@ -357,13 +357,13 @@ def _run_action(args):
|
||||
#add in any that will just be referenced but which will not actually do anything (ie the action will not be applied to these)
|
||||
ref_components = settings.parse_components(args.pop("ref_components"))
|
||||
for c in ref_components.keys():
|
||||
if(c not in components):
|
||||
if c not in components:
|
||||
components[c] = ref_components.get(c)
|
||||
#now do it!
|
||||
LOG.info("Starting action [%s] on %s for distro [%s]" % (action, date.rcf8222date(), distro))
|
||||
results = _run_components(action, component_order, components, distro, rootdir, args)
|
||||
LOG.info("Finished action [%s] on %s" % (action, date.rcf8222date()))
|
||||
if(results):
|
||||
if results:
|
||||
LOG.info('Check [%s] for traces of what happened.' % ", ".join(results))
|
||||
return True
|
||||
|
||||
|
@ -29,19 +29,19 @@ def log_deps(components):
|
||||
deps = settings.get_dependencies(c)
|
||||
dep_str = ""
|
||||
dep_len = len(deps)
|
||||
if(dep_len >= 1):
|
||||
if dep_len >= 1:
|
||||
dep_str = "component"
|
||||
if(dep_len > 1):
|
||||
if dep_len > 1:
|
||||
dep_str += "s"
|
||||
dep_str += ":"
|
||||
elif(dep_len == 0):
|
||||
elif dep_len == 0:
|
||||
dep_str = "no components."
|
||||
LOG.info("%s depends on %s" % (c, dep_str))
|
||||
for d in deps:
|
||||
LOG.info("\t%s" % (d))
|
||||
shown.add(c)
|
||||
for d in deps:
|
||||
if(d not in shown and d not in left_show):
|
||||
if d not in shown and d not in left_show:
|
||||
left_show.append(d)
|
||||
return True
|
||||
|
||||
|
@ -71,17 +71,17 @@ class ForkRunner(object):
|
||||
|
||||
def stop(self, name, *args, **kargs):
|
||||
trace_dir = kargs.get("trace_dir")
|
||||
if(not trace_dir or not sh.isdir(trace_dir)):
|
||||
if not trace_dir or not sh.isdir(trace_dir):
|
||||
msg = "No trace directory found from which to stop %s" % (name)
|
||||
raise excp.StopException(msg)
|
||||
fn_name = FORK_TEMPL % (name)
|
||||
(pid_file, stderr_fn, stdout_fn) = self._form_file_names(trace_dir, fn_name)
|
||||
trace_fn = tr.trace_fn(trace_dir, fn_name)
|
||||
if(sh.isfile(pid_file) and sh.isfile(trace_fn)):
|
||||
if sh.isfile(pid_file) and sh.isfile(trace_fn):
|
||||
pid = int(sh.load_file(pid_file).strip())
|
||||
(killed, attempts) = self._stop_pid(pid)
|
||||
#trash the files
|
||||
if(killed):
|
||||
if killed:
|
||||
LOG.info("Killed pid %s after %s attempts" % (pid, attempts))
|
||||
LOG.info("Removing pid file %s" % (pid_file))
|
||||
sh.unlink(pid_file)
|
||||
@ -107,7 +107,7 @@ class ForkRunner(object):
|
||||
def _fork_start(self, program, appdir, pid_fn, stdout_fn, stderr_fn, *args):
|
||||
#first child, not the real program
|
||||
pid = os.fork()
|
||||
if(pid == 0):
|
||||
if pid == 0:
|
||||
#upon return the calling process shall be the session
|
||||
#leader of this new session,
|
||||
#shall be the process group leader of a new process group,
|
||||
@ -116,14 +116,14 @@ class ForkRunner(object):
|
||||
pid = os.fork()
|
||||
#fork to get daemon out - this time under init control
|
||||
#and now fully detached (no shell possible)
|
||||
if(pid == 0):
|
||||
if pid == 0:
|
||||
#move to where application should be
|
||||
if(appdir):
|
||||
if appdir:
|
||||
os.chdir(appdir)
|
||||
#close other fds
|
||||
limits = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||
mkfd = limits[1]
|
||||
if(mkfd == resource.RLIM_INFINITY):
|
||||
if mkfd == resource.RLIM_INFINITY:
|
||||
mkfd = MAXFD
|
||||
for fd in range(0, mkfd):
|
||||
try:
|
||||
@ -132,10 +132,10 @@ class ForkRunner(object):
|
||||
#not open, thats ok
|
||||
pass
|
||||
#now adjust stderr and stdout
|
||||
if(stdout_fn):
|
||||
if stdout_fn:
|
||||
stdoh = open(stdout_fn, "w")
|
||||
os.dup2(stdoh.fileno(), sys.stdout.fileno())
|
||||
if(stderr_fn):
|
||||
if stderr_fn:
|
||||
stdeh = open(stderr_fn, "w")
|
||||
os.dup2(stdeh.fileno(), sys.stderr.fileno())
|
||||
#now exec...
|
||||
|
@ -43,10 +43,10 @@ class ScreenRunner(object):
|
||||
lookfor = r"^(\d+\." + re.escape(real_name) + r")\s+(.*)$"
|
||||
for line in lines:
|
||||
cleaned_line = line.strip()
|
||||
if(len(cleaned_line) == 0):
|
||||
if len(cleaned_line) == 0:
|
||||
continue
|
||||
mtch = re.match(lookfor, cleaned_line)
|
||||
if(not mtch):
|
||||
if not mtch:
|
||||
continue
|
||||
kill_entry = mtch.group(1)
|
||||
entries.append(kill_entry)
|
||||
|
@ -238,7 +238,7 @@ def resolve_dependencies(components):
|
||||
component_deps = get_dependencies(curr_comp)
|
||||
new_components.add(curr_comp)
|
||||
for c in component_deps:
|
||||
if(c in new_components or c in active_components):
|
||||
if c in new_components or c in active_components:
|
||||
pass
|
||||
else:
|
||||
active_components.append(c)
|
||||
@ -250,7 +250,7 @@ def prioritize_components(components):
|
||||
mporder = dict()
|
||||
for c in components:
|
||||
priority = COMPONENT_NAMES_PRIORITY.get(c)
|
||||
if(priority == None):
|
||||
if priority == None:
|
||||
priority = sys.maxint
|
||||
mporder[c] = priority
|
||||
#sort by priority value
|
||||
@ -262,31 +262,31 @@ def prioritize_components(components):
|
||||
|
||||
def parse_components(components, assume_all=False):
|
||||
#none provided, init it
|
||||
if(not components):
|
||||
if not components:
|
||||
components = list()
|
||||
adjusted_components = dict()
|
||||
for c in components:
|
||||
mtch = EXT_COMPONENT.match(c)
|
||||
if(mtch):
|
||||
if mtch:
|
||||
component_name = mtch.group(1).lower().strip()
|
||||
if(component_name not in COMPONENT_NAMES):
|
||||
if component_name not in COMPONENT_NAMES:
|
||||
LOG.warn("Unknown component named %s" % (component_name))
|
||||
else:
|
||||
component_opts = mtch.group(2)
|
||||
components_opts_cleaned = list()
|
||||
if(component_opts == None or len(component_opts) == 0):
|
||||
if component_opts == None or len(component_opts) == 0:
|
||||
pass
|
||||
else:
|
||||
sp_component_opts = component_opts.split(",")
|
||||
for co in sp_component_opts:
|
||||
cleaned_opt = co.strip()
|
||||
if(len(cleaned_opt)):
|
||||
if len(cleaned_opt):
|
||||
components_opts_cleaned.append(cleaned_opt)
|
||||
adjusted_components[component_name] = components_opts_cleaned
|
||||
else:
|
||||
LOG.warn("Unparseable component %s" % (c))
|
||||
#should we adjust them to be all the components?
|
||||
if(len(adjusted_components) == 0 and assume_all):
|
||||
if len(adjusted_components) == 0 and assume_all:
|
||||
all_components = dict()
|
||||
for c in COMPONENT_NAMES:
|
||||
all_components[c] = list()
|
||||
|
@ -37,10 +37,10 @@ def execute(*cmd, **kwargs):
|
||||
env_overrides = kwargs.pop('env_overrides', None)
|
||||
ignore_exit_code = False
|
||||
|
||||
if(isinstance(check_exit_code, bool)):
|
||||
if isinstance(check_exit_code, bool):
|
||||
ignore_exit_code = not check_exit_code
|
||||
check_exit_code = [0]
|
||||
elif(isinstance(check_exit_code, int)):
|
||||
elif isinstance(check_exit_code, int):
|
||||
check_exit_code = [check_exit_code]
|
||||
|
||||
run_as_root = kwargs.pop('run_as_root', False)
|
||||
@ -49,16 +49,16 @@ def execute(*cmd, **kwargs):
|
||||
cmd = ROOT_HELPER + list(cmd)
|
||||
|
||||
cmd = [str(c) for c in cmd]
|
||||
if(shell):
|
||||
if shell:
|
||||
cmd = " ".join(cmd)
|
||||
LOG.debug('Running shell cmd: [%s]' % (cmd))
|
||||
else:
|
||||
LOG.debug('Running cmd: [%s]' % (' '.join(cmd)))
|
||||
|
||||
if(process_input != None):
|
||||
if process_input != None:
|
||||
LOG.debug('With stdin: %s' % (process_input))
|
||||
|
||||
if(cwd):
|
||||
if cwd:
|
||||
LOG.debug("In working directory: %s" % (cwd))
|
||||
|
||||
stdin_fh = subprocess.PIPE
|
||||
@ -66,22 +66,22 @@ def execute(*cmd, **kwargs):
|
||||
stderr_fh = subprocess.PIPE
|
||||
close_file_descriptors = True
|
||||
|
||||
if('stdout_fh' in kwargs.keys()):
|
||||
if 'stdout_fh' in kwargs.keys():
|
||||
stdout_fh = kwargs.get('stdout_fh')
|
||||
LOG.debug("Redirecting stdout to file handle: %s" % (stdout_fh))
|
||||
|
||||
if('stdin_fh' in kwargs.keys()):
|
||||
if 'stdin_fh' in kwargs.keys():
|
||||
stdin_fh = kwargs.get('stdin_fh')
|
||||
LOG.debug("Redirecting stdin to file handle: %s" % (stdin_fh))
|
||||
process_input = None
|
||||
|
||||
if('stderr_fh' in kwargs.keys()):
|
||||
if 'stderr_fh' in kwargs.keys():
|
||||
stderr_fh = kwargs.get('stderr_fh')
|
||||
LOG.debug("Redirecting stderr to file handle: %s" % (stderr_fh))
|
||||
|
||||
process_env = env.get()
|
||||
LOG.debug("With environment: %s" % (process_env))
|
||||
if(env_overrides and len(env_overrides)):
|
||||
if env_overrides and len(env_overrides):
|
||||
LOG.debug("With additional environment overrides: %s" % (env_overrides))
|
||||
for (k, v) in env_overrides.items():
|
||||
process_env[k] = str(v)
|
||||
@ -96,7 +96,7 @@ def execute(*cmd, **kwargs):
|
||||
env=process_env)
|
||||
|
||||
result = None
|
||||
if(process_input != None):
|
||||
if process_input != None:
|
||||
result = obj.communicate(str(process_input))
|
||||
else:
|
||||
result = obj.communicate()
|
||||
@ -106,10 +106,10 @@ def execute(*cmd, **kwargs):
|
||||
_returncode = obj.returncode
|
||||
LOG.debug('Cmd result had exit code: %s' % _returncode)
|
||||
|
||||
if((not ignore_exit_code) and (_returncode not in check_exit_code)):
|
||||
if (not ignore_exit_code) and (_returncode not in check_exit_code):
|
||||
(stdout, stderr) = result
|
||||
ecmd = cmd
|
||||
if(not shell):
|
||||
if not shell:
|
||||
ecmd = ' '.join(cmd)
|
||||
raise excp.ProcessExecutionError(
|
||||
exit_code=_returncode,
|
||||
@ -137,7 +137,7 @@ def joinpths(*paths):
|
||||
|
||||
|
||||
def _gen_password(pw_len):
|
||||
if(pw_len <= 0):
|
||||
if pw_len <= 0:
|
||||
msg = "Password length %s can not be less than or equal to zero" % (pw_len)
|
||||
raise excp.BadParamException(msg)
|
||||
LOG.debug("Generating you a pseudo-random password of byte length: %s" % (pw_len))
|
||||
@ -147,7 +147,7 @@ def _gen_password(pw_len):
|
||||
|
||||
|
||||
def _prompt_password(prompt_=None):
|
||||
if(prompt_):
|
||||
if prompt_:
|
||||
return getpass.getpass(prompt_)
|
||||
else:
|
||||
return getpass.getpass()
|
||||
@ -156,9 +156,9 @@ def _prompt_password(prompt_=None):
|
||||
def password(prompt_=None, pw_len=8):
|
||||
rd = ""
|
||||
ask_for_pw = env.get_bool(PASS_ASK_ENV, True)
|
||||
if(ask_for_pw):
|
||||
if ask_for_pw:
|
||||
rd = _prompt_password(prompt_)
|
||||
if(len(rd) == 0):
|
||||
if len(rd) == 0:
|
||||
return _gen_password(pw_len)
|
||||
else:
|
||||
return rd
|
||||
@ -173,61 +173,61 @@ def mkdirslist(path):
|
||||
(base, _) = os.path.split(path)
|
||||
dirs_possible.add(base)
|
||||
path = base
|
||||
if(path == os.sep):
|
||||
if path == os.sep:
|
||||
break
|
||||
#sorting is important so that we go in the right order.. (/ before /tmp and so on)
|
||||
dirs_made = list()
|
||||
for check_path in sorted(dirs_possible):
|
||||
if(not isdir(check_path)):
|
||||
if not isdir(check_path):
|
||||
mkdir(check_path, False)
|
||||
dirs_made.append(check_path)
|
||||
return dirs_made
|
||||
|
||||
|
||||
def append_file(fn, text, flush=True, quiet=False):
|
||||
if(not quiet):
|
||||
if not quiet:
|
||||
LOG.debug("Appending to file %s (%d bytes)", fn, len(text))
|
||||
with open(fn, "a") as f:
|
||||
f.write(text)
|
||||
if(flush):
|
||||
if flush:
|
||||
f.flush()
|
||||
|
||||
|
||||
def write_file(fn, text, flush=True, quiet=False):
|
||||
if(not quiet):
|
||||
if not quiet:
|
||||
LOG.debug("Writing to file %s (%d bytes)", fn, len(text))
|
||||
with open(fn, "w") as f:
|
||||
f.write(text)
|
||||
if(flush):
|
||||
if flush:
|
||||
f.flush()
|
||||
|
||||
|
||||
def touch_file(fn, die_if_there=True, quiet=False):
|
||||
if(not isfile(fn)):
|
||||
if(not quiet):
|
||||
if not isfile(fn):
|
||||
if not quiet:
|
||||
LOG.debug("Touching and truncating file %s", fn)
|
||||
with open(fn, "w") as f:
|
||||
f.truncate(0)
|
||||
else:
|
||||
if(die_if_there):
|
||||
if die_if_there:
|
||||
msg = "Can not touch file %s since it already exists" % (fn)
|
||||
raise excp.FileException(msg)
|
||||
|
||||
|
||||
def load_file(fn, quiet=False):
|
||||
if(not quiet):
|
||||
if not quiet:
|
||||
LOG.debug("Loading data from file %s", fn)
|
||||
data = ""
|
||||
with open(fn, "r") as f:
|
||||
data = f.read()
|
||||
if(not quiet):
|
||||
if not quiet:
|
||||
LOG.debug("Loaded (%d) bytes from file %s", len(data), fn)
|
||||
return data
|
||||
|
||||
|
||||
def mkdir(path, recurse=True):
|
||||
if(not isdir(path)):
|
||||
if(recurse):
|
||||
if not isdir(path):
|
||||
if recurse:
|
||||
LOG.debug("Recursively creating directory \"%s\"" % (path))
|
||||
os.makedirs(path)
|
||||
else:
|
||||
@ -236,20 +236,20 @@ def mkdir(path, recurse=True):
|
||||
|
||||
|
||||
def deldir(path):
|
||||
if(isdir(path)):
|
||||
if isdir(path):
|
||||
LOG.debug("Recursively deleting directory tree starting at \"%s\"" % (path))
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
def rmdir(path, quiet=True):
|
||||
if(not isdir(path)):
|
||||
if not isdir(path):
|
||||
return
|
||||
try:
|
||||
LOG.debug("Deleting directory \"%s\" with the cavet that we will fail if it's not empty." % (path))
|
||||
os.rmdir(path)
|
||||
LOG.debug("Deleted directory \"%s\"" % (path))
|
||||
except OSError:
|
||||
if(not quiet):
|
||||
if not quiet:
|
||||
raise
|
||||
else:
|
||||
pass
|
||||
@ -276,7 +276,7 @@ def unlink(path, ignore_errors=True):
|
||||
LOG.debug("Unlinking (removing) %s" % (path))
|
||||
os.unlink(path)
|
||||
except OSError:
|
||||
if(not ignore_errors):
|
||||
if not ignore_errors:
|
||||
raise
|
||||
else:
|
||||
pass
|
||||
|
@ -52,7 +52,7 @@ class Trace(object):
|
||||
return self.tracefn
|
||||
|
||||
def trace(self, cmd, action=None):
|
||||
if(action == None):
|
||||
if action == None:
|
||||
action = date.rcf8222date()
|
||||
line = TRACE_FMT % (cmd, action)
|
||||
sh.append_file(self.tracefn, line)
|
||||
@ -67,14 +67,14 @@ class TraceWriter(object):
|
||||
self.started = False
|
||||
|
||||
def _start(self):
|
||||
if(self.started):
|
||||
if self.started:
|
||||
return
|
||||
else:
|
||||
dirs = sh.mkdirslist(self.root)
|
||||
self.filename = touch_trace(self.root, self.name)
|
||||
self.tracer = Trace(self.filename)
|
||||
self.tracer.trace(TRACE_VERSION, str(TRACE_VER))
|
||||
if(len(dirs)):
|
||||
if len(dirs):
|
||||
for d in dirs:
|
||||
self.tracer.trace(DIR_MADE, d)
|
||||
self.started = True
|
||||
@ -158,9 +158,9 @@ class TraceReader(object):
|
||||
lines = self._read()
|
||||
pyentries = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == PYTHON_INSTALL and len(action)):
|
||||
if cmd == PYTHON_INSTALL and len(action):
|
||||
jentry = json.loads(action)
|
||||
if(type(jentry) is dict):
|
||||
if type(jentry) is dict:
|
||||
pyentries.append(jentry)
|
||||
return pyentries
|
||||
|
||||
@ -174,7 +174,7 @@ class TraceReader(object):
|
||||
lines = self._read()
|
||||
files = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == FILE_TOUCHED and len(action)):
|
||||
if cmd == FILE_TOUCHED and len(action):
|
||||
files.append(action)
|
||||
files = list(set(files))
|
||||
files.sort()
|
||||
@ -184,7 +184,7 @@ class TraceReader(object):
|
||||
lines = self._read()
|
||||
dirs = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == DIR_MADE and len(action)):
|
||||
if cmd == DIR_MADE and len(action):
|
||||
dirs.append(action)
|
||||
#ensure in ok order (ie /tmp is before /)
|
||||
dirs = list(set(dirs))
|
||||
@ -196,9 +196,9 @@ class TraceReader(object):
|
||||
lines = self._read()
|
||||
files = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == AP_STARTED and len(action)):
|
||||
if cmd == AP_STARTED and len(action):
|
||||
jdec = json.loads(action)
|
||||
if(type(jdec) is dict):
|
||||
if type(jdec) is dict:
|
||||
files.append(jdec)
|
||||
return files
|
||||
|
||||
@ -206,7 +206,7 @@ class TraceReader(object):
|
||||
lines = self._read()
|
||||
files = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == CFG_WRITING_FILE and len(action)):
|
||||
if cmd == CFG_WRITING_FILE and len(action):
|
||||
files.append(action)
|
||||
files = list(set(files))
|
||||
files.sort()
|
||||
@ -217,13 +217,13 @@ class TraceReader(object):
|
||||
pipsinstalled = dict()
|
||||
pip_list = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == PIP_INSTALL and len(action)):
|
||||
if cmd == PIP_INSTALL and len(action):
|
||||
pip_list.append(action)
|
||||
for pdata in pip_list:
|
||||
pip_info_full = json.loads(pdata)
|
||||
if(type(pip_info_full) is dict):
|
||||
if type(pip_info_full) is dict:
|
||||
name = pip_info_full.get('name')
|
||||
if(name and len(name)):
|
||||
if name and len(name):
|
||||
pipsinstalled[name] = pip_info_full.get('pip_meta')
|
||||
return pipsinstalled
|
||||
|
||||
@ -232,13 +232,13 @@ class TraceReader(object):
|
||||
pkgsinstalled = dict()
|
||||
pkg_list = list()
|
||||
for (cmd, action) in lines:
|
||||
if(cmd == PKG_INSTALL and len(action)):
|
||||
if cmd == PKG_INSTALL and len(action):
|
||||
pkg_list.append(action)
|
||||
for pdata in pkg_list:
|
||||
pkg_info = json.loads(pdata)
|
||||
if(type(pkg_info) is dict):
|
||||
if type(pkg_info) is dict:
|
||||
name = pkg_info.get('name')
|
||||
if(name and len(name)):
|
||||
if name and len(name):
|
||||
pkgsinstalled[name] = pkg_info.get('pkg_meta')
|
||||
return pkgsinstalled
|
||||
|
||||
@ -256,7 +256,7 @@ def touch_trace(rootdir, name):
|
||||
|
||||
def split_line(line):
|
||||
pieces = line.split("-", 1)
|
||||
if(len(pieces) == 2):
|
||||
if len(pieces) == 2:
|
||||
cmd = pieces[0].rstrip()
|
||||
action = pieces[1].lstrip()
|
||||
return (cmd, action)
|
||||
@ -272,7 +272,7 @@ def read(rootdir, name):
|
||||
|
||||
|
||||
def parse_fn(fn):
|
||||
if(not sh.isfile(fn)):
|
||||
if not sh.isfile(fn):
|
||||
msg = "No trace found at filename %s" % (fn)
|
||||
raise excp.NoTraceException(msg)
|
||||
contents = sh.load_file(fn)
|
||||
@ -280,7 +280,7 @@ def parse_fn(fn):
|
||||
accum = list()
|
||||
for line in lines:
|
||||
ep = split_line(line)
|
||||
if(ep == None):
|
||||
if ep == None:
|
||||
continue
|
||||
accum.append(tuple(ep))
|
||||
return accum
|
||||
|
@ -52,17 +52,17 @@ def execute_template(*cmds, **kargs):
|
||||
cmd_to_run_templ = cmdinfo.get("cmd")
|
||||
cmd_to_run = list()
|
||||
for piece in cmd_to_run_templ:
|
||||
if(params_replacements and len(params_replacements)):
|
||||
if params_replacements and len(params_replacements):
|
||||
cmd_to_run.append(param_replace(piece, params_replacements,
|
||||
ignore_missing=ignore_missing))
|
||||
else:
|
||||
cmd_to_run.append(piece)
|
||||
stdin_templ = cmdinfo.get('stdin')
|
||||
stdin = None
|
||||
if(stdin_templ and len(stdin_templ)):
|
||||
if stdin_templ and len(stdin_templ):
|
||||
stdin_full = list()
|
||||
for piece in stdin_templ:
|
||||
if(params_replacements and len(params_replacements)):
|
||||
if params_replacements and len(params_replacements):
|
||||
stdin_full.append(param_replace(piece, params_replacements,
|
||||
ignore_missing=ignore_missing))
|
||||
else:
|
||||
@ -81,7 +81,7 @@ def load_json(fn):
|
||||
lines = data.splitlines()
|
||||
new_lines = list()
|
||||
for line in lines:
|
||||
if(line.lstrip().startswith('#')):
|
||||
if line.lstrip().startswith('#'):
|
||||
continue
|
||||
new_lines.append(line)
|
||||
data = joinlinesep(*new_lines)
|
||||
@ -92,11 +92,11 @@ def get_host_ip():
|
||||
ip = None
|
||||
interfaces = get_interfaces()
|
||||
def_info = interfaces.get(settings.DEFAULT_NET_INTERFACE)
|
||||
if(def_info):
|
||||
if def_info:
|
||||
ipinfo = def_info.get(settings.DEFAULT_NET_INTERFACE_IP_VERSION)
|
||||
if(ipinfo):
|
||||
if ipinfo:
|
||||
ip = ipinfo.get('addr')
|
||||
if(ip == None):
|
||||
if ip == None:
|
||||
msg = "Your host does not have an ip address!"
|
||||
raise excp.NoIpException(msg)
|
||||
return ip
|
||||
@ -108,11 +108,11 @@ def get_interfaces():
|
||||
interface_info = dict()
|
||||
interface_addresses = netifaces.ifaddresses(intfc)
|
||||
ip6 = interface_addresses.get(netifaces.AF_INET6)
|
||||
if(ip6 and len(ip6)):
|
||||
if ip6 and len(ip6):
|
||||
#just take the first
|
||||
interface_info[settings.IPV6] = ip6[0]
|
||||
ip4 = interface_addresses.get(netifaces.AF_INET)
|
||||
if(ip4 and len(ip4)):
|
||||
if ip4 and len(ip4):
|
||||
#just take the first
|
||||
interface_info[settings.IPV4] = ip4[0]
|
||||
#there are others but this is good for now
|
||||
@ -124,12 +124,12 @@ def determine_distro():
|
||||
plt = platform.platform()
|
||||
#ensure its a linux distro
|
||||
(distname, _, _) = platform.linux_distribution()
|
||||
if(not distname):
|
||||
if not distname:
|
||||
return (None, plt)
|
||||
#attempt to match it to our platforms
|
||||
found_os = None
|
||||
for (known_os, pattern) in settings.KNOWN_DISTROS.items():
|
||||
if(pattern.search(plt)):
|
||||
if pattern.search(plt):
|
||||
found_os = known_os
|
||||
break
|
||||
return (found_os, plt)
|
||||
@ -139,13 +139,13 @@ def get_pip_list(distro, component):
|
||||
LOG.info("Getting pip packages for distro %s and component %s." % (distro, component))
|
||||
all_pkgs = dict()
|
||||
fns = settings.PIP_MAP.get(component)
|
||||
if(fns == None):
|
||||
if fns == None:
|
||||
return all_pkgs
|
||||
#load + merge them
|
||||
for fn in fns:
|
||||
js = load_json(fn)
|
||||
distro_pkgs = js.get(distro)
|
||||
if(distro_pkgs and len(distro_pkgs)):
|
||||
if distro_pkgs and len(distro_pkgs):
|
||||
combined = dict(all_pkgs)
|
||||
for (pkgname, pkginfo) in distro_pkgs.items():
|
||||
#we currently just overwrite
|
||||
@ -158,22 +158,22 @@ def get_pkg_list(distro, component):
|
||||
LOG.info("Getting packages for distro %s and component %s." % (distro, component))
|
||||
all_pkgs = dict()
|
||||
fns = settings.PKG_MAP.get(component)
|
||||
if(fns == None):
|
||||
if fns == None:
|
||||
return all_pkgs
|
||||
#load + merge them
|
||||
for fn in fns:
|
||||
js = load_json(fn)
|
||||
distro_pkgs = js.get(distro)
|
||||
if(distro_pkgs and len(distro_pkgs)):
|
||||
if distro_pkgs and len(distro_pkgs):
|
||||
combined = dict(all_pkgs)
|
||||
for (pkgname, pkginfo) in distro_pkgs.items():
|
||||
if(pkgname in all_pkgs.keys()):
|
||||
if pkgname in all_pkgs.keys():
|
||||
oldpkginfo = all_pkgs.get(pkgname) or dict()
|
||||
newpkginfo = dict(oldpkginfo)
|
||||
for (infokey, infovalue) in pkginfo.items():
|
||||
#this is expected to be a list of cmd actions
|
||||
#so merge that accordingly
|
||||
if(infokey == settings.PRE_INSTALL or infokey == settings.POST_INSTALL):
|
||||
if infokey == settings.PRE_INSTALL or infokey == settings.POST_INSTALL:
|
||||
oldinstalllist = oldpkginfo.get(infokey) or []
|
||||
infovalue = oldinstalllist + infovalue
|
||||
newpkginfo[infokey] = infovalue
|
||||
@ -190,13 +190,13 @@ def joinlinesep(*pieces):
|
||||
|
||||
def param_replace(text, replacements, ignore_missing=False):
|
||||
|
||||
if(not replacements or len(replacements) == 0):
|
||||
if not replacements or len(replacements) == 0:
|
||||
return text
|
||||
|
||||
if(len(text) == 0):
|
||||
if len(text) == 0:
|
||||
return text
|
||||
|
||||
if(ignore_missing):
|
||||
if ignore_missing:
|
||||
LOG.debug("Performing parameter replacements (ignoring missing) on %s" % (text))
|
||||
else:
|
||||
LOG.debug("Performing parameter replacements (not ignoring missing) on %s" % (text))
|
||||
@ -205,9 +205,9 @@ def param_replace(text, replacements, ignore_missing=False):
|
||||
org = match.group(0)
|
||||
name = match.group(1)
|
||||
v = replacements.get(name)
|
||||
if(v == None and ignore_missing):
|
||||
if v == None and ignore_missing:
|
||||
v = org
|
||||
elif(v == None and not ignore_missing):
|
||||
elif v == None and not ignore_missing:
|
||||
msg = "No replacement found for parameter %s" % (org)
|
||||
raise excp.NoReplacementException(msg)
|
||||
else:
|
||||
@ -275,7 +275,7 @@ def center_text(text, fill, max_len):
|
||||
def welcome(ident):
|
||||
ver_str = version.version_string()
|
||||
lower = "|"
|
||||
if(ident):
|
||||
if ident:
|
||||
lower += ident
|
||||
lower += " "
|
||||
lower += ver_str
|
||||
@ -285,7 +285,7 @@ def welcome(ident):
|
||||
footer = colored(settings.PROG_NICE_NAME, 'green') + \
|
||||
": " + colored(lower, 'blue')
|
||||
uncolored_footer = (settings.PROG_NICE_NAME + ": " + lower)
|
||||
if(max_line_len - len(uncolored_footer) > 0):
|
||||
if max_line_len - len(uncolored_footer) > 0:
|
||||
#this format string wil center the uncolored text which
|
||||
#we will then replace
|
||||
#with the color text equivalent
|
||||
|
4
utils/clean-parens.sh
Executable file
4
utils/clean-parens.sh
Executable file
@ -0,0 +1,4 @@
|
||||
for i in `find . -name "*.py"`
|
||||
do
|
||||
perl -i -pe "BEGIN{undef $/;} s/if\s*\(\s*(.*?)\s*\)\s*:/if \$1:/sg" $i
|
||||
done
|
@ -4,7 +4,7 @@ import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
me = os.path.basename(sys.argv[0])
|
||||
if(len(sys.argv) == 1):
|
||||
if len(sys.argv) == 1:
|
||||
print("%s filename filename filename..." % (me))
|
||||
sys.exit(0)
|
||||
fn = sys.argv[1]
|
||||
@ -13,7 +13,7 @@ if __name__ == "__main__":
|
||||
lines = contents.splitlines()
|
||||
cleaned_up = list()
|
||||
for line in lines:
|
||||
if(line.lstrip().startswith('#')):
|
||||
if line.lstrip().startswith('#'):
|
||||
continue
|
||||
else:
|
||||
cleaned_up.append(line)
|
||||
|
Loading…
Reference in New Issue
Block a user