Exemplo n.º 1
0
 def main(self, args):
     if args.meta:
         ini_file = args.app.get_cache_file('meta')
     else:
         ini_file = args.app.get_ini_file()
     parser = read_ini_file(ini_file, CaseSensitiveConfigParser)
     for section, attr, value in args.attrs:
         attribute = args.app.get_attr(underscore(attr))
         self.process(args.app, attribute, section, camelcase(attr), value,
                      parser)
     self.log('Rewriting %s' % ini_file)
     with NamedTemporaryFile('w+b') as tmp_ini_file:
         parser.write(tmp_ini_file)
         tmp_ini_file.flush()
         if not args.meta:
             for locale in ['en', 'de']:
                 new_app = App.from_ini(tmp_ini_file.name,
                                        locale=locale,
                                        cache=args.app.get_app_cache_obj())
                 if new_app is None:
                     raise Abort(
                         'ini file would be malformed. Not saving attributes!'
                     )
         shutil.copy2(tmp_ini_file.name, ini_file)
         os.chmod(ini_file, 0o644)
         args.app.get_app_cache_obj().clear_cache()
Exemplo n.º 2
0
 def process(self, app, attribute, section, attr, value, parser):
     if isinstance(attribute, AppFileAttribute):
         if section == 'Application':
             section = 'EN'
         attr = '%s_%s' % (underscore(attr), section)
         self.set_file_content(app, attr.upper(), value)
     else:
         self.set_ini_value(section, attr, value, parser)
Exemplo n.º 3
0
def get_extended_attributes(app):
    attributes = []
    object_classes = []
    parser = read_ini_file(app.get_cache_file('attributes'),
                           CaseSensitiveConfigParser)
    object_class_suffix = 1
    attribute_suffix = 1
    for section in parser.sections():
        kwargs = dict([underscore(key), value]
                      for key, value in parser.items(section))
        kwargs['name'] = section
        if kwargs.get('type') == 'ObjectClass':
            object_class = ObjectClass(app, **kwargs)
            if object_class.oid is None:
                object_class.set_standard_oid(app, object_class_suffix)
                object_class_suffix += 1
            attribute_logger.debug('Adding %s to list of classes' % section)
            object_classes.append(object_class)
        else:
            attribute = ExtendedAttribute(app, **kwargs)
            attribute_logger.debug('Adding %s to list of attributes' % section)
            if attribute.oid is None:
                attribute.set_standard_oid(app, attribute_suffix)
                attribute_suffix += 1
            attributes.append(attribute)
    if app.generic_user_activation:
        attribute_name = app.generic_user_activation
        if attribute_name is True:
            attribute_name = '%sActivated' % app.id
        if attribute_name not in [attr.name for attr in attributes]:
            attribute_logger.debug('Adding %s to list of attributes' %
                                   attribute_name)
            attribute = ExtendedAttribute(
                app,
                name=attribute_name,
                description='Activate user for %s' % app.name,
                description_de='Nutzer für %s aktivieren' % app.name,
                syntax='Boolean')
            attribute.set_standard_oid(app, attribute_suffix)
            attribute._full_width = True
            attributes.insert(0, attribute)
    for attribute in attributes:
        if attribute.belongs_to not in [obj.name for obj in object_classes]:
            class_name = attribute.belongs_to
            object_class = ObjectClass(app, name=class_name)
            object_class.set_standard_oid(app, object_class_suffix)
            object_classes.insert(0, object_class)
        object_class = [
            obj for obj in object_classes if obj.name == attribute.belongs_to
        ][0]
        if attribute.name not in re.split('\s*,\s*', object_class.must):
            object_class.may = '%s, %s' % (object_class.may, attribute.name)
    return attributes, object_classes
