def install_script(self, name, **kwargs): if name != self.name: name = '%s_%s' % (self.name, name) for k, v in kwargs.items(): if isinstance(v, list): v = '\n'.join(v) k = k.replace('_', '-') if k in ('bin-directory',): self.buildout['buildout'][k] = v else: self.options[k] = v self.log('using %s', ', '.join(self.options['eggs'].split('\n'))) scripts = Scripts(self.buildout, name, self.options) scripts.install()
def install_wsgi(self): """Install a wsgi application and scripts. Take care of django""" eggs = Scripts(self.buildout, self.options['recipe'], self.options) reqs, ws = eggs.working_set() filename = self.buildout['buildout'].get('dump-picked-versions-file') if filename: config = Config() config.versions = dict( [(pkg.project_name, pkg.version) for pkg in ws]) config.write(filename) extra_paths = self.options.get('extra-paths', '') extra_paths = extra_paths.split() if self.is_django: extra_paths.append(os.path.dirname(self.django_setttings)) self.install_script(name='scripts', extra_paths=extra_paths) # now we can switch in offline mode self.buildout['buildout']['offline'] = 'true' config = self.config addons_requires = self.addons_requires self.install_script( name='wsgi', bin_directory=self.lib_dir, entry_points='pytheon_wsgi.py=logging:warn', scripts='pytheon_wsgi.py=pytheon_wsgi.py', arguments='"%s run as a main module", __file__', extra_paths=extra_paths, eggs=self.options['eggs'] + '\npytheon.deploy\nPasteDeploy\nsqlalchemy' + addons_requires, script_initialization=WSGI_SCRIPT % config, ) wsgi_script = os.path.join(self.lib_dir, 'pytheon_wsgi.py') # bin/touch script self.install_script( name='touch', scripts='touch-wsgi=touch-wsgi', extra_paths='', eggs='', entry_points='touch-wsgi=os:utime', arguments='%r, (t, t)' % wsgi_script, script_initialization='import time; t = time.time()') # bin/backup-db backup_db = os.path.join( os.path.dirname(os.path.abspath(sys.argv[0])), 'backup-db') if os.path.isfile(backup_db): self.install_script( name='backup', scripts='backup-db=backup-db', extra_paths='', eggs='', entry_points='backup-db=subprocess:call', arguments='[%r]' % backup_db) if utils.PY3: # add lib dir to extra_paths so cherrypy can find the wsgi script dirname = os.path.dirname(wsgi_script) self.install_script( name='cherrypy', scripts='pytheon-serve\nceleryd=celeryd', extra_paths=[dirname] + extra_paths, entry_points=('pytheon-serve=' 'pytheon.deploy.scripts:cherrypy_serve'), eggs=self.options['eggs'] + '\npytheon.deploy\nPasteDeploy\nsqlalchemy' + addons_requires, script_initialization=SERVE % ([config, self.options['bind']],) ) elif self.options.get('use', 'gunicorn') == 'gunicorn': self.options['bind'] = 'unix:%s' % join(self.run_dir, 'gunicorn.sock') gu_config = self.install_config('gunicorn_config.py') # add lib dir to extra_paths so gunicorn can find the wsgi script dirname = os.path.dirname(wsgi_script) self.install_script( name='gunicorn', scripts='gunicorn=pytheon-serve\nceleryd=celeryd', extra_paths=[dirname] + extra_paths, eggs=self.options['eggs'] + '\npytheon.deploy\ngunicorn\nsqlalchemy' + addons_requires, script_initialization=SERVE % ( ["-c", gu_config, "pytheon_wsgi:application"],)) else: self.install_script( name='pastescript', scripts='paster=pytheon-serve\nceleryd=celeryd', extra_paths=extra_paths, eggs=self.options['eggs'] + '\npytheon.deploy\nPasteScript\nsqlalchemy' + addons_requires, script_initialization=SERVE % ( ["serve", "--server-name=pytheon", config],)) if self.is_django: self.install_script( name='django', scripts='manage', eggs=self.options['eggs'] + '\npytheon.deploy\nsqlalchemy' + addons_requires, entry_points='manage=pytheon.deploy.django_utils:manage', extra_paths=extra_paths, arguments='%r' % config) if 'CELERY_URL' in os.environ: celeryconfig = join(self.lib_dir, 'celeryconfig.py') if not os.path.isfile(celeryconfig): self.install_config('celeryconfig.py', output=celeryconfig) if not os.path.isfile(join(self.bin_dir, 'pytheon-update')): self.install_script( name='buildout', scripts='buildout=pytheon-update', eggs='pytheon.deploy\nzc.buildout', script_initialization=BUILDOUT % self.curdir, ) return tuple()