<commit_before>#!/usr/bin/env python
from glob import glob
import json
import os
from os.path import (
    dirname,
    join,
    )
import sys
import subprocess
from tempfile import NamedTemporaryFile


def main():
    scripts = dirname(__file__)
    os.environ['PATH'] = '{}:{}'.format(scripts, os.environ['PATH'])
    revision_build = os.environ['revision_build']
    job_name = os.environ['JOB_NAME']
    build_number = os.environ['BUILD_NUMBER']
    workspace = os.environ['WORKSPACE']
    s3_config = join(os.environ['JUJU_HOME'], 'juju-qa.s3cfg')
    host = sys.argv[1]

    subprocess.check_call(['jujuci.py', '-v', 'setup-workspace', workspace])

    arch = subprocess.check_output(
        ['ssh', host, 'dpkg', '--print-architecture']).rstrip()
    series = subprocess.check_output(
        ['ssh', host, 'lsb_release', '-sc']).rstrip()
    release = subprocess.check_output(
        ['ssh', host, 'lsb_release', '-sr']).rstrip()
    release_glob = '*{}*'.format(release)

    subprocess.check_call([
        'jujuci.py', 'get', '-b', 'lastBuild', 'build-source-packages',
        release_glob, workspace])
    packages = glob(release_glob)
    (dsc_file,) = [x for x in packages if x.endswith('.dsc')]
    subprocess.check_call(
        ['jujuci.py', 'get', '-b', 'lastBuild', 'build-source-packages',
         '*orig.tar.gz', workspace])
    packages.extend(glob('*.orig.tar.gz'))
    command = [
        'mv', 'packages/*', '.', ';',
        '/home/ubuntu/juju-release-tools/build_package.py', '-v', 'binary',
        dsc_file, '$(pwd)', series, arch]
    prefix = 'juju-ci/products/version-{}/{}/build-{}'.format(
        revision_build, job_name, build_number)
    private_key = join(os.environ['JUJU_HOME'], 'staging-juju-rsa')
    with NamedTemporaryFile() as config_file:
        json.dump({
            'command': command,
            'install': {'packages': packages},
            'artifacts': {'packages': ['*.deb']},
            'bucket': 'juju-qa-data',
            }, config_file)
        config_file.flush()
        subprocess.check_call([
            'workspace-run', '-v', config_file.name, host, prefix,
            '--s3-config', s3_config, '-i', private_key,
            ])


if __name__ == '__main__':
    main()<commit_msg>Accept parameters for arch, release, series, source-package-build.<commit_after>#!/usr/bin/env python
from argparse import ArgumentParser
from glob import glob
import json
import os
from os.path import (
    dirname,
    join,
    )
import subprocess
from tempfile import NamedTemporaryFile


def main():
    scripts = dirname(__file__)
    parser = ArgumentParser()
    parser.add_argument('host', help='SSH user@hostname spec.')
    parser.add_argument('release', help='The distro version number.')
    parser.add_argument('series', help='The distro codename.')
    parser.add_argument('arch', help='The machine architecture.')
    parser.add_argument('source_package_build',
                        help='The build-source-package build to use.')
    args = parser.parse_args()
    os.environ['PATH'] = '{}:{}'.format(scripts, os.environ['PATH'])
    revision_build = os.environ['revision_build']
    job_name = os.environ['JOB_NAME']
    build_number = os.environ['BUILD_NUMBER']
    workspace = os.environ['WORKSPACE']
    s3_config = join(os.environ['JUJU_HOME'], 'juju-qa.s3cfg')

    subprocess.check_call(['jujuci.py', '-v', 'setup-workspace', workspace])

    release_glob = '*{}*'.format(args.release)

    subprocess.check_call([
        'jujuci.py', 'get', '-b', args.source_package_build,
        'build-source-packages', release_glob, workspace])
    packages = glob(release_glob)
    (dsc_file,) = [x for x in packages if x.endswith('.dsc')]
    subprocess.check_call(
        ['jujuci.py', 'get', '-b', args.source_package_build,
         'build-source-packages', '*orig.tar.gz', workspace])
    packages.extend(glob('*.orig.tar.gz'))
    command = [
        'mv', 'packages/*', '.', ';',
        '/home/ubuntu/juju-release-tools/build_package.py', '-v', 'binary',
        dsc_file, '$(pwd)', args.series, args.arch]
    prefix = 'juju-ci/products/version-{}/{}/build-{}'.format(
        revision_build, job_name, build_number)
    private_key = join(os.environ['JUJU_HOME'], 'staging-juju-rsa')
    with NamedTemporaryFile() as config_file:
        json.dump({
            'command': command,
            'install': {'packages': packages},
            'artifacts': {'packages': ['*.deb']},
            'bucket': 'juju-qa-data',
            }, config_file)
        config_file.flush()
        subprocess.check_call([
            'workspace-run', '-v', config_file.name, args.host, prefix,
            '--s3-config', s3_config, '-i', private_key,
            ])


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.17333892265772374, 'fraction_numerical': 0.0018863969817648292, 'mean_word_length': 3.057823129251701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4637855', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1571, 'n_words': 300}