Commit 63e1b6d5 authored by Nirbheek Chauhan's avatar Nirbheek Chauhan

cerbero: Add fetch() and extract() to bootstrapper

This separates each bootstrapper into three distinct stages:

1. Fetch network resources into self.config.local_sources
2. Extract/copy network resources into the correct location
3. Run arbitrary commands that do not need network access

https://bugzilla.gnome.org/show_bug.cgi?id=797316
parent ded0eb57
......@@ -16,12 +16,52 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import os
import shutil
from cerbero.build.source import BaseTarball
class BootstrapTarball(BaseTarball):
def __init__(self, config, offline, url, checksum, download_dir, tarball_name=None):
self.config = config
self.offline = offline
self.url = url
self.download_dir = download_dir
self.tarball_name = tarball_name
self.tarball_checksum = checksum
super().__init__()
class BootstrapperBase (object):
# Dict of URLs to be fetched and their checksums
fetch_urls = None
# Dict of extract steps to be done
extract_steps = None
def __init__(self, config, offline):
self.config = config
self.offline = offline
self.fetch_urls = {}
self.extract_steps = []
self.sources = {}
def start(self):
raise NotImplemented("'start' must be implemented by subclasses")
def fetch(self):
for url, checksum in self.fetch_urls.items():
source = BootstrapTarball(self.config, self.offline, url, checksum,
self.config.local_sources)
self.sources[url] = source
source.fetch()
def extract(self):
for (url, unpack, unpack_dir) in self.extract_steps:
if unpack:
self.sources[url].extract(unpack_dir)
else:
# Just copy the file as-is
fname = os.path.basename(url)
fpath = os.path.join(self.config.local_sources, fname)
shutil.copy(fpath, unpack_dir)
......@@ -37,6 +37,8 @@ class Bootstrap(Command):
def run(self, config, args):
bootstrappers = Bootstrapper(config, args.build_tools_only, args.offline)
for bootstrapper in bootstrappers:
bootstrapper.fetch()
bootstrapper.extract()
bootstrapper.start()
register_command(Bootstrap)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment