Beispiel #1
0
    def init(self):
        """Initializes the dependency repository."""
        if not os.path.isdir(DEPS_DIR):
            try:
                log.info('Cloning vmcloak-deps.')
                subprocess.check_call(
                    [get_path('git'), 'clone', DEPS_REPO, DEPS_DIR])
            except subprocess.CalledProcessError as e:
                log.error('Error cloning vmcloak-deps: %s.', e)
                return False

        self._load_config()

        if not os.path.isdir(self.files_dir):
            files_git = os.path.join(DEPS_DIR, 'files')

            try:
                log.info('Setting up vmcloak-files.')
                subprocess.check_call([get_path('git'), 'init', files_git])
                subprocess.check_call([
                    get_path('git'), 'remote', 'add', 'origin', self.files_repo
                ],
                                      cwd=files_git)
            except subprocess.CalledProcessError as e:
                log.error('Error setting up vmcloak-files directory: %s', e)
                return False

        return True
Beispiel #2
0
    def init(self):
        """Initializes the dependency repository."""
        if not os.path.isdir(DEPS_DIR):
            try:
                log.info('Cloning vmcloak-deps.')
                subprocess.check_call([get_path('git'), 'clone',
                                       DEPS_REPO, DEPS_DIR])
            except subprocess.CalledProcessError as e:
                log.error('Error cloning vmcloak-deps: %s.', e)
                return False

        self._load_config()

        if not os.path.isdir(self.files_dir):
            files_git = os.path.join(DEPS_DIR, 'files')

            try:
                log.info('Setting up vmcloak-files.')
                subprocess.check_call([get_path('git'), 'init', files_git])
                subprocess.check_call([get_path('git'), 'remote', 'add',
                                       'origin', self.files_repo],
                                      cwd=files_git)
            except subprocess.CalledProcessError as e:
                log.error('Error setting up vmcloak-files directory: %s', e)
                return False

        return True
Beispiel #3
0
    def fetch(self, dependency):
        """Fetch a single dependency."""
        if not self._check():
            return False

        self._load_config()

        if dependency not in self.repo:
            log.warning('No such dependency: %s.', dependency)
            return False

        info = self.repo[dependency]

        filepath = os.path.join(DEPS_DIR, 'files', info['filename'])

        if self.available(dependency):
            log.info('Dependency %r has already been fetched.', dependency)
            return True

        if info['filename'] in self.urls:
            url = self.urls[info['filename']]

            # TODO We have to check the sha1sum of the downloaded binary.

            # Using wget seems the easiest as it shows the progress.
            # TODO Should we be using a Python library for this?
            try:
                log.debug('Fetching dependency %r: %s.', dependency,
                          info['filename'])
                subprocess.check_call([
                    get_path('wget'), '-O', filepath, url,
                    '--no-check-certificate'
                ])
            except subprocess.CalledProcessError as e:
                log.warning('Error downloading %s: %s.', info['filename'], e)
                return False
        else:
            url = self.conf['vmcloak-files']['raw'] % info['filename']

            # Using wget seems the easiest as it shows the progress.
            # TODO Should we be using a Python library for this?
            try:
                log.debug('Fetching dependency %r: %s.', dependency,
                          info['filename'])
                subprocess.check_call([
                    get_path('wget'), '-O', filepath, url,
                    '--no-check-certificate'
                ])
            except subprocess.CalledProcessError as e:
                log.warning('Error downloading %s: %s.', info['filename'], e)
                return False

        if not self.available(dependency):
            return False

        return True
Beispiel #4
0
    def fetch(self, dependency):
        """Fetch a single dependency."""
        if not self._check():
            return False

        self._load_config()

        if dependency not in self.repo:
            log.warning('No such dependency: %s.', dependency)
            return False

        info = self.repo[dependency]

        filepath = os.path.join(DEPS_DIR, 'files', info['filename'])

        if self.available(dependency):
            log.info('Dependency %r has already been fetched.', dependency)
            return True

        if info['filename'] in self.urls:
            url = self.urls[info['filename']]

            # TODO We have to check the sha1sum of the downloaded binary.

            # Using wget seems the easiest as it shows the progress.
            # TODO Should we be using a Python library for this?
            try:
                log.debug('Fetching dependency %r: %s.',
                          dependency, info['filename'])
                subprocess.check_call([get_path('wget'), '-O', filepath, url,
                                       '--no-check-certificate'])
            except subprocess.CalledProcessError as e:
                log.warning('Error downloading %s: %s.', info['filename'], e)
                return False
        else:
            url = self.conf['vmcloak-files']['raw'] % info['filename']

            # Using wget seems the easiest as it shows the progress.
            # TODO Should we be using a Python library for this?
            try:
                log.debug('Fetching dependency %r: %s.',
                          dependency, info['filename'])
                subprocess.check_call([get_path('wget'), '-O', filepath, url,
                                       '--no-check-certificate'])
            except subprocess.CalledProcessError as e:
                log.warning('Error downloading %s: %s.', info['filename'], e)
                return False

        if not self.available(dependency):
            return False

        return True
