Revision 124c300e ci/utils.py

b/ci/utils.py
10 10
import logging
11 11
import fabric.api as fabric
12 12
import subprocess
13
import tempfile
13 14
from ConfigParser import ConfigParser, DuplicateSectionError
14 15

  
15 16
from kamaki.cli import config as kamaki_config
......
445 446
        """
446 447
        _run(cmd, False)
447 448

  
449

  
450
    @_check_fabric
451
    def build_documentation(self):
452
        self.logger.info("Build Synnefo documentation..")
453
        _run("pip install -U Sphinx", False)
454
        with fabric.cd("synnefo"):
455
            _run("./ci/make_docs.sh synnefo_documentation", False)
456

  
457
    def fetch_documentation(self, dest=None):
458
        if dest is None:
459
            dest = "synnefo_documentation"
460
        dest = os.path.abspath(dest)
461
        if not os.path.exists(dest):
462
            os.makedirs(dest)
463
        self.fetch_compressed("synnefo/synnefo_documentation", dest)
464
        self.logger.info("Downloaded documentation to %s" %
465
                         _green(dest))
466

  
448 467
    @_check_fabric
449 468
    def deploy_synnefo(self, schema=None):
450 469
        """Deploy Synnefo using snf-deploy"""
......
520 539
        _run(cmd, True)
521 540

  
522 541
    @_check_fabric
523
    def fetch_packages(self, dest=None):
524
        """Download Synnefo packages"""
525
        self.logger.info("Download Synnefo packages")
526
        self.logger.debug("Create tarball with packages")
527
        cmd = """
528
        tar czf synnefo_build-area.tgz synnefo_build-area
529
        """
542
    def fetch_compressed(self, src, dest=None):
543
        self.logger.debug("Creating tarball of %s" % src)
544
        basename = os.path.basename(src)
545
        tar_file = basename + ".tgz"
546
        cmd = "tar czf %s %s" % (tar_file, src)
530 547
        _run(cmd, False)
548
        if not os.path.exists(dest):
549
            os.makedirs(dest)
531 550

  
532
        if dest is None:
533
            pkgs_dir = self.config.get('Global', 'pkgs_dir')
534
        else:
535
            pkgs_dir = dest
536

  
537
        self.logger.debug("Fetch packages to local dir %s" % pkgs_dir)
538
        # Create package directory if missing
539
        if not os.path.exists(pkgs_dir):
540
            os.makedirs(pkgs_dir)
541

  
542
        with fabric.quiet():
543
            fabric.get("synnefo_build-area.tgz", pkgs_dir)
544

  
545
        pkgs_file = os.path.join(pkgs_dir, "synnefo_build-area.tgz")
546
        self._check_hash_sum(pkgs_file, "synnefo_build-area.tgz")
551
        tmp_dir = tempfile.mkdtemp()
552
        fabric.get(tar_file, tmp_dir)
547 553

  
548
        self.logger.debug("Untar packages file %s" % pkgs_file)
554
        dest_file = os.path.join(tmp_dir, tar_file)
555
        self._check_hash_sum(dest_file, tar_file)
556
        self.logger.debug("Untar packages file %s" % dest_file)
549 557
        cmd = """
550 558
        cd %s
551
        tar xzf synnefo_build-area.tgz
552
        cp synnefo_build-area/* %s
553
        rm -r synnefo_build-area
554
        """ % (pkgs_dir, dest)
559
        tar xzf %s
560
        cp -r %s/* %s
561
        rm -r %s
562
        """ % (tmp_dir, tar_file, src, dest, tmp_dir)
555 563
        os.system(cmd)
564
        self.logger.info("Downloaded %s to %s" %
565
                         (src, _green(dest)))
566

  
567
    @_check_fabric
568
    def fetch_packages(self, dest=None):
569
        if dest is None:
570
            dest = self.config.get('Global', 'pkgs_dir')
571
        dest = os.path.abspath(dest)
572
        if not os.path.exists(dest):
573
            os.makedirs(dest)
574
        self.fetch_compressed("synnefo_build-area", dest)
556 575
        self.logger.info("Downloaded debian packages to %s" %
557
                         _green(pkgs_dir))
576
                         _green(dest))

Also available in: Unified diff