Пример #1
0
    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()
Пример #2
0
 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))
Пример #3
0
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, ))
Пример #4
0
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')
Пример #5
0
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}')
Пример #6
0
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')
Пример #7
0
    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()
Пример #8
0
    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)
Пример #9
0
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
Пример #10
0
    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())
Пример #11
0
    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())
Пример #12
0
    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())
Пример #13
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()}
     )
Пример #14
0
 def is_made(self):
     p = sh(self.target, capture=True)
     self.executed = time.time()
     return p.returncode == 0
Пример #15
0
 def test_non_file_rule(self):
     PythonPackage('toc').make()
     self.assertTrue('toc' in sh('pip show toc', capture=True).stdout)
Пример #16
0
 def tearDown(self):
     shutil.rmtree('test-build', ignore_errors=True)
     sh('yes | pip uninstall toc')
Пример #17
0
 def is_made(self):
     return sh('type {0}'.format(self.target), capture=True).returncode == 0
Пример #18
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])
Пример #19
0
 def is_made(self):
     return sh(f'type {self.target}', capture=True).returncode == 0
Пример #20
0
 def command(rule):
     sh('DEBIAN_FRONTEND=noninteractive sudo apt-get install --quiet -y %s'
        % ' '.join(rule.packages))
Пример #21
0
 def tearDown(self):
     sh('dropdb j3db')
     sh('psql postgres -c "DROP USER j3test"')
Пример #22
0
 def is_made(self):
     return sh(f'type {self.target}', capture=True).returncode == 0
Пример #23
0
 def tearDown(self):
     sh('dropdb j3db', capture=True)
     sh('psql postgres -c "DROP USER j3test"', capture=True)
Пример #24
0
 def command(rule):
     sh('DEBIAN_FRONTEND=noninteractive sudo apt-get install --quiet -y %s' % ' '.join(rule.packages))
Пример #25
0
 def command(rule):
     sh(f'{rule.python} -m venv {env.virtualenv}')
Пример #26
0
 def is_made(self):
     return sh(f'type {self.target}').returncode == 0
Пример #27
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()
     })
Пример #28
0
 def command(rule):
     sh(f'{rule.python} -m venv {env.virtualenv}')
Пример #29
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])