Beispiel #5
0
def buildiso(mount, winnt_sif, iso_out, bootstrap, tmp_dir=None):
    """Builds an ISO file containing all our modifications."""
    tempdir = tempfile.mkdtemp(dir=tmp_dir)

    # Copy all files to our temporary directory as mounted iso files are
    # read-only and we need lowercase (aka case-insensitive) filepaths.
    copytreelower(mount, tempdir)

    # Copy the boot image.
    shutil.copy(os.path.join(VMCLOAK_ROOT, 'data', 'boot.img'), tempdir)

    dst_winnt = os.path.join(tempdir, 'i386', 'winnt.sif')

    # Merge the existing winnt.sif with our changes.
    mode, winnt = ini_read(dst_winnt)
    ini_merge(winnt, winnt_sif, overwrite=True)

    # There are a couple of optional values that should be set if they have
    # not already been set.
    winnt_opt_sif = os.path.join(VMCLOAK_ROOT, 'data', 'winnt-opt.sif')
    ini_merge(winnt, winnt_opt_sif, overwrite=False)

    ini_write(dst_winnt, mode, winnt)

    osdir = os.path.join(tempdir, '$oem$', '$1')
    os.makedirs(os.path.join(osdir, 'vmcloak'))

    data_bootstrap = os.path.join(VMCLOAK_ROOT, 'data', 'bootstrap')
    for fname in os.listdir(data_bootstrap):
        shutil.copy(os.path.join(data_bootstrap, fname),
                    os.path.join(osdir, 'vmcloak', fname))

    copytreeinto(bootstrap, osdir)

    isocreate = get_path('genisoimage')
    if not isocreate:
        log.error('Either genisoimage or mkisofs is required!')
        shutil.rmtree(tempdir)
        return False

    try:
        args = [
            isocreate, '-quiet', '-b', 'boot.img', '-no-emul-boot',
            '-boot-load-seg', '1984', '-boot-load-size', '4',
            '-iso-level', '2', '-J', '-l', '-D', '-N', '-joliet-long',
            '-relaxed-filenames', '-o', iso_out, tempdir
        ]

        subprocess.check_call(args)
    except subprocess.CalledProcessError as e:
        log.error('Error creating ISO file: %s', e)
        shutil.rmtree(tempdir)
        return False

    shutil.rmtree(tempdir)
    return True
Beispiel #6
0
    def _wget(self, filename, url=None, subdir=None):
        if subdir is None:
            path = os.path.join(self.deps_directory, filename)
        else:
            path = os.path.join(self.deps_directory, subdir, filename)

        if url is None:
            url = urlparse.urljoin(self.deps_repository, filename)

        args = get_path('wget'), '-O', path, url, '--no-check-certificate'
        subprocess.check_call(args)
Beispiel #7
0
    def _wget(self, filename, url=None, subdir=None):
        if subdir is None:
            path = os.path.join(self.deps_directory, filename)
        else:
            path = os.path.join(self.deps_directory, subdir, filename)

        if url is None:
            url = urlparse.urljoin(self.deps_repository, filename)

        args = [get_path('wget'), '-O', path, url, '--no-check-certificate']
        subprocess.check_call(args)
