Merge lp:~eeejay/mago/typed_args into lp:~mago-contributors/mago/mago-1.0

Proposed by Eitan Isaacson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~eeejay/mago/typed_args
Merge into: lp:~mago-contributors/mago/mago-1.0
Diff against target: None lines
To merge this branch: bzr merge lp:~eeejay/mago/typed_args
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Joker Wild (community) Approve
Nagappan Alagappan Approve
Review via email: mp+10219@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Eitan Isaacson (eeejay) wrote :

This branch adds the following features to suite/case argument parsing:

1. First attempt to parse argument values as integers, reverting to strings.
2. Allow nested dictionaries.
3. Allow lists.

The following XML args:
    <args>
      <partition_device>/dev/sda</partition_device>
      <table>
        <partition>
          <fs>ext4</fs>
          <mountpoint>/</mountpoint>
          <size>1234</size>
          <primary>1</primary>
        </partition>
        <partition>
          <fs>ext4</fs>
          <mountpoint>/home</mountpoint>
          <size>4321</size>
          <primary>1</primary>
        </partition>
      </table>
    </args>

Will be parsed like this:

partition_device = '/dev/sda',
table = {'partition': [{'fs': 'ext4',
                        'mountpoint': '/',
                        'primary': 1,
                        'size': 1234},
                       {'fs': 'ext4',
                        'mountpoint': '/home',
                        'primary': 1,
                        'size': 4321}]}}

Revision history for this message
Nagappan Alagappan (nagappan) wrote :

This is pretty neat :)

review: Approve
Revision history for this message
Joker Wild (lajjr-deactivatedaccount) wrote :

Nice.
Regards,
lajjr

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

Hello,

Looks fine. I just wanted to ask about the 'ascii' encoding part. As far as I know there's a japanese test case for gedit and I'm not sure if it's safe to assume that arguments can be ascii encoded.

Best regards,
    Javier

review: Needs Information
Revision history for this message
Eitan Isaacson (eeejay) wrote :

The ascii encoding is only for keys, not values. It is not a change I introduced, it was there before my branch (see diff below).

> Hello,
>
> Looks fine. I just wanted to ask about the 'ascii' encoding part. As far as I
> know there's a japanese test case for gedit and I'm not sure if it's safe to
> assume that arguments can be ascii encoded.
>
> Best regards,
> Javier

Revision history for this message
Javier Collado (javier.collado) wrote :

Thanks for the explanation Eitan.

review: Approve
Revision history for this message
Eitan Isaacson (eeejay) wrote :

Thanks for the approval folks. I'll merge this, hope Ara approves when she is back from holiday ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mago/cmd/discovery.py'
2--- mago/cmd/discovery.py 2009-08-06 14:53:33 +0000
3+++ mago/cmd/discovery.py 2009-08-16 22:53:59 +0000
4@@ -126,14 +126,29 @@
5 """
6 Return suite arguments as a dictionary
7 """
8- args_tag = self.root.find('args')
9+ def _parse_args(tag):
10+ if tag is None:
11+ return {}
12+
13+ if len(tag) == 0:
14+ try:
15+ return int(tag.text)
16+ except ValueError:
17+ return tag.text
18+
19+ rv = {}
20+ for child in tag:
21+ key = child.tag.encode('ascii')
22+ value = _parse_args(child)
23+ try:
24+ rv[key].append(value)
25+ except AttributeError:
26+ rv[key] = [rv[key], value]
27+ except KeyError:
28+ rv[key] = value
29+ return rv
30
31- if not args_tag:
32- return {}
33-
34- return dict([(arg.tag.encode('ascii'), (arg.text or '').strip())
35- for arg in args_tag])
36-
37+ return _parse_args(self.root.find('args'))
38
39 @property
40 def description(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: