def build(env): env.log('build') testing_error = env.settings.get('testing', 'testing.error', fallback='') if testing_error == 'env_session_error': env.session.start() with builddir.create(env, 'sadm.testing') as fh: fh.write('testing\n')
def configure(env, unit, typ, name, tpldat): service = "%s-%s.%s" % (unit, name, typ) with libdir.fopen('utils', 'systemd', "%s.%s" % (unit, typ)) as fh: data = fh.read() dst = path.join('etc', 'systemd', 'system', service) with builddir.create(env, dst) as fh: fh.write(data.format(**tpldat)) fh.flush()
def _parse(env, name, src, dst, attr, args): env.log("parse %s: src=%s dst=%s" % (name, src, dst)) with env.assets.open(src) as srcfh: tpl = Template(srcfh.read()) with builddir.create(env, dst, **attr) as dstfh: try: dstfh.write(tpl.substitute(args)) except KeyError as err: raise PluginError("template %s key miss: %s" % (name, err))
def _sync(env, opt, src, dst, args): if env.assets.isdir(src): env.log("%s dir %s -> %s" % (opt, src, dst)) builddir.sync(env, src, dst, **args) else: env.log("%s file %s -> %s" % (opt, src, dst)) with env.assets.open(src) as sfh: with builddir.create(env, dst, **args) as dfh: dfh.write(sfh.read())
def _setHostname(env): hostname = env.settings.get('os', 'hostname') hfn = env.settings.get('os', 'hostname.file') env.debug("hostname file %s" % hfn) with builddir.create(env, hfn) as fh: fh.write(hostname.strip()) fh.write('\n') fh.flush() env.log("%s: %s" % (hfn, hostname))
def _writeSettings(env): env.log('configure.ini') fn = None with builddir.create(env, 'configure.ini', meta = True) as fh: env.settings.write(fh) fn = fh.name h = sha256() with open(fn, 'rb') as fh: h.update(fh.read()) env.session.set('sadm.configure.checksum', h.hexdigest())
def _buildListen(env): cfgfiles = ( (libdir.fpath('listen', 'wsgi', 'uwsgi.ini'), path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'uwsgi.ini')), (libdir.fpath('listen', 'wsgi', 'uwsgi.service'), path.join(path.sep, 'etc', 'systemd', 'system', 'sadm-listen.service')), (libdir.fpath('listen', 'wsgi', 'apache.conf'), path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'apache.conf')), (libdir.fpath('listen', 'wsgi', 'nginx.conf'), path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'nginx.conf')), (libdir.fpath('listen', 'wsgi', 'lighttpd.conf'), path.join(path.sep, 'etc', 'opt', 'sadm', 'listen', 'lighttpd.conf')), (libdir.fpath('listen', 'fail2ban', 'filter.d', 'sadm-listen.conf'), path.join(path.sep, 'etc', 'fail2ban', 'filter.d', 'sadm-listen.conf')), (libdir.fpath('listen', 'fail2ban', 'jail.d', 'sadm-listen.conf'), path.join(path.sep, 'etc', 'fail2ban', 'jail.d', 'sadm-listen.conf')), ) for srcfn, dstfn in cfgfiles: env.log("create %s" % dstfn) with open(srcfn, 'r') as src: with builddir.create(env, dstfn) as dst: dst.write(src.read())
def _meta(env): env.log('meta.json') with builddir.create(env, 'meta.json', meta = True) as fh: json.dump(_getmeta(env), fh, indent = '\t', sort_keys = True)
def _saveSession(env): env.debug('session.json') with builddir.create(env, 'session.json', meta = True) as fh: env.session.dump(fh)