Beispiel #8
0
    def buildiso(self, mount, newiso, bootstrap, tmp_dir=None):
        """Builds an ISO file containing all our modifications."""
        outdir = tempfile.mkdtemp(dir=tmp_dir)

        # Copy all files to our temporary directory as mounted iso files are
        # read-only and we need lowercase (aka case-insensitive) filepaths.
        copytreelower(mount, outdir)

        # Copy the boot image.
        shutil.copy(os.path.join(self.path, "boot.img"), outdir)

        # Allow the OS handler to write additional files.
        self.isofiles(outdir, tmp_dir)

        os.makedirs(os.path.join(outdir, self.osdir, "vmcloak"))

        data_bootstrap = os.path.join(self.data_path, "bootstrap")
        for fname in os.listdir(data_bootstrap):
            shutil.copy(os.path.join(data_bootstrap, fname),
                        os.path.join(outdir, self.osdir, "vmcloak", fname))

        copytreeinto(bootstrap, os.path.join(outdir, self.osdir))

        isocreate = get_path("genisoimage")
        if not isocreate:
            log.error("Either genisoimage or mkisofs is required!")
            shutil.rmtree(outdir)
            return False

        args = [
            isocreate,
            "-quiet",
            "-b",
            "boot.img",
            "-allow-limited-size",
            "-o",
            newiso,
        ] + self.genisoargs + [outdir]

        log.debug("Executing genisoimage: %s", " ".join(args))
        p = subprocess.Popen(args,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, err = p.communicate()
        warning = re.sub("[\\s]+", " ", err).strip()
        if p.wait() or out or warning not in GENISOIMAGE_WARNINGS:
            log.error("Error creating ISO file (err=%d): %s %s", p.wait(), out,
                      err)
            shutil.rmtree(outdir)
            return False

        shutil.rmtree(outdir)
        return True
Beispiel #9
0
    def update(self):
        """Updates the dependency repository."""
        if not self._check():
            return False

        try:
            log.info('Updating vmcloak-deps.')
            subprocess.check_call(
                [get_path('git'), 'pull', 'origin', 'master'], cwd=DEPS_DIR)
        except subprocess.CalledProcessError as e:
            log.error('Error updating the vmcloak-deps repository: %s', e)
            return False

        return True
Beispiel #10
0
    def buildiso(self, mount, newiso, bootstrap, tmp_dir=None):
        """Builds an ISO file containing all our modifications."""
        outdir = tempfile.mkdtemp(dir=tmp_dir)

        # Copy all files to our temporary directory as mounted iso files are
        # read-only and we need lowercase (aka case-insensitive) filepaths.
        copytreelower(mount, outdir)

        # Copy the boot image.
        shutil.copy(os.path.join(self.path, "boot.img"), outdir)

        # Allow the OS handler to write additional files.
        self.isofiles(outdir, tmp_dir)

        os.makedirs(os.path.join(outdir, self.osdir, "vmcloak"))

        data_bootstrap = os.path.join(self.data_path, "bootstrap")
        for fname in os.listdir(data_bootstrap):
            shutil.copy(os.path.join(data_bootstrap, fname),
                        os.path.join(outdir, self.osdir, "vmcloak", fname))

        copytreeinto(bootstrap, os.path.join(outdir, self.osdir))

        isocreate = get_path("genisoimage")
        if not isocreate:
            log.error("Either genisoimage or mkisofs is required!")
            shutil.rmtree(outdir)
            return False

        args = [
            isocreate, "-quiet", "-b", "boot.img", "-o", newiso,
        ] + self.genisoargs + [outdir]

        log.debug("Executing genisoimage: %s", " ".join(args))
        p = subprocess.Popen(
            args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        out, err = p.communicate()
        warning = re.sub("[\\s]+", " ", err).strip()
        if p.wait() or out or warning not in GENISOIMAGE_WARNINGS:
            log.error(
                "Error creating ISO file (err=%d): %s %s",
                p.wait(), out, err
            )
            shutil.rmtree(outdir)
            return False

        shutil.rmtree(outdir)
        return True
Beispiel #11
0
    def update(self):
        """Updates the dependency repository."""
        if not self._check():
            return False

        try:
            log.info('Updating vmcloak-deps.')
            subprocess.check_call([get_path('git'), 'pull',
                                   'origin', 'master'],
                                  cwd=DEPS_DIR)
        except subprocess.CalledProcessError as e:
            log.error('Error updating the vmcloak-deps repository: %s', e)
            return False

        return True
Beispiel #12
0
    def buildiso(self, mount, newiso, bootstrap, tmp_dir=None):
        """Builds an ISO file containing all our modifications."""
        outdir = tempfile.mkdtemp(dir=tmp_dir)

        # Copy all files to our temporary directory as mounted iso files are
        # read-only and we need lowercase (aka case-insensitive) filepaths.
        copytreelower(mount, outdir)

        # Copy the boot image.
        shutil.copy(os.path.join(self.path, 'boot.img'), outdir)

        # Allow the OS handler to write additional files.
        self.isofiles(outdir, tmp_dir)

        os.makedirs(os.path.join(outdir, self.osdir, 'vmcloak'))

        data_bootstrap = os.path.join(self.data_path, 'bootstrap')
        for fname in os.listdir(data_bootstrap):
            shutil.copy(os.path.join(data_bootstrap, fname),
                        os.path.join(outdir, self.osdir, 'vmcloak', fname))

        copytreeinto(bootstrap, os.path.join(outdir, self.osdir))

        isocreate = get_path('genisoimage')
        if not isocreate:
            log.error('Either genisoimage or mkisofs is required!')
            shutil.rmtree(outdir)
            return False

        args = [
            isocreate, '-quiet', '-b', 'boot.img', '-o', newiso,
        ] + self.genisoargs + [outdir]

        p = subprocess.Popen(
            args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        out, err = p.communicate()
        if p.wait() or out or err != GENISOIMAGE_ERROR:
            log.error(
                "Error creating ISO file (err=%d): %s %s",
                p.wait(), out, err
            )
            shutil.rmtree(outdir)
            return False

        shutil.rmtree(outdir)
        return True
Beispiel #13
0
    def fetch_all(self):
        """Fetch all dependencies at once."""
        if not self._check():
            return False

        self._load_config()

        try:
            log.info('Cloning the vmcloak-files repository.')
            subprocess.check_call(
                [get_path('git'), 'pull', 'origin', 'master'],
                cwd=self.files_dir)
        except subprocess.CalledProcessError as e:
            log.error('Error fetching vmcloak-files repository: %s', e)
            return False

        return True
Beispiel #14
0
    def fetch_all(self):
        """Fetch all dependencies at once."""
        if not self._check():
            return False

        self._load_config()

        try:
            log.info('Cloning the vmcloak-files repository.')
            subprocess.check_call([get_path('git'), 'pull',
                                   'origin', 'master'],
                                  cwd=self.files_dir)
        except subprocess.CalledProcessError as e:
            log.error('Error fetching vmcloak-files repository: %s', e)
            return False

        return True
Beispiel #15
0
    def buildiso(self, mount, newiso, bootstrap, tmp_dir=None):
        """Builds an ISO file containing all our modifications."""
        outdir = tempfile.mkdtemp(dir=tmp_dir)

        # Copy all files to our temporary directory as mounted iso files are
        # read-only and we need lowercase (aka case-insensitive) filepaths.
        copytreelower(mount, outdir)

        # Copy the boot image.
        shutil.copy(os.path.join(self.path, 'boot.img'), outdir)

        # Allow the OS handler to write additional files.
        self.isofiles(outdir, tmp_dir)

        os.makedirs(os.path.join(outdir, self.osdir, 'vmcloak'))

        data_bootstrap = os.path.join(self.data_path, 'bootstrap')
        for fname in os.listdir(data_bootstrap):
            shutil.copy(os.path.join(data_bootstrap, fname),
                        os.path.join(outdir, self.osdir, 'vmcloak', fname))

        copytreeinto(bootstrap, os.path.join(outdir, self.osdir))

        isocreate = get_path('genisoimage')
        if not isocreate:
            log.error('Either genisoimage or mkisofs is required!')
            shutil.rmtree(outdir)
            return False

        args = [
            isocreate, '-quiet', '-b', 'boot.img', '-o', newiso,
        ] + self.genisoargs + [outdir]

        try:
            # TODO Properly suppress the ISO-9660 warning.
            subprocess.check_call(args)
        except subprocess.CalledProcessError as e:
            log.error('Error creating ISO file: %s', e)
            shutil.rmtree(outdir)
            return False

        shutil.rmtree(outdir)
        return True
Beispiel #16
0
    def buildiso(self, mount, newiso, bootstrap, tmp_dir=None):
        """Builds an ISO file containing all our modifications."""
        outdir = tempfile.mkdtemp(dir=tmp_dir)

        # Copy all files to our temporary directory as mounted iso files are
        # read-only and we need lowercase (aka case-insensitive) filepaths.
        copytreelower(mount, outdir)

        # Copy the boot image.
        shutil.copy(os.path.join(self.path, 'boot.img'), outdir)

        # Allow the OS handler to write additional files.
        self.isofiles(outdir, tmp_dir)

        os.makedirs(os.path.join(outdir, self.osdir, 'vmcloak'))

        data_bootstrap = os.path.join(self.data_path, 'bootstrap')
        for fname in os.listdir(data_bootstrap):
            shutil.copy(os.path.join(data_bootstrap, fname),
                        os.path.join(outdir, self.osdir, 'vmcloak', fname))

        copytreeinto(bootstrap, os.path.join(outdir, self.osdir))

        isocreate = get_path('genisoimage')
        if not isocreate:
            log.error('Either genisoimage or mkisofs is required!')
            shutil.rmtree(outdir)
            return False

        args = [
            isocreate, '-quiet', '-b', 'boot.img', '-o', newiso,
        ] + self.genisoargs + [outdir]

        try:
            # TODO Properly suppress the ISO-9660 warning.
            subprocess.check_call(args)
        except subprocess.CalledProcessError as e:
            log.error('Error creating ISO file: %s', e)
            shutil.rmtree(outdir)
            return False

        shutil.rmtree(outdir)
        return True
Beispiel #17
0
 def __init__(self, *args, **kwargs):
     Machinery.__init__(self, *args, **kwargs)
     self.vboxmanage = get_path("vboxmanage")
Beispiel #18
0
def test_path2():
    assert get_path("vboxmanage") == "/usr/local/bin/VBoxManage"
Beispiel #19
0
def test_path1():
    assert get_path("vboxmanage") == "/usr/bin/VBoxManage"