Beispiel #1
0
    def test_run_cmd_override_env(self):
        os.environ['TESTVAR'] = 'foo'
        stdout = run_cmd(['env'])
        self.assertIn(b'TESTVAR=foo', stdout)

        stdout = run_cmd(['env'], override_env={'TESTVAR': 'bar'})
        self.assertIn(b'TESTVAR=bar', stdout)

        stdout = run_cmd(['env'], override_env={'TESTVAR': None})
        self.assertNotIn(b'TESTVAR=', stdout)
    def checkout(self):
        from aasemble.utils import run_cmd

        run_cmd(['git',
                 'clone', self.build_record['source']['git_repository'],
                 '--recursive',
                 '-b', self.build_record['source']['git_branch'],
                 self.builddir], logger=self.logger)
        cmd = ['git', 'reset', '--hard']
        build_id = self.build_record['sha']
        if build_id is not None:
            cmd.append(build_id)
        run_cmd(cmd, cwd=self.builddir, logger=self.logger)
Beispiel #3
0
 def _reprepro(self, *args):
     return run_cmd(
         ['reprepro', '-b', self.basedir, '--waitforlock=10'] + list(args),
         override_env={
             'GNUPGHOME':
             self.reposity_signature_driver.get_default_gpghome()
         })
 def native_version(self):
     cmd = ['dpkg-parsechangelog', '--show-field', 'Version']
     v = run_cmd(cmd, cwd=self.builddir).strip().decode()
     if ':' in v:
         v = v.split(':')[1]
     if '-' in v:
         v = v.split('-')[0]
     return v
    def generate_key(self):
        LOG.info('Generating key for %s' % (self.repository))
        gpg_input = render_to_string('buildsvc/gpg-keygen-input.tmpl',
                                     {'repository': self.repository})
        output = run_cmd(['gpg', '--batch', '--gen-key'], input=gpg_input)

        for l in output.split('\n'):
            if l.startswith('gpg: key '):
                return l.split(' ')[2]
    def checkout(self, sha=None, logger=LOG):
        tmpdir = tempfile.mkdtemp()
        builddir = os.path.join(tmpdir, 'build')
        try:
            run_cmd(['git',
                     'clone', self.git_url,
                     '--recursive',
                     '-b', self.branch,
                     'build'],
                    cwd=tmpdir, logger=logger)

            if sha:
                run_cmd(['git', 'reset', '--hard', sha], cwd=builddir, logger=logger)

            stdout = run_cmd(['git', 'rev-parse', 'HEAD'], cwd=builddir, logger=logger)
            return tmpdir, builddir, stdout.strip()
        except:
            shutil.rmtree(tmpdir)
            raise
Beispiel #7
0
    def test_run_cmd_alternate_stdout(self):
        fd, tmpfile = tempfile.mkstemp()
        try:
            with os.fdopen(fd, 'wb') as fp:
                rv = run_cmd(['echo', 'foo'], stdout=fp)

            self.assertEquals(rv, None)

            with open(tmpfile, 'rb') as fp:
                self.assertEquals(fp.read(), b'foo\n')

        finally:
            os.unlink(tmpfile)
Beispiel #8
0
    def poll(self):
        cmd = ['git', 'ls-remote', self.git_url, 'refs/heads/%s' % self.branch]
        try:
            stdout = run_cmd(cmd)
            stdout = stdout.decode()
        except CommandFailed as e:
            self.last_failure_time = now()
            self.last_failure = e.stdout
            self.disabled = True
            self.save()
            return False

        sha = stdout.split('\t')[0]

        if sha == self.last_seen_revision:
            return False

        self.last_seen_revision = sha
        self.save()
        return True
    def poll(self):
        cmd = ['git', 'ls-remote', self.git_url,
               'refs/heads/%s' % self.branch]
        try:
            stdout = run_cmd(cmd)
            stdout = stdout.decode()
        except CommandFailed as e:
            self.last_failure_time = now()
            self.last_failure = e.stdout
            self.disabled = True
            self.save()
            return False

        sha = stdout.split('\t')[0]

        if sha == self.last_seen_revision:
            return False

        self.last_seen_revision = sha
        self.save()
        return True
Beispiel #10
0
 def test_run_cmd_stdout_can_discard_stderr(self):
     tmpfile = self._prepare_stdout_stderr_script()
     try:
         self.assertNotIn(b'stderr', run_cmd([tmpfile], discard_stderr=True))
     finally:
         os.unlink(tmpfile)
Beispiel #11
0
 def test_run_cmd_other_cwd(self):
     self.assertEquals(run_cmd(['pwd'], cwd='/').strip(), b'/')
