Exemplo n.º 1
0
    def __init__(self, element, parent):
        ''' The init method, used to create a new prerequisite object which can
            be tested on the host system.'''
        # Store information about the prerequisite
        self.description = element.get('description')
        self.version     = element.get('version')
        self.endpoint    = element.get('endpoint')
        self.test        = element.get('test')
        self.commands    = element.get('commands')

        # Add the version to the title, if applicable
        if self.version is not None:

            # Convert the version to a string
            self.version = str(self.version)

            # Update the description
            self.description += " " + self.version

            # Extract the version information
            self.major, self.minor, self.revision = \
                        self.extrapolate(self.version)

        # Store the system for running commands
        self.parent = parent

        # Note that we've started the check
        Output.log(Output.PENDING, self.description)
Exemplo n.º 2
0
    def __init__(self, element, parent):
        ''' The init method, used to create a new preparation object which can
            be ensured on the host system.'''
        # Store information about the preparation object
        self.description = element.get('description')
        self.test = element.get('test')
        self.commands = element.get('commands')
        self.result = element.get('result')

        # Store the system for running commands
        self.parent = parent

        # Check if we're in chroot
        if self.parent.user != 'chroot':

            # Initialise the logger
            self.logger = Logger(self.parent.environment['WANDER'],
                                 self.parent.stage[1], '.')

        else:

            # Initialise the logger
            self.logger = Logger('/', self.parent.stage[1])

        # Note that we've started the check
        Output.log(Output.PENDING, self.description)
Exemplo n.º 3
0
    def verify(self):
        ''' The verify method, which ensures that the partition is correctly
            selected and properly formatted.'''
        # First, check if we are in a docker container
        if docker():

            return True

        # Otherwise, tell the user what's happening
        Output.header('Checking partition system...')

        # Create the disk variable
        disk, device = self.getPath()

        # Store the partition to use
        partition = self.getPartition(self.printPartitions(disk, device),
                                      device)

        # Store the partition that we're using
        self.path = device.path + str(partition)

        # Let the user know exactly what the path is
        Output.text('Wander will be built on ' + self.path + '.')

        # Log the filesystem
        Output.log(
            Output.TESTING,
            'Checking that the filesystem of ' + self.path + ' is ext4.')

        # Store the unknown filesystem
        filesystem = None

        # Check the file system
        for partition in disk.partitions:

            # Check that the paths match
            if partition.path == self.path:

                # Store the file system information
                filesystem = partition.fileSystem
                filesystem = filesystem.type if filesystem else None

                # And close
                break

        # Get our result
        result = filesystem == 'ext4'

        # Log the filesystem
        Output.log(
            Output.PASSED if result else Output.FAILED,
            'Checking that' + ' the filesystem of ' + self.path + ' is ext4.')
        print()

        # Inform the user of the status
        Output.footer(result, "Checking partition system")

        # And return the result
        return result
Exemplo n.º 4
0
    def __init__(self, element, parent):
        ''' The init method, used to create a new module object which can be
            built on the host system.'''
        # Store information about the prerequisite
        self.package  = element.get('package')
        self.patch    = element.get('patch')
        self.modules  = element.get('modules')
        self.folder   = element.get('folder')
        self.commands = element.get('commands')
        self.skip     = element.get('skip')
        self.result   = element.get('result')

        # Store the system for running commands
        self.parent   = parent

        # Extract information on the package archive itself
        self.package = parent.packages.elements[self.package]

        self.description = self.package.get('description') if element.get('description') is None else element.get('description')
        self.version     = self.package.get('version')
        self.file        = self.package.get('file').replace('{version}', str(self.version))
        self.extension   = self.package.get('extension')

        # Check if there is a patch to apply
        if self.patch is not None:

            # Extract information about the patches
            self.patch = parent.patches.elements[self.patch]

            self.patch_version   = self.patch.get('version')
            self.patch_file      = self.patch.get('file').replace('{version}', str(self.patch_version))
            self.patch_extension = self.patch.get('extension')

        # Check if we're in chroot
        if self.parent.user != 'chroot':

            # If we're not in chroot, use the full path
            self.target = path.join(self.parent.environment['WANDER'], 'sources', self.file)

            # Initialise the logger
            self.logger = Logger(self.parent.environment['WANDER'], self.parent.stage[1], self.file)

        else:

            # Store the root file name
            self.target = path.join('/sources', self.file)

            # Initialise the logger
            self.logger = Logger('/', self.parent.stage[1], self.file)

        # Check if there are prerequisites
        if self.modules is None:

            # And make it an empty list
            self.modules = list()

        # Note that we've started the check
        Output.log(Output.PENDING, self.description)
Exemplo n.º 5
0
    def verify(self):
        ''' The verify method, which checks that a module built correctly, and
            prints that to the console.'''
        # Check if this module should be skipped
        if self.skip:

            # We're now finished with this prerequisite
            Output.clear()
            Output.log(Output.SKIPPED, self.description)

            # And return our result
            return True

        # Collect each of the elements which needs to be built
        elements = [(self.extract,   Output.EXTRACTING),
                    (self.fix,       Output.PATCHING),
                    (self.setup,     Output.SETUP),
                    (self.prepare,   Output.PREPARING),
                    (self.compile,   Output.COMPILING),
                    (self.configure, Output.CONFIGURING),
                    (self.test,      Output.TESTING),
                    (self.install,   Output.INSTALLING),
                    (self.validate,  Output.VALIDATING),
                    (self.cleanup,   Output.CLEANING)]

        # Store the result of the build
        result = True

        # Iterate through each of the phases
        for element, stage in elements:

            # Notify the user of what we're doing
            Output.clear()
            Output.log(stage, self.description)

            # Add the result to our results variable
            result &= element()

            # Check that everything is still fine
            if not result:

                # And stop our system
                Output.clear()
                Output.log(Output.FAILED, self.description)

                # And return our result
                return False

        # At this point, we're pretty much finished
        Output.clear()
        Output.log(Output.PASSED, self.description)

        # And return our result
        return True
