def to_dict(cls):
        """Creates dict out of list and regex attributes, so it can be passed to angular
            for frontend validation

            Returns:
                dict:
        """
        result = {}
        for attr_name in _.reject(set(dir(cls)), lambda x: x.startswith('_')):
            attr = getattr(cls, attr_name)
            if _.is_list(attr) or _.is_string(attr):
                result[attr_name] = attr
        return result
    def create(cls, name, required=True):
        """Creates validation function from given attribute name

        Args:
            name (string): Name of attribute
            required (bool, optional) If false, empty string will be always accepted as valid

        Returns:
            function: validation function
        """
        attr = getattr(cls, name)
        if _.is_list(attr):
            return util.create_validator(lengths=attr, required=required)
        elif _.is_string(attr):
            return util.create_validator(regex=attr, required=required)
        elif _.is_function(attr):
            return attr
Exemple #3
0
 def run(self):
     c = self.app.conf
     log = self.app.log
     s = self.app.services
     spinner = self.app.spinner
     setattr(self.app, 'release', s.configure.load_release())
     release = self.app.release
     spinner.stop()
     log.debug('release: ' + json.dumps(release, indent=4, sort_keys=True))
     spinner.start()
     self.app.conf = munchify(_.merge({}, self.app.conf, {
         'codename': c.codename if 'codename' in c else release.distrib_codename,
         'origin': c.origin if 'origin' in c else release.distrib_id,
         'name': c.name if 'name' in c else release.distrib_name,
         'version': c.version if 'version' in c else release.distrib_version
     }))
     preseed = c.preseed if ('preseed' in c and c.preseed != True) else _.snake_case(c.name)
     if _.is_string(preseed) and preseed[len(preseed) - 5:] != '.seed':
         preseed = preseed + '.seed'
     self.app.conf = munchify(_.merge({}, self.app.conf, {
         'description': c.description if 'description' in c else c.name + ' ' + c.version,
         'hostname': c.hostname if 'hostname' in c else _.snake_case(c.name).replace('_', '-'),
         'preseed': preseed
     }))