~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to jujuci.py

  • Committer: Aaron Bentley
  • Date: 2015-07-27 19:19:56 UTC
  • mto: This revision was merged to the branch mainline in revision 1048.
  • Revision ID: aaron.bentley@canonical.com-20150727191956-uz4gdxuv28qhvv94
Use per-client JUJU_HOME.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from deploy_stack import destroy_environment
19
19
from jujuconfig import NoSuchEnvironment
20
20
from jujupy import (
21
 
    client_from_config,
 
21
    SimpleEnvironment,
 
22
    EnvJujuClient,
22
23
)
23
24
try:
24
25
    from lsb_release import get_distro_information
30
31
    extract_deb,
31
32
    get_deb_arch,
32
33
    get_revision_build,
33
 
    print_now,
34
34
    )
35
35
 
36
36
 
45
45
Artifact = namedtuple('Artifact', ['file_name', 'location'])
46
46
 
47
47
 
 
48
def print_now(string):
 
49
    print(string)
 
50
 
 
51
 
48
52
Credentials = namedtuple('Credentials', ['user', 'password'])
49
53
 
50
54
 
185
189
    artifact = get_filename_artifact(file_name, build_data)
186
190
    target_path = os.path.join(workspace, artifact.file_name)
187
191
    retrieve_artifact(credentials, artifact.location, target_path)
188
 
    return acquire_binary(target_path, workspace)
189
 
 
190
 
 
191
 
def acquire_binary(package_path, workspace):
192
192
    bin_dir = os.path.join(workspace, 'extracted-bin')
193
 
    extract_deb(package_path, bin_dir)
 
193
    extract_deb(target_path, bin_dir)
194
194
    for root, dirs, files in os.walk(bin_dir):
195
195
        if 'juju' in files:
196
196
            return os.path.join(root, 'juju')
222
222
 
223
223
def clean_environment(env_name, verbose=False):
224
224
    try:
225
 
        client = client_from_config(env_name, None)
 
225
        env = SimpleEnvironment.from_config(env_name)
226
226
    except NoSuchEnvironment as e:
227
227
        # Nothing to do.
228
228
        if verbose:
229
229
            print_now(str(e))
230
230
        return False
 
231
    client = EnvJujuClient.by_version(env)
231
232
    if verbose:
232
233
        print_now("Destroying %s" % env_name)
233
234
    destroy_environment(client, env_name)
424
425
class PackageNamer(Namer):
425
426
    """A class knows the names of packages."""
426
427
 
427
 
    def get_release_package_suffix(self):
428
 
        return '-0ubuntu1~{distro_release}.1~juju1_{arch}.deb'.format(
429
 
            distro_release=self.distro_release, arch=self.arch)
430
 
 
431
428
    def get_release_package(self, version):
432
429
        return (
433
 
            'juju-core_{version}{suffix}'
434
 
            ).format(version=version, suffix=self.get_release_package_suffix())
 
430
            'juju-core_{version}-0ubuntu1~{distro_release}.1~juju1_{arch}.deb'
 
431
            ).format(version=version, distro_release=self.distro_release,
 
432
                     arch=self.arch)
435
433
 
436
434
    def get_certification_package(self, version):
437
435
        return (
438
 
            'juju-core_{version}~{distro_release}.1_{arch}.deb'
 
436
            'juju-core_{version}.{distro_release}.1_{arch}.deb'
439
437
            ).format(version=version, distro_release=self.distro_release,
440
438
                     arch=self.arch)
441
439
 
453
451
    try:
454
452
        args, credentials = parse_args(argv)
455
453
    except CredentialsMissing as e:
456
 
        print_now(e)
 
454
        print(e)
457
455
        sys.exit(2)
458
456
    try:
459
457
        if args.command == 'list':
470
468
                args.path, env=args.clean_env,
471
469
                dry_run=args.dry_run, verbose=args.verbose)
472
470
        elif args.command == 'get-juju-bin':
473
 
            print_now(get_juju_bin(credentials, args.workspace))
 
471
            print(get_juju_bin(credentials, args.workspace))
474
472
        elif args.command == 'get-certification-bin':
475
473
            path = get_certification_bin(credentials, args.version,
476
474
                                         args.workspace)
477
 
            print_now(path)
 
475
            print(path)
478
476
        elif args.command == 'get-build-vars':
479
477
            text = get_buildvars(
480
478
                credentials, args.build, env=args.env,
482
480
                version=args.version, short_branch=args.short_branch,
483
481
                short_revision=args.short_revision,
484
482
                branch=args.branch, revision=args.revision)
485
 
            print_now(text)
 
483
            print(text)
486
484
        elif args.command == 'get-package-name':
487
 
            print_now(PackageNamer.factory().get_release_package(args.version))
 
485
            print(PackageNamer.factory().get_release_package(args.version))
488
486
 
489
487
    except Exception as e:
490
 
        print_now(e)
 
488
        print(e)
491
489
        if args.verbose:
492
490
            traceback.print_tb(sys.exc_info()[2])
493
491
        return 2
494
492
    if args.verbose:
495
 
        print_now("Done.")
 
493
        print("Done.")
496
494
    return 0
497
495
 
498
496