Exemplo n.º 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()
Exemplo n.º 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))
Exemplo n.º 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, ))
Exemplo n.º 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')
Exemplo n.º 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}')
Exemplo n.º 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')
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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()}
     )
Exemplo n.º 14
0
 def is_made(self):
     p = sh(self.target, capture=True)
     self.executed = time.time()
     return p.returncode == 0
Exemplo n.º 15
0
 def test_non_file_rule(self):
     PythonPackage('toc').make()
     self.assertTrue('toc' in sh('pip show toc', capture=True).stdout)
Exemplo n.º 16
0
 def tearDown(self):
     shutil.rmtree('test-build', ignore_errors=True)
     sh('yes | pip uninstall toc')
Exemplo n.º 17
0
 def is_made(self):
     return sh('type {0}'.format(self.target), capture=True).returncode == 0
Exemplo n.º 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])
Exemplo n.º 19
0
 def is_made(self):
     return sh(f'type {self.target}', capture=True).returncode == 0
Exemplo n.º 20
0
 def command(rule):
     sh('DEBIAN_FRONTEND=noninteractive sudo apt-get install --quiet -y %s'
        % ' '.join(rule.packages))
Exemplo n.º 21
0
 def tearDown(self):
     sh('dropdb j3db')
     sh('psql postgres -c "DROP USER j3test"')
Exemplo n.º 22
0
 def is_made(self):
     return sh(f'type {self.target}', capture=True).returncode == 0
Exemplo n.º 23
0
 def tearDown(self):
     sh('dropdb j3db', capture=True)
     sh('psql postgres -c "DROP USER j3test"', capture=True)
Exemplo n.º 24
0
 def command(rule):
     sh('DEBIAN_FRONTEND=noninteractive sudo apt-get install --quiet -y %s' % ' '.join(rule.packages))
Exemplo n.º 25
0
 def command(rule):
     sh(f'{rule.python} -m venv {env.virtualenv}')
Exemplo n.º 26
0
Arquivo: file.py Projeto: shimde/july3
 def is_made(self):
     return sh(f'type {self.target}').returncode == 0
Exemplo n.º 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()
     })
Exemplo n.º 28
0
 def command(rule):
     sh(f'{rule.python} -m venv {env.virtualenv}')
Exemplo n.º 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])