def run_remove(self, template_name=None, service_dir=None): " Run remove scripts. " print_header('Uninstall %s' % self.get_name()) map(call, self._gen_scripts( 'remove', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Remove done.') return True
def run_update(self, template_name=None, service_dir=None): " Run update scripts. " LOGGER.info('Site Update start.') print_header('Update %s' % self.get_name()) map(call, self._gen_scripts( 'update', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Update done.') return True
def run_install(self, template_name=None, service_dir=None): " Run instalation scripts. " LOGGER.info('Site Install start.') print_header('Install %s' % self.get_name()) map(call, self._gen_scripts( 'install', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Install done.') return True
def run_remove(self, template_name=None, service_dir=None): " Run remove scripts. " print_header('Uninstall %s' % self.get_name()) map( call, self._gen_scripts('remove', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Remove done.') return True
def run_update(self, template_name=None, service_dir=None): " Run update scripts. " LOGGER.info('Site Update start.') print_header('Update %s' % self.get_name()) map( call, self._gen_scripts('update', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Update done.') return True
def run_install(self, template_name=None, service_dir=None): " Run instalation scripts. " LOGGER.info('Site Install start.') print_header('Install %s' % self.get_name()) map( call, self._gen_scripts('install', template_name=template_name, service_dir=service_dir)) LOGGER.info('Site Install done.') return True
def clone_source(self): " Clone source and prepare templates " print_header('Clone src: %s' % self.src, '-') # Get source source_dir = self._get_source() # Append settings from source self.read(op.join(source_dir, settings.CFGNAME)) self.templates += (self.args.template or self.template).split(',') self.templates = OrderedSet(self._gen_templates(self.templates)) self['template'] = ','.join(str(x[0]) for x in self.templates) print_header('Deploy templates: %s' % self.template, sep='-') with open(op.join(self.deploy_dir, settings.TPLNAME), 'w') as f: f.write(self.template) with open(op.join(self.deploy_dir, settings.CFGNAME), 'w') as f: self['deploy_dir'], tmp_dir = self.target_dir, self.deploy_dir self.write(f) self['deploy_dir'] = tmp_dir # Create site site = Site(self.deploy_dir) # Prepare templates for template_name, template in self.templates: site.paste_template(template_name, template, tmp_dir) # Create site if self.args.info: print_header('Project context', sep='-') LOGGER.info(site.get_info(full=True)) return None # Check requirements call('sudo chmod +x %s/*.sh' % self.service_dir) site.run_check(service_dir=self.service_dir) # Save options site.write() return site
def install(args): " Install site from sources or module " # Deactivate virtualenv if 'VIRTUAL_ENV' in environ: LOGGER.warning('Virtualenv enabled: %s' % environ['VIRTUAL_ENV']) # Install from base modules if args.module: args.src = op.join(settings.MOD_DIR, args.module) assert op.exists(args.src), "Not found module: %s" % args.module # Fix project name args.PROJECT = args.PROJECT.replace('-', '_') args.home = op.abspath(args.path) # Create engine engine = Installer(args) args.deploy_dir = engine.target_dir # Check dir exists assert args.info or args.repeat or not op.exists( engine.target_dir), "Path %s exists. Stop deploy." % args.deploy_dir try: if args.repeat: site = Site(engine.target_dir) site.run_install() return site site = engine.clone_source() if not site: return True engine.build() site.run_install() return site except (CalledProcessError, AssertionError): print "Installation failed" print "Fix errors and repeat installation with (-r) or run 'makesite uninstall %s' for cancel." % args.deploy_dir raise
def paste_template(self, template_name, template=None, deploy_dir=None): " Paste template. " LOGGER.info("Paste template: %s" % template_name) deploy_dir = deploy_dir or self.deploy_dir template = template or self._get_template_path(template_name) self.read([op.join(template, settings.CFGNAME)], extending=True) for fname in gen_template_files(template): curdir = op.join(deploy_dir, op.dirname(fname)) if not op.exists(curdir): makedirs(curdir) source = op.join(template, fname) target = op.join(deploy_dir, fname) copy2(source, target) name, ext = op.splitext(fname) if ext == '.tmpl': t = Template.from_filename(target, namespace=self.as_dict()) with open(op.join(deploy_dir, name), 'w') as f: f.write(t.substitute()) remove(target) return deploy_dir
def paste_template(self, template_name, template=None, deploy_dir=None): " Paste template. " LOGGER.debug("Paste template: %s" % template_name) deploy_dir = deploy_dir or self.deploy_dir template = template or self._get_template_path(template_name) self.read([op.join(template, settings.CFGNAME)], extending=True) for fname in gen_template_files(template): curdir = op.join(deploy_dir, op.dirname(fname)) if not op.exists(curdir): makedirs(curdir) source = op.join(template, fname) target = op.join(deploy_dir, fname) copy2(source, target) name, ext = op.splitext(fname) if ext == '.tmpl': t = Template.from_filename(target, namespace=self.as_dict()) with open(op.join(deploy_dir, name), 'w') as f: f.write(t.substitute()) remove(target) return deploy_dir