Beispiel #12
0
 def test_run_cmd_stdout_includes_stderr(self):
     tmpfile = self._prepare_stdout_stderr_script()
     try:
         self.assertIn(b'stderr', run_cmd([tmpfile]))
     finally:
         os.unlink(tmpfile)
 def key_data(self):
     if self.repository.key_id:
         env = {'GNUPG_HOME': self.gpghome()}
         return run_cmd(['gpg', '-a', '--export', self.repository.key_id], override_env=env)
 def update_mirror(self):
     self.write_config()
     try:
         run_cmd(['apt-mirror', 'mirror.conf'], cwd=self.basepath, logger=self.logger)
     finally:
         Mirror.objects.filter(id=self.id).update(refresh_in_progress=False)
 def run_cmd(self, *args, **kwargs):
     return run_cmd(*args, **kwargs)
 def sync_dists(self):
     for mirror in self.mirrorset.mirrors.all():
         destdir = os.path.join(self.basepath, mirror.archive_subpath)
         if not os.path.exists(destdir):
             os.makedirs(destdir)
         run_cmd(['rsync', '-aHAPvi', '--exclude=**/i18n', mirror.dists, destdir])
Beispiel #17
0
 def run_cmd(self, *args, **kwargs):
     return run_cmd(*args, **kwargs)
 def run_it():
     return run_cmd(cmd, cwd=self.builddir, discard_stderr=True, logger=logger).strip()
    def test_export(self):
        tmpdir = tempfile.mkdtemp()
        try:
            privatedir = os.path.join(tmpdir, 'private')
            publicdir = os.path.join(tmpdir, 'public')
            with self.settings(BUILDSVC_REPOS_BASE_DIR=privatedir,
                               BUILDSVC_REPOS_BASE_PUBLIC_DIR=publicdir):
                repo = Repository.objects.get(id=13)
                self.driver(repo).export()

                base_dir = os.path.join(publicdir, 'eric', 'eric6')
                assert os.path.isdir(base_dir)

                dists_dir = os.path.join(base_dir, 'dists')
                assert os.path.isdir(dists_dir)

                binary_amd64_dir = os.path.join(dists_dir, 'aasemble', 'main', 'binary-amd64')
                assert os.path.isdir(binary_amd64_dir)

                packages_file = os.path.join(binary_amd64_dir, 'Packages')

                with open(packages_file, 'r') as fp:
                    self.assertEquals(fp.read(), '')

                packages_gz_file = os.path.join(binary_amd64_dir, 'Packages.gz')
                with gzip.open(packages_gz_file, 'rb') as fp:
                    self.assertEquals(fp.read(), b'')

                binary_amd64_release_file = os.path.join(binary_amd64_dir, 'Release')
                with open(binary_amd64_release_file, 'r') as fp:
                    self.assertEquals(fp.read(), '''Archive: aasemble
Component: main
Origin: Eric6
Label: Eric6
Architecture: amd64
Description: eric6 aasemble
''')
                sources_dir = os.path.join(dists_dir, 'aasemble', 'main', 'source')
                assert os.path.isdir(sources_dir)

                sources_gz_file = os.path.join(sources_dir, 'Sources.gz')
                with gzip.open(sources_gz_file, 'rb') as fp:
                    self.assertEquals(fp.read(), b'')

                sources_release_file = os.path.join(sources_dir, 'Release')
                with open(sources_release_file, 'r') as fp:
                    self.assertEquals(fp.read(), '''Archive: aasemble
Component: main
Origin: Eric6
Label: Eric6
Architecture: source
Description: eric6 aasemble
''')

                gpghome = self.driver(repo).reposity_signature_driver.get_default_gpghome()
                inrelease_file = os.path.join(dists_dir, 'aasemble', 'InRelease')
                run_cmd(['gpg', '--verify', inrelease_file],
                        override_env={'GNUPGHOME': gpghome})

                with open(inrelease_file, 'r') as fp:
                    lines = [l.rstrip('\n') for l in fp.readlines()]

                sepline = lines.index('-----BEGIN PGP SIGNATURE-----')
                body = '\n'.join(lines[3:sepline]) + '\n'

                release_file = os.path.join(dists_dir, 'aasemble', 'Release')
                with open(release_file, 'r') as fp:
                    self.assertEquals(fp.read(), body)

                release_gpg_file = os.path.join(dists_dir, 'aasemble', 'Release.gpg')

                run_cmd(['gpg', '--verify', release_gpg_file, release_file],
                        override_env={'GNUPGHOME': gpghome})

                with open(os.path.join(base_dir, 'repo.key'), 'r') as fp1:
                    with open(os.path.join(os.path.dirname(__file__), 'test_data', 'eric6.public.key')) as fp2:
                        self.assertEquals(fp1.read(), fp2.read())
        finally:
            shutil.rmtree(tmpdir)
 def sync_dists(self):
     for mirror in self.mirrorset.mirrors.all():
         destdir = os.path.join(self.basepath, mirror.archive_subpath)
         if not os.path.exists(destdir):
             os.makedirs(destdir)
         run_cmd(["rsync", "-aHAPvi", "--exclude=**/i18n", mirror.dists, destdir])
Beispiel #21
0
 def test_run_cmd_with_input(self):
     stdout = run_cmd(['cat'], input=b'hello\n')
     self.assertEquals(stdout, b'hello\n')
def key_data(repository):
    if repository.key_id:
        return run_cmd(['gpg', '-a', '--export', repository.key_id])