Exemplo n.º 4
0
def get_extended_attributes(app):
    attributes = []
    object_classes = []
    extended_options = []
    parser = read_ini_file(app.get_cache_file('attributes'),
                           CaseSensitiveConfigParser)
    object_class_suffix = 1
    attribute_suffix = 1
    for section in parser.sections():
        kwargs = dict([underscore(key), ucr_run_filter(value)]
                      for key, value in parser.items(section))
        kwargs['name'] = section
        kwargs.setdefault('type', 'ExtendedAttribute')
        if kwargs['type'] == 'ObjectClass':
            object_class = ObjectClass(app, **kwargs)
            if object_class.oid is None:
                object_class.set_standard_oid(app, object_class_suffix)
                object_class_suffix += 1
            attribute_logger.debug('Adding %s to list of classes' % section)
            object_classes.append(object_class)

            # for backwards compatibility with UCS 4.3 we can't use the new type == ExtendedOption, so this flag is the equivalent
            if kwargs.get('add_extended_option') == '1':
                okwargs = kwargs.copy()
                okwargs['name'] = kwargs.get('option_name',
                                             '%sUser' % (app.id, ))
                okwargs.setdefault('object_class', object_class.name)
                option = ExtendedOption(app, **okwargs)
                attribute_logger.debug('Adding %s to list of options' %
                                       (okwargs['name'], ))
                extended_options.append(option)
        elif kwargs[
                'type'] == 'ExtendedOption':  # Can't be used if System < UCS 4.4, use add_extended_option instead!
            option = ExtendedOption(app, **kwargs)
            attribute_logger.debug('Adding %s to list of options' % section)
            extended_options.append(option)
        elif kwargs['type'] == 'ExtendedAttribute':
            attribute = ExtendedAttribute(app, **kwargs)
            attribute_logger.debug('Adding %s to list of attributes' % section)
            if attribute.oid is None:
                attribute.set_standard_oid(app, attribute_suffix)
                attribute_suffix += 1
            attributes.append(attribute)
        else:  # ignore, so that it is extensible for the future :-)
            attribute_logger.warn('Unknown attribute type for section %s: %r' %
                                  (section, kwargs['type']))

    if app.generic_user_activation:
        attribute_name = app.generic_user_activation_attribute
        if attribute_name is not False:
            if attribute_name is True or not attribute_name:
                attribute_name = '%sActivated' % (app.id, )
            try:
                attribute = [
                    attr for attr in attributes if attr.name == attribute_name
                ][0]
            except IndexError:
                attribute_logger.debug('Adding %s to list of attributes' %
                                       attribute_name)
                attribute = ExtendedAttribute(
                    app,
                    module='users/user',
                    name=attribute_name,
                    description='Activate user for %s' % app.name,
                    description_de='Nutzer für %s aktivieren' % app.name,
                    syntax='Boolean',
                    full_width=False,
                )
                attribute.set_standard_oid(app, attribute_suffix)
                attributes.insert(0, attribute)

        option_name = app.generic_user_activation_option
        if option_name is True:
            option_name = '%sUser' % (app.id, )
        if option_name and option_name not in [
                opt.name for opt in extended_options
        ]:
            attribute_logger.debug('Adding %s to list of options' %
                                   option_name)
            option = ExtendedOption(
                app,
                name=option_name,
                module='users/user',
                object_class=option_name,
                long_description='Activate user for %s' % app.name,
                long_description_de='Nutzer für %s aktivieren' % app.name)
            extended_options.insert(0, option)

    for attribute in attributes:
        if attribute.belongs_to not in [obj.name for obj in object_classes]:
            class_name = attribute.belongs_to
            object_class = ObjectClass(app, name=class_name)
            object_class.set_standard_oid(app, object_class_suffix)
            object_class_suffix += 1
            object_classes.insert(0, object_class)
        object_class = [
            obj for obj in object_classes if obj.name == attribute.belongs_to
        ][0]
        if attribute.name not in re.split('\s*,\s*', object_class.must):
            object_class.may = '%s, %s' % (object_class.may, attribute.name)
        for option in extended_options:
            if option.name in (object_class.option_name, attribute.belongs_to):
                attribute.options.append(option.name)

    for option in extended_options:
        if option.object_class not in [obj.name for obj in object_classes]:
            class_name = option.object_class
            object_class = ObjectClass(app, name=class_name)
            object_class.set_standard_oid(app, object_class_suffix)
            object_class_suffix += 1
            object_classes.insert(0, object_class)

    return attributes, object_classes, extended_options
Exemplo n.º 5
0
 def get_action_name(cls):
     return underscore(cls.__name__).replace('_', '-')
Exemplo n.º 6
0
 def get_name(cls):
     return underscore(cls.__name__)