Ejemplo n.º 1
0
def download(distro, uri, target_dir, **kwargs):
    puri = urlparse(uri)
    scheme = puri.scheme.lower()
    path = puri.path
    if scheme in ['git'] or path.find('.git') != -1:
        dirs_made = sh.mkdirslist(target_dir)
        downloader = GitDownloader(distro, uri, target_dir)
        downloader.download()
        return dirs_made
    if scheme in ['http', 'https']:
        dirs_made = []
        with utils.tempdir() as tdir:
            fn = sh.basename(path)
            downloader = UrlLibDownloader(uri, sh.joinpths(tdir, fn))
            downloader.download()
            if fn.endswith('.tar.gz'):
                dirs_made = sh.mkdirslist(target_dir)
                cmd = ['tar', '-xzvf', sh.joinpths(tdir, fn), '-C', target_dir]
                sh.execute(*cmd)
            elif fn.endswith('.zip'):
                # TODO(harlowja) this might not be 100% right...
                # we might have to move the finished directory...
                dirs_made = sh.mkdirslist(target_dir)
                cmd = ['unzip', sh.joinpths(tdir, fn), '-d', target_dir]
                sh.execute(*cmd)
            else:
                raise excp.DownloadException("Unable to extract %s downloaded from %s" % (fn, uri))
        return dirs_made
    else:
        raise excp.DownloadException("Unknown scheme %s, unable to download from %s" % (scheme, uri))
Ejemplo n.º 2
0
 def _make_source_archive(self):
     with utils.tempdir() as td:
         arch_base_name = "%s-%s" % (self.details['name'], self.details['version'])
         sh.copytree(self.get_option('app_dir'), sh.joinpths(td, arch_base_name))
         arch_tmp_fn = sh.joinpths(td, "%s.tar.gz" % (arch_base_name))
         tar_it(arch_tmp_fn, arch_base_name, td)
         sh.move(arch_tmp_fn, self.build_paths['sources'])
     return "%s.tar.gz" % (arch_base_name)
Ejemplo n.º 3
0
 def _make_source_archive(self):
     with utils.tempdir() as td:
         arch_base_name = "%s-%s" % (self.details['name'], self.details['version'])
         sh.copytree(self.get_option('app_dir'), sh.joinpths(td, arch_base_name))
         arch_tmp_fn = sh.joinpths(td, "%s.tar.gz" % (arch_base_name))
         tar_it(arch_tmp_fn, arch_base_name, td)
         sh.move(arch_tmp_fn, self.build_paths['sources'])
     return "%s.tar.gz" % (arch_base_name)
Ejemplo n.º 4
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" % (self.url))
     with utils.tempdir() as tdir:
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(self.url, sh.joinpths(tdir, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url, bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, tdir)
         tgt_image_name = self._generate_img_name(url_fn)
         img_id = self._register(tgt_image_name, unpack_info)
         return (tgt_image_name, img_id)
Ejemplo n.º 5
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" %
                       (self.url))
     with utils.tempdir() as tdir:
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(
                 self.url, sh.joinpths(tdir, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url,
                       bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, tdir)
         tgt_image_name = self._generate_img_name(url_fn)
         img_id = self._register(tgt_image_name, unpack_info)
         return (tgt_image_name, img_id)
Ejemplo n.º 6
0
def get_archive_details(filename):
    if not sh.isfile(filename):
        raise IOError("Can not detail non-existent file %s" % (filename))

    # Check if we already got the details of this file previously
    cache_key = "f:%s:%s" % (sh.basename(filename), sh.getsize(filename))
    if cache_key in EGGS_DETAILED:
        return EGGS_DETAILED[cache_key]

    # Get pip to get us the egg-info.
    with utils.tempdir() as td:
        filename = sh.copy(filename, sh.joinpths(td, sh.basename(filename)))
        extract_to = sh.mkdir(sh.joinpths(td, 'build'))
        pip_util.unpack_file(filename, extract_to, content_type='', link='')
        details = get_directory_details(extract_to)

    EGGS_DETAILED[cache_key] = details
    return details
Ejemplo n.º 7
0
def get_archive_details(filename):
    if not sh.isfile(filename):
        raise IOError("Can not detail non-existent file %s" % (filename))

    # Check if we already got the details of this file previously
    cache_key = "f:%s:%s" % (sh.basename(filename), sh.getsize(filename))
    if cache_key in EGGS_DETAILED:
        return EGGS_DETAILED[cache_key]

    # Get pip to get us the egg-info.
    with utils.tempdir() as td:
        filename = sh.copy(filename, sh.joinpths(td, sh.basename(filename)))
        extract_to = sh.mkdir(sh.joinpths(td, 'build'))
        pip_util.unpack_file(filename, extract_to, content_type='', link='')
        details = get_directory_details(extract_to)

    EGGS_DETAILED[cache_key] = details
    return details
Ejemplo n.º 8
0
def download(distro, uri, target_dir, **kwargs):
    puri = urlparse(uri)
    scheme = puri.scheme.lower()
    path = puri.path.strip().split("?", 1)[0]
    if scheme == 'git' or path.lower().endswith('.git'):
        downloader = GitDownloader(distro, uri, target_dir)
        downloader.download()
    elif scheme in ['http', 'https']:
        with utils.tempdir() as tdir:
            fn = sh.basename(path)
            downloader = UrlLibDownloader(uri, sh.joinpths(tdir, fn))
            downloader.download()
            if fn.endswith('.tar.gz'):
                cmd = ['tar', '-xzvf', sh.joinpths(tdir, fn), '-C', target_dir]
                sh.execute(*cmd)
            elif fn.endswith('.zip'):
                # TODO(harlowja) this might not be 100% right...
                # we might have to move the finished directory...
                cmd = ['unzip', sh.joinpths(tdir, fn), '-d', target_dir]
                sh.execute(*cmd)
            else:
                raise excp.DownloadException("Unable to extract %s downloaded from %s" % (fn, uri))
    else:
        raise excp.DownloadException("Unknown scheme %s, unable to download from %s" % (scheme, uri))
Ejemplo n.º 9
0
    def _install_src_rpm(self, rpm):
        filename = sh.basename(rpm)
        if not filename:
            LOG.error("Cannot determine file name from rpm: %r", rpm)
            return False
        (package, ext) = os.path.splitext(filename)
        if not package:
            LOG.error("Cannot determine package name from rpm: %r", rpm)
            return False

        if self._is_installed(package):
            return True
        with utils.tempdir() as tdir:
            if not sh.exists(rpm):
                (fetched_filen, bytes_down) = downloader.UrlLibDownloader(rpm, sh.joinpths(tdir, filename)).download()
                LOG.debug("For url %s, we downloaded %s bytes to %s", rpm, bytes_down, fetched_filen)
                # RLOO, do we want to catch any exceptions?
            else:
                fetched_filen = rpm
        
            cmd = YUM_INSTALL + ["--nogpgcheck", fetched_filen] 
            self._execute_yum(cmd)

        return True