Exemplo n.º 6
0
    def verify(self):
        ''' The verify method, which checks that a requirement is valid, and
            prints that to the console.'''
        # Perform the tests
        Output.clear()
        Output.log(Output.EXECUTING, self.description)

        # Iterate up to the test
        for element in range(self.test + 1):

            # Execute the commands
            result = self.parent.run([self.commands[element]],
                                     self.result is None,
                                     directory='/',
                                     logger=self.logger,
                                     phase='preparation')[-1]

        # And execute the rest of the commands
        for element in range(self.test + 1, len(self.commands)):

            # Execute the final commands
            self.parent.run([self.commands[element]], directory='/')

        # Check that the output is correct
        if self.result is not None:

            # Iterate through each of the acceptable results
            for possibility in self.result:

                # And return if the output matches
                if possibility.strip() in result.strip():

                    # Inform the user that things went well
                    Output.clear()
                    Output.log(Output.PASSED, self.description)

                    return True

        # Check that the command exited safely
        elif result.endswith("0"):

            # If so, things are good
            Output.clear()
            Output.log(Output.PASSED, self.description)

            # And return our result
            return True

        # At this point, we obviously don't have the correct requirement
        Output.clear()
        Output.log(Output.FAILED, self.description)

        # And return our bad result
        return False
Exemplo n.º 7
0
    def verify(self):
        ''' The method which iterates through each item in the list and performs
            the appropriate actions.'''
        # Collect each of the elements which needs to be built
        elements = [(self.scan,      Output.SCANNING),
                    (self.download,  Output.DOWNLOADING),
                    (self.checksum,  Output.VERIFYING),
                    (self.copy,      Output.COPYING)]

        # Store all of the results
        result = True

        # Iterate through each item in turn
        for element in self.elements:

            # Get the information from the file
            self.version     = self.elements[element].get('version')
            self.description = self.elements[element].get('description') + ' ' + str(self.version)
            self.file        = self.elements[element].get('file').replace('{version}', str(self.version))
            self.extension   = self.elements[element].get('extension')
            self.url         = path.join(self.elements[element].get('url').replace('{version}', str(self.version)).replace('{version_}', str(self.version).replace('.', '_')), self.file + self.extension)
            self.md5         = self.elements[element].get('md5')

            # Store the root file name
            self.source      = path.join(sys.path[0], '..', 'sources', self.file)
            self.target      = path.join(self.environment['WANDER'], 'sources', self.file)

            # Notify the user of what's happening
            Output.log(Output.PENDING, self.description)

            # Presume that each stage will run successfully
            success = True

            # Iterate through each of the phases
            for element, stage in elements:

                # Notify the user of what we're doing
                Output.clear()
                Output.log(stage, self.description)

                # Add the result to our success variable
                success &= element()

                # Add the result to our results variable
                result &= success

                # And stop if there is an error
                if not success:
                    break

            # At this point, we're pretty much finished
            Output.clear()
            Output.log(Output.PASSED if success else Output.FAILED, self.description)

            # Add the final line of output
            print('')

        # And return how we did
        return result
Exemplo n.º 8
0
    def verify(self):
        ''' The verify method, which checks that a requirement is valid, and
            prints that to the console.'''
        # Perform the tests
        Output.clear()
        Output.log(Output.TESTING, self.description)

        # Check the type of test
        if self.version is not None:

            # Execute the test code
            version = self.parent.run(self.commands)[-1]

            # Check that the command was found
            if 'not found' in version:

                # We don't have the program installed
                Output.clear()
                Output.log(Output.FAILED, self.description)

                # And return our result
                return False

            # Extrapolate the version information
            major, minor, revision = self.extrapolate(version)

            # Start checking the versions
            if major > self.major:

                # If the major is greater, we obviously have a newer version
                Output.clear()
                Output.log(Output.PASSED, self.description)

                # And return our result
                return True

            elif minor > self.minor:

                # If the minor is greater, we still have a newer version
                Output.clear()
                Output.log(Output.PASSED, self.description)

                # And return our result
                return True

            elif revision >= self.revision:

                # If the revision is greater or equal, we must have a newer
                # version
                Output.clear()
                Output.log(Output.PASSED, self.description)

                # And return our result
                return True

        elif self.endpoint is not None:

            # Execute the test code
            endpoint = self.parent.run(self.commands)[-1]

            # Check that the endpoint is correct
            if endpoint.endswith(self.endpoint):

                # If the endpoints are the same, things are good
                Output.clear()
                Output.log(Output.PASSED, self.description)

                # And return our result
                return True

        elif self.test is not None:

            # Iterate up to the test
            for element in range(self.test + 1):

                # Execute the commands
                result = self.parent.run([self.commands[element]], test = True)[-1]

            # And execute the rest of the commands
            for element in range(self.test + 1, len(self.commands)):

                # Execute the final commands
                self.parent.run([self.commands[element]])

            # Check that the output is correct
            if result.endswith('0'):

                # If the endpoints are the same, things are good
                Output.clear()
                Output.log(Output.PASSED, self.description)

                # And return our result
                return True

        # At this point, we obviously don't have the correct requirement
        Output.clear()
        Output.log(Output.FAILED, self.description)

        # And return our bad result
        return False