def _extract_info_from_deb(path):
    from aasemble.utils import run_cmd
    out = run_cmd(['dpkg-deb', '-I', path, 'control'])
    return deb822.Deb822(out)
 def run_it():
     return run_cmd(cmd,
                    cwd=self.builddir,
                    discard_stderr=True,
                    logger=logger).strip()
 def _reprepro(self, *args):
     env = {'GNUPG_HOME': self.gpghome()}
     return run_cmd(['reprepro', '-b', self.basedir, '--waitforlock=10'] + list(args),
                    override_env=env)
Beispiel #26
0
 def test_run_cmd_dead_simple(self):
     # Should simply return successfully
     stdout = run_cmd(['true'])
     self.assertEquals(stdout, b'')
Beispiel #27
0
    def test_export(self):
        tmpdir = tempfile.mkdtemp()
        try:
            privatedir = os.path.join(tmpdir, 'private')
            publicdir = os.path.join(tmpdir, 'public')
            with self.settings(BUILDSVC_REPOS_BASE_DIR=privatedir,
                               BUILDSVC_REPOS_BASE_PUBLIC_DIR=publicdir):
                repo = Repository.objects.get(id=13)
                self.driver(repo).export()

                base_dir = os.path.join(publicdir, 'eric', 'eric6')
                assert os.path.isdir(base_dir)

                dists_dir = os.path.join(base_dir, 'dists')
                assert os.path.isdir(dists_dir)

                binary_amd64_dir = os.path.join(dists_dir, 'aasemble', 'main',
                                                'binary-amd64')
                assert os.path.isdir(binary_amd64_dir)

                packages_file = os.path.join(binary_amd64_dir, 'Packages')

                with open(packages_file, 'r') as fp:
                    self.assertEquals(fp.read(), '')

                packages_gz_file = os.path.join(binary_amd64_dir,
                                                'Packages.gz')
                with gzip.open(packages_gz_file, 'rb') as fp:
                    self.assertEquals(fp.read(), b'')

                binary_amd64_release_file = os.path.join(
                    binary_amd64_dir, 'Release')
                with open(binary_amd64_release_file, 'r') as fp:
                    self.assertEquals(
                        fp.read(), '''Archive: aasemble
Component: main
Origin: Eric6
Label: Eric6
Architecture: amd64
Description: eric6 aasemble
''')
                sources_dir = os.path.join(dists_dir, 'aasemble', 'main',
                                           'source')
                assert os.path.isdir(sources_dir)

                sources_gz_file = os.path.join(sources_dir, 'Sources.gz')
                with gzip.open(sources_gz_file, 'rb') as fp:
                    self.assertEquals(fp.read(), b'')

                sources_release_file = os.path.join(sources_dir, 'Release')
                with open(sources_release_file, 'r') as fp:
                    self.assertEquals(
                        fp.read(), '''Archive: aasemble
Component: main
Origin: Eric6
Label: Eric6
Architecture: source
Description: eric6 aasemble
''')

                gpghome = self.driver(
                    repo).reposity_signature_driver.get_default_gpghome()
                inrelease_file = os.path.join(dists_dir, 'aasemble',
                                              'InRelease')
                run_cmd(['gpg', '--verify', inrelease_file],
                        override_env={'GNUPGHOME': gpghome})

                with open(inrelease_file, 'r') as fp:
                    lines = [l.rstrip('\n') for l in fp.readlines()]

                sepline = lines.index('-----BEGIN PGP SIGNATURE-----')
                body = '\n'.join(lines[3:sepline]) + '\n'

                release_file = os.path.join(dists_dir, 'aasemble', 'Release')
                with open(release_file, 'r') as fp:
                    self.assertEquals(fp.read(), body)

                release_gpg_file = os.path.join(dists_dir, 'aasemble',
                                                'Release.gpg')

                run_cmd(['gpg', '--verify', release_gpg_file, release_file],
                        override_env={'GNUPGHOME': gpghome})

                with open(os.path.join(base_dir, 'repo.key'), 'r') as fp1:
                    with open(
                            os.path.join(os.path.dirname(__file__),
                                         'test_data',
                                         'eric6.public.key')) as fp2:
                        self.assertEquals(fp1.read(), fp2.read())
        finally:
            shutil.rmtree(tmpdir)
Beispiel #28
0
 def test_run_cmd_no_trailing_linefeed(self):
     logger = mock.MagicMock()
     stdout = run_cmd(['bash', '-c', 'echo -n foo'], logger=logger)
     self.assertEquals(stdout, b'foo')
     logger.log.assert_called_with(20, 'foo')
 def _reprepro(self, *args):
     return run_cmd(['reprepro', '-b', self.basedir, '--waitforlock=10'] + list(args),
                    override_env={'GNUPGHOME': self.reposity_signature_driver.get_default_gpghome()})
Beispiel #30
0
def _extract_info_from_deb(path):
    from aasemble.utils import run_cmd
    out = run_cmd(['dpkg-deb', '-I', path, 'control'])
    return deb822.Deb822(out)
 def update_mirror(self):
     self.write_config()
     try:
         run_cmd(["apt-mirror", "mirror.conf"], cwd=self.basepath, logger=self.logger)
     finally:
         Mirror.objects.filter(id=self.id).update(refresh_in_progress=False)