[apparmor] [patch][utils] Refractor prompts to class

Kshitij Gupta kgupta8592 at gmail.com
Tue Oct 7 08:06:12 UTC 2014


Hello,

Sorry for the delayed response, I was unable find time for the same
(owing to exams).

On Mon, Sep 22, 2014 at 2:26 AM, Christian Boltz <apparmor at cboltz.de> wrote:
> Hello,
>
> Am Mittwoch, 10. September 2014 schrieb Kshitij Gupta:
>> In keeping with the idea to make the less Perl-ish and more OOP style
>> (in hope to get more Pythonic). I thought it was a simple place to
>> start off with.
>>
>> Any suggestions and changes for the patch are welcome.
>>
>> The following patch:
>> - creates a class for prompt questions moving away from Perl hash hack
>> for the purpose.
>> - moves some functions to the methods for that class
>> - fix options being incorrectly passed to questionPrompt in
>> aa-mergeprof
>>
>> Due to the functions being moved around the patch is a bit long.
>
> That, and lots of q.['whatever'] -> q.whatever changes ;-)
>
Well due to a patch to fix the messages so that they named parameters,
this patch got a bit broken.

Attached below is the updated patch and a diff of the old and new
patch to make things easier (harder?).

>> Basic testing done with logprof.
>

Again basic ui tested with logprof.

> The patch looks good, with one exception:
>
> === modified file 'utils/apparmor/ui.py'
> --- utils/apparmor/ui.py    2014-08-06 17:07:41 +0000
> +++ utils/apparmor/ui.py    2014-09-10 06:59:16 +0000
>
> +    def promptUser(self, params=''):
> +        cmd = None
> +        arg = None
> +        if UI_mode == 'text':
> +            cmd, arg = self.Text_PromptUser()
> +        else:
> +            q.type = 'wizard'
> +            SendDataToYast(q)
> +            ypath, yarg = GetDataFromYast()
>
> That should probably be
>             ypath, yarg = self.GetDataFromYast()
> (note the added "self.")
>
No the self is not needed as the function is from a different module
and a method of the class.

Regards,

Kshitij Gupta

> With this fixed,
> Acked-by: Christian Boltz <apparmor at cboltz.de>
>
>
> Regards,
>
> Christian Boltz
> --
>> I'll be happy to fix the wording or Germanglish :D
> And shift it to Netherlangish? ;)
> [> Jos Poortvliet and Lars Müller in opensuse-project]
>
>
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
-------------- next part --------------
2,12c2,3
< --- utils/aa-mergeprof	2014-09-03 23:49:47 +0000
< +++ utils/aa-mergeprof	2014-09-10 09:46:48 +0000
< @@ -26,7 +26,7 @@
<  from apparmor.translations import init_translation
<  _ = init_translation()
<  
< -parser = argparse.ArgumentParser(description=_('Perform a 2-way or 3-way merge on the given profiles'), 
< +parser = argparse.ArgumentParser(description=_('Perform a 2-way or 3-way merge on the given profiles'),
<      epilog='WARNING: the arguments will change in a future version!')
<  parser.add_argument('mine', type=str, help=_('your profile'))
<  parser.add_argument('base', type=str, help=_('base profile'))
---
> --- utils/aa-mergeprof	2014-09-14 18:17:00 +0000
> +++ utils/aa-mergeprof	2014-10-07 07:59:39 +0000
263,264c254,255
< --- utils/apparmor/aa.py	2014-09-08 12:31:18 +0000
< +++ utils/apparmor/aa.py	2014-09-10 07:07:21 +0000
---
> --- utils/apparmor/aa.py	2014-10-01 19:45:22 +0000
> +++ utils/apparmor/aa.py	2014-10-07 07:57:48 +0000
621,622c612,613
< --- utils/apparmor/tools.py	2014-03-06 19:54:38 +0000
< +++ utils/apparmor/tools.py	2014-09-10 09:34:19 +0000
---
> --- utils/apparmor/tools.py	2014-09-14 18:17:00 +0000
> +++ utils/apparmor/tools.py	2014-10-07 08:00:03 +0000
630c621
< -                q['explanation'] = _('The local profile for %s in file %s was changed. Would you like to save it?') % (program, filename)
---
> -                q['explanation'] = _('The local profile for %(program)s in file %(file)s was changed. Would you like to save it?') % { 'program': program, 'file': filename }
637c628
< +                q.explanation = _('The local profile for %s in file %s was changed. Would you like to save it?') % (program, filename)
---
> +                q.explanation = _('The local profile for %(program)s in file %(file)s was changed. Would you like to save it?') % { 'program': program, 'file': filename }
652,653c643,644
< --- utils/apparmor/ui.py	2014-08-06 17:07:41 +0000
< +++ utils/apparmor/ui.py	2014-09-10 06:59:16 +0000
---
> --- utils/apparmor/ui.py	2014-09-14 18:17:00 +0000
> +++ utils/apparmor/ui.py	2014-10-07 07:59:52 +0000
732c723
< +                raise AppArmorException(_('PromptUser: Duplicate hotkey for %s: %s ') % (cmd, menutext))
---
> +                raise AppArmorException(_('PromptUser: Duplicate hotkey for %(command)s: %(menutext)s ') % { 'command': cmd, 'menutext': menutext })
837c828,829
< @@ -323,134 +467,6 @@
---
> @@ -322,135 +466,6 @@
>                      })
840c832
<  
---
> -
866c858
< -            raise AppArmorException(_('PromptUser: Duplicate hotkey for %s: %s ') % (cmd, menutext))
---
> -            raise AppArmorException(_('PromptUser: Duplicate hotkey for %(command)s: %(menutext)s ') % { 'command': cmd, 'menutext': menutext })
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ui_refractor.patch3
Type: application/octet-stream
Size: 42095 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20141007/8b56d798/attachment-0001.obj>


More information about the AppArmor mailing list