def command(rule): if os.path.exists(rule.path): sh("cd %s; ssh-agent bash -c 'ssh-add %s; git pull'" % (rule.path, env.deploy_key_file)) else: sh("ssh-agent bash -c 'ssh-add %s; git clone %s %s'" % (env.deploy_key_file, rule.url, rule.path)) rule.executed = time.time()
def command(rule): if os.path.exists(rule.path): sh("cd %s; ssh-agent bash -c 'ssh-add %s; git pull'" % (rule.path, env.deploy_key_file)) else: sh("ssh-agent bash -c 'ssh-add %s; git clone %s %s'" % (env.deploy_key_file, rule.url, rule.path))
def render_template(source, rule, context, sudo=False): with NamedTemporaryFile('w') as tmp: tmp.file.write(Template(filename=source).render(**context)) tmp.file.flush() sudo_cmd = 'sudo ' if sudo else '' sh('%scp %s %s' % (sudo_cmd, tmp.name, rule)) sh('%schmod a+r %s' % (sudo_cmd, rule, ))
def pip(command, pip='pip3', virtualenv=None, sudo=False): pip_cmd = pip if virtualenv: pip_cmd = virtualenv + '/bin/' + pip_cmd pip_cmd = sudo_cmd(sudo) + pip_cmd sh(f'{pip_cmd} {command} | grep -v "Requirement already satisfied"; test ${{PIPESTATUS[0]}} -eq 0', executable='/bin/bash')
def pip(command, pip='pip3', virtualenv=None, sudo=False): pip_cmd = pip if virtualenv: pip_cmd = virtualenv + '/bin/' + pip_cmd pip_cmd = sudo_cmd(sudo) + pip_cmd sh(f'{pip_cmd} {command}')
def test_postgres_connection(self): postgres = PostgresConnection('j3db', 'j3test', 'j3pass') postgres.make() sh(r'psql -U j3test j3db -t -c "select 1"') self.assertEqual('1', sh(r'psql -U j3test j3db -t -c "select 1"', capture=True).stdout.strip()) self.assertTrue(postgres.is_made()) postgres.make()
def command(rule): cmd = 'createdb --owner {owner} --template {template} --encoding={encoding} --lc-ctype={locale} --lc-collate={locale} {name}'.format( owner=rule.user, name=rule.dbname, template=env.get('postgres_template', 'template0'), encoding=env.get('postgres_encoding', 'UTF8'), locale=env.get('postgres_locale', 'en_US.UTF-8'), ) if 'psql_sudo' in env: cmd = 'sudo -u {0} '.format(env.psql_sudo) + cmd sh(cmd)
def psql(query, options='', capture=False): command = 'psql postgres %s -c "%s"' % (options, query) if 'psql_sudo' in env: command = 'sudo -u {0} '.format(env.psql_sudo) + command return sh(command, capture=capture).stdout
def test_non_file_rule(self): python_package = PythonPackage('toc') python_package.make() self.assertTrue('toc' in sh('pip show toc', capture=True).stdout) self.assertTrue(python_package.is_made())
def test_postgres_user_and_db(self): print('begin') postgres_user = PostgresUser('j3test', 'j3pass') postgres_db = PostgresDatabase('j3db', 'j3test', 'j3pass', dependencies=[postgres_user]) postgres_db.make() self.assertEqual('1', sh(r'psql -U j3test j3db -t -c "select 1"', capture=True).stdout.strip()) self.assertTrue(postgres_db.is_made())
def test_depend_non_file_rule(self): os.makedirs('test-build') toc_install = PythonPackage('toc') @Rule(f'test-build/{env.project_name}', dependencies=['files/nginx-site.mako', toc_install]) def nginx_site_file(rule): with open(rule.target, 'w') as f: f.write(Template(filename=rule.dependencies[0]).render(**env)) nginx_site_file.make() self.assertTrue('toc' in sh('pip show toc', capture=True).stdout) self.assertTrue(env.web_server_name in open(env.build_path + env.project_name).read())
def is_made(self): return set(self.packages).issubset( {package.split(' ')[0] for package in sh('{0} list --format=legacy'.format(self.pip), capture=True).stdout.splitlines()} )
def is_made(self): p = sh(self.target, capture=True) self.executed = time.time() return p.returncode == 0
def test_non_file_rule(self): PythonPackage('toc').make() self.assertTrue('toc' in sh('pip show toc', capture=True).stdout)
def tearDown(self): shutil.rmtree('test-build', ignore_errors=True) sh('yes | pip uninstall toc')
def is_made(self): return sh('type {0}'.format(self.target), capture=True).returncode == 0
def is_made(self): result = sh("dpkg-query -Wf'${db:Status-abbrev}' %s" % ' '.join(self.packages), capture=True) return result.returncode == 0 and all( [status == 'ii' for status in result.stdout.split(' ') if status])
def is_made(self): return sh(f'type {self.target}', capture=True).returncode == 0
def command(rule): sh('DEBIAN_FRONTEND=noninteractive sudo apt-get install --quiet -y %s' % ' '.join(rule.packages))
def tearDown(self): sh('dropdb j3db') sh('psql postgres -c "DROP USER j3test"')
def tearDown(self): sh('dropdb j3db', capture=True) sh('psql postgres -c "DROP USER j3test"', capture=True)
def command(rule): sh(f'{rule.python} -m venv {env.virtualenv}')
def is_made(self): return sh(f'type {self.target}').returncode == 0
def is_made(self): return set(self.packages).issubset({ package.split(' ')[0] for package in sh('{0} list --format=legacy'.format(self.pip), capture=True).stdout.splitlines() })
def is_made(self): result = sh(" dpkg-query -Wf'${db:Status-abbrev}' %s" % ' '.join(self.packages), capture=True) return result.returncode == 0 and all([status == 'ii' for status in result.stdout.split(' ') if status])