~allanlesage/uci-engine/coverage-extractor

« back to all changes in this revision

Viewing changes to juju-deployer/deploy.py

  • Committer: Vincent Ladeuil
  • Date: 2014-06-04 09:28:06 UTC
  • mto: This revision was merged to the branch mainline in revision 533.
  • Revision ID: vila+ci@canonical.com-20140604092806-ugjw5ciqhv1t71w6
Create a version info file using the python format to start with.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import bzrlib
44
44
from bzrlib import (
45
45
    builtins,
 
46
    cmd_version_info,
46
47
    plugin,
47
48
    workingtree,
48
49
)
572
573
    os.environ['JUJU_REPOSITORY'] = repository
573
574
 
574
575
 
 
576
def generate_version_info(path):
 
577
    orig = sys.stdout
 
578
    try:
 
579
        with open(path, 'w') as f:
 
580
            # Create a file containing the version info from the current
 
581
            # working tree
 
582
            cmd = cmd_version_info.cmd_version_info()
 
583
            def redirect():
 
584
                cmd.outf = f
 
585
 
 
586
            # Shame that bzr doesn't provide a better way
 
587
            cmd._setup_outf = redirect
 
588
            cmd.run_argv_aliases(['--python'])
 
589
    finally:
 
590
        sys.stdout = orig
 
591
 
575
592
def build_payload(path):
576
593
    """Build the payload as a compressed tarball at the given path.
577
594
 
604
621
        # We add some more files not under version control. As such, we don't
605
622
        # include them in the sha1 (if they matter for the sha1, they should be
606
623
        # under version control ;)
 
624
        uploaded_version_info_path = './.uploaded_version_info'
 
625
        generate_version_info(uploaded_version_info_path)
 
626
 
607
627
        def reset_ids(tarinfo):
608
628
            # We don't want to get the uid/gid from the uploader
609
629
            tarinfo.uid = tarinfo.gid = 0
611
631
            return tarinfo
612
632
 
613
633
        with tarfile.open(ball.name, 'a') as tarball:
614
 
            # We use relpaths below to mimick bzr's behavior building a tarball
615
 
            # that can be extracted anywhere.
616
 
            for added_path in ['./.bzrignore']:
 
634
            # Always use relpaths below to mimick bzr's behavior building a
 
635
            # tarball that can be extracted anywhere.
 
636
            for added_path in [uploaded_version_info_path]:
617
637
                tarball.add(added_path, filter=reset_ids)
618
638
        # Finally, we compress the resulting tarball
619
639
        with gzip.GzipFile(path, 'w') as gz, open(ball.name) as tarball:
620
640
            gz.write(tarball.read())
621
 
        
622
641
    return sha1.hexdigest()
623
642
 
624
643