Message ID | 1431519294-8873-3-git-send-email-M.Cerveny@computer.org |
---|---|
State | New |
Headers | show |
On 13/05/2015 14:14, Martin Cerveny wrote: > for item in items: > if item['type'].startswith('child<'): > - list_node(path + '/' + item['name']) > + list_node((path if (path != '/') else '') + '/' + item['name']) I'm not sure which Python version introduced if...else. The more traditional idiom would be path != '/' and path or '' Can you use it, and move the expression out of the 'for item in items' loop into a variable? Paolo
Hello. Ternary/if/else >= python 2.5 (I use the same coding as in scripts/qmp/qemu-ga-client). "import json" >= python 2.6 (scripts/qmp/qmp.py) "import argparse" >= python 2.7 (scripts/analyze-migration.py, scripts/vmstate-static-checker.py) "import optparse" < python 2.7 (deprecated, scripts/qmp/qemu-ga-client) .... Of course there is no problem to use traditional syntax. (My platform (centos5.10) has python2.4, I must also replace json imports: try: import json except ImportError: import simplejson as json ) Which version of python is officialy minimum supported ? Thanks for explanation of python status. M.C> On Thu, 14 May 2015, Paolo Bonzini wrote: > > > On 13/05/2015 14:14, Martin Cerveny wrote: >> for item in items: >> if item['type'].startswith('child<'): >> - list_node(path + '/' + item['name']) >> + list_node((path if (path != '/') else '') + '/' + item['name']) > > I'm not sure which Python version introduced if...else. The more > traditional idiom would be > > path != '/' and path or '' > > Can you use it, and move the expression out of the 'for item in items' > loop into a variable? > > Paolo >
On 14/05/2015 13:41, Martin Cerveny wrote: > Hello. > > Ternary/if/else >= python 2.5 (I use the same coding as in > scripts/qmp/qemu-ga-client). Oh, that's old. Shows my knowledge of Python. Then your patch is okay---thanks for enduring with me. :) Paolo > "import json" >= python 2.6 (scripts/qmp/qmp.py) > "import argparse" >= python 2.7 (scripts/analyze-migration.py, > scripts/vmstate-static-checker.py) > "import optparse" < python 2.7 (deprecated, scripts/qmp/qemu-ga-client) > .... > > Of course there is no problem to use traditional syntax. > (My platform (centos5.10) has python2.4, I must also replace json imports: > try: > import json > except ImportError: > import simplejson as json > ) > > Which version of python is officialy minimum supported ? > > Thanks for explanation of python status. > > M.C>
Am 14.05.2015 um 13:47 schrieb Paolo Bonzini: > On 14/05/2015 13:41, Martin Cerveny wrote: >> Hello. >> >> Ternary/if/else >= python 2.5 (I use the same coding as in >> scripts/qmp/qemu-ga-client). > > Oh, that's old. Shows my knowledge of Python. > > Then your patch is okay---thanks for enduring with me. :) Thanks, applied to qom-next then: https://github.com/afaerber/qemu-cpu/commits/qom-next Andreas
diff --git a/scripts/qmp/qom-tree b/scripts/qmp/qom-tree index 07f8a9d..c3e3738 100755 --- a/scripts/qmp/qom-tree +++ b/scripts/qmp/qom-tree @@ -75,6 +75,11 @@ def list_node(path): print '' for item in items: if item['type'].startswith('child<'): - list_node(path + '/' + item['name']) + list_node((path if (path != '/') else '') + '/' + item['name']) -list_node('/machine') +if len(args) == 0: + path = '/' +else: + path = args[0] + +list_node(path)
Add processing of optional argument path as "tree base". Signed-off-by: Martin Cerveny <M.Cerveny@computer.org> --- scripts/qmp/qom-tree | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)