def load_json(fn): data = load_file(fn) lines = data.splitlines() new_lines = list() for line in lines: if(line.lstrip().startswith('#')): continue new_lines.append(line) data = joinlinesep(*new_lines) return json.loads(data)
def load_json(fn): data = load_file(fn) lines = data.splitlines() new_lines = list() for line in lines: if (line.lstrip().startswith('#')): continue new_lines.append(line) data = joinlinesep(*new_lines) return json.loads(data)
def _readpy(self): lines = self._read() pyfn = None pylines = list() for (cmd, action) in lines: if(cmd == PYTHON_INSTALL and len(action)): pyfn = action break if(pyfn != None): lines = load_file(pyfn).splitlines() pylines = lines return pylines
def parse_fn(fn): if(not isfile(fn)): msg = "No trace found at filename %s" % (fn) raise NoTraceException(msg) contents = load_file(fn) lines = contents.splitlines() accum = list() for line in lines: ep = split_line(line) if(ep == None): continue accum.append(tuple(ep)) return accum
def configure(self): dirsmade = mkdirslist(self.cfgdir) self.tracewriter.dir_made(*dirsmade) configs = self._get_config_files() if(configs and len(configs)): for fn in configs: parameters = self._get_param_map(fn) sourcefn = joinpths(STACK_CONFIG_DIR, self.component_name, fn) tgtfn = joinpths(self.cfgdir, fn) LOG.info("Configuring template file %s" % (sourcefn)) contents = load_file(sourcefn) LOG.info("Replacing parameters in file %s" % (sourcefn)) LOG.debug("Replacements = %s" % (parameters)) contents = param_replace(contents, parameters) LOG.debug("Applying side-effects of param replacement for template %s" % (sourcefn)) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %s" % (tgtfn)) write_file(tgtfn, contents) #this trace is used to remove the files configured self.tracewriter.cfg_write(tgtfn) return self.tracedir
def configure(self): dirsmade = mkdirslist(self.cfgdir) self.tracewriter.dir_made(*dirsmade) configs = self._get_config_files() if (configs and len(configs)): for fn in configs: parameters = self._get_param_map(fn) sourcefn = joinpths(STACK_CONFIG_DIR, self.component_name, fn) tgtfn = joinpths(self.cfgdir, fn) LOG.info("Configuring template file %s" % (sourcefn)) contents = load_file(sourcefn) LOG.info("Replacing parameters in file %s" % (sourcefn)) LOG.debug("Replacements = %s" % (parameters)) contents = param_replace(contents, parameters) LOG.debug( "Applying side-effects of param replacement for template %s" % (sourcefn)) contents = self._config_adjust(contents, fn) LOG.info("Writing configuration file %s" % (tgtfn)) write_file(tgtfn, contents) #this trace is used to remove the files configured self.tracewriter.cfg_write(tgtfn) return self.tracedir
def stop(self, name, *args, **kargs): rootdir = kargs.get("trace_dir") pidfile = joinpths(rootdir, name + ".pid") stderr = joinpths(rootdir, name + ".stderr") stdout = joinpths(rootdir, name + ".stdout") tfname = Trace.trace_fn(rootdir, name) if(isfile(pidfile) and isfile(tfname)): pid = int(load_file(pidfile).strip()) killed = False lastmsg = "" attempts = 1 for attempt in range(0, MAX_KILL_TRY): try: os.kill(pid, signal.SIGKILL) attempts += 1 except OSError as (ec, msg): if(ec == errno.ESRCH): killed = True break else: lastmsg = msg time.sleep(SLEEP_TIME) #trash the files if(killed): LOG.info("Killed pid %s in %s attempts" % (str(pid), str(attempts))) LOG.info("Removing pid file %s" % (pidfile)) unlink(pidfile) LOG.info("Removing stderr file %s" % (stderr)) unlink(stderr) LOG.info("Removing stdout file %s" % (stdout)) unlink(stdout) LOG.info("Removing %s trace file %s" % (name, tfname)) unlink(tfname) else: msg = "Could not stop program named %s after %s attempts - [%s]" % (name, MAX_KILL_TRY, lastmsg) raise StopException(msg)
def read(rootdir, name): pth = trace_fn(rootdir, name) contents = load_file(pth) lines = contents.splitlines() return lines