Exemplo n.º 1
0
    def get_default_loglevel_from_environment(self):
        """
        Returns a default log level based on the AUTOBUILD_LOGLEVEL environment variable

        This may be used directly by the user, but in combination with the
        set_recursive_loglevel method below also ensures 
        that any recursive invocation of autobuild inherits the same level as the
        parent, even if intervening commands do not pass it through.
        """
        try:
            environment_level = os.environ[AUTOBUILD_LOGLEVEL]
        except KeyError:
            environment_level = ''

        if environment_level == '--quiet' or environment_level == '-q':
            return logging.ERROR
        elif environment_level == '':
            return logging.WARNING
        elif environment_level == '--verbose' or environment_level == '-v':
            return logging.INFO
        elif environment_level == '--debug' or environment_level == '-d':
            return logging.DEBUG
        else:
            raise AutobuildError("invalid %s value '%s'" %
                                 (AUTOBUILD_LOGLEVEL, environment_level))
Exemplo n.º 2
0
 def delete(self, name='', platform='', **kwargs):
     """
     Delete the named config value.
     """
     if not name:
         raise AutobuildError(
             "Name argument must be provided with --delete option.")
Exemplo n.º 3
0
def verify_hash(hash_algorithm, pathname, hash):
    """
    Primary entry point for this module
    """
    if not hash:
        # If there's no specified hash value, what can we do? We could
        # unconditionally fail, but that risks getting the user stuck. So
        # -- if there's no specified hash value, unconditionally accept
        # the download.
        print "Warning: unable to verify %s; expected hash value not specified" % pathname
        return True

    if not hash_algorithm:
        # Historical: if there IS a hash value, but no hash_algorithm,
        # assume MD5 because that used to be the only supported hash
        # algorithm. There may be files out there that don't specify.
        hash_algorithm = "md5"

    try:
        function = REGISTERED_ALGORITHMS[hash_algorithm]
    except KeyError:
        raise AutobuildError("Unsupported hash type %s for %s" %
                             (hash_algorithm, pathname))

    # Apparently we do have a function to support this hash_algorithm. Call
    # it.
    return function(pathname, hash)
Exemplo n.º 4
0
 def _get_configuration(self, name='', platform=''):
     if not name or not platform:
         raise AutobuildError(
             "'name' and 'platform' arguments must both be provided with --delete option."
         )
     platform_description = self.config.get_platform(platform)
     configuration = platform_description.configurations.get(name)
     return configuration
Exemplo n.º 5
0
 def delete(self, name='', **kwargs):
     """
     Delete the named config value.
     """
     if not name:
         raise AutobuildError(
             "'name' argument must be provided with --delete option.")
     print "Deleting entry."
     self.config.package_description.platforms.pop(name)
Exemplo n.º 6
0
    def interactive_mode(self, delete=False):
        """
        Utility to run a command in interactive mode.

        Requires:
            self to be a class describing the feature to be configured interactively.
        """
        try:
            getattr(self, 'ARGUMENTS')
        except AttributeError:
            raise AutobuildError("Interactive mode not supported.")

        command = '%s' % self.__class__.__name__
        command = command.lower()
        if getattr(self, 'description', ''):
            print '\n%s' % self.description

        action = "Create or update"
        if delete:
            action = "Delete"
        print "\n%s %s details:" % (action, command)
        if getattr(self, 'help', ''):
            print self.help
        print "Any fields left blank will remain unchanged."
        print "Any fields entered as 'none' will clear the existing value."

        input_values = {}
        for argument in self.ARGUMENTS:
            try:
                helptext = self.ARG_DICT[argument]['help']
                i = raw_input("    %s> " % helptext)
                if i:
                    if i.lower() == 'none':
                        i = ''
                    input_values[argument] = i
            except EOFError:
                print ""
                exit = 'y'
                exit = raw_input("Do you really want to exit ([y]/n)? ")
                if exit == 'y':
                    sys.exit(0)

        print "These fields will be changed:"
        print input_values
        if delete:
            if self._confirm_delete():
                self.delete(**input_values)
        else:
            save = raw_input("Save to config (y/[n])? ")
            if save in ['y', 'Y', 'yes', 'Yes', 'YES']:
                self.run(**input_values)
            else:
                print "Not saved."
Exemplo n.º 7
0
    def _create_build_config_desc(self, config, name, platform, build,
                                  configure):
        if not name:
            raise AutobuildError('build configuration name not given')

        init_dict = dict({
            'build': build,
            'configure': configure,
            'name': name
        })
        build_config_desc = configfile.BuildConfigurationDescription(init_dict)
        try:
            platform_description = config.get_platform(platform)
        except configfile.ConfigurationError:
            platform_description = configfile.PlatformDescription()
            platform_description.name = platform
        platform_description.configurations[name] = build_config_desc
        config.package_description.platforms[platform] = platform_description
        return build_config_desc
Exemplo n.º 8
0
 def delete(self, **kwargs):
     """
     Stub for the delete command.
     """
     raise AutobuildError("Delete not yet implemented for this command.")
Exemplo n.º 9
0
 def non_interactive_delete(**kwargs):
     """
     To be used in the case where 'self.interactive_delete' is False.
     """
     raise AutobuildError("Delete not yet implemented for this command.")