-
Notifications
You must be signed in to change notification settings - Fork 30
Added todict() method to Command #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Seemone
wants to merge
9
commits into
tonioo:master
Choose a base branch
from
Seemone:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6e3d4d9
Added todict() method to Command
e7a1565
Conformity to PEP8 for PR
58fca36
Fixed multiple arguments conversion in todict()
f04346f
More compact representation
7a96318
Fixed handling of list parameters
982b298
Merge remote-tracking branch 'upstream/master'
5009e50
todict(): Switched the attributes type and command and rely on Comman…
1ae3d4e
Added attribute name mapping capability to Command.todict()
284bd51
Added command name override and the ability to mangle args
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| import sys | ||
|
|
||
| from future.utils import python_2_unicode_compatible | ||
|
|
||
| from collections import OrderedDict | ||
|
|
||
| class CommandError(Exception): | ||
| """Base command exception class.""" | ||
|
|
@@ -138,6 +138,58 @@ def __init__(self, parent=None): | |
| def __repr__(self): | ||
| return "%s (type: %s)" % (self.name, self._type) | ||
|
|
||
| def iterify(self,iterable): | ||
| if not isinstance(iterable, list): | ||
| iterable = [iterable] | ||
| return iterable | ||
|
|
||
|
|
||
| def todict(self): | ||
| """Generate the dict representation corresponding to this command | ||
|
|
||
| Recursive method. | ||
|
|
||
| """ | ||
|
|
||
| j=OrderedDict() | ||
| comms=[] | ||
|
|
||
| if isinstance(self,TestCommand): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| j.update({"command": "test"}) | ||
| elif isinstance(self,ControlCommand): | ||
| j.update({"command": "control"}) | ||
| elif isinstance(self,ActionCommand): | ||
| j.update({"command": "action"}) | ||
| else: | ||
| j.update({"command": "unsupported"}) | ||
|
|
||
| j.update({"type": self.name}) | ||
|
|
||
| if self.hash_comments: | ||
| for comment in self.hash_comments: | ||
| comment_s=comment.decode("utf-8") | ||
| comms=comms + [comment_s] | ||
| j.update({"comments": comms}) | ||
|
|
||
| if self.arguments: | ||
| j.update({"arguments": OrderedDict()}) | ||
| for argname in self.arguments: | ||
| args=self.iterify(self[argname]) | ||
| for arg in args: | ||
| if isinstance(arg,Command): | ||
| j["arguments"].update(arg.todict()) | ||
| else: | ||
| j["arguments"].update({argname: str(arg).replace('"', '')}) | ||
|
|
||
| if self.children: | ||
| j.update({"children": []}) | ||
| for child in self.children: | ||
| #target.write(("*" * (indentlevel+10))+'{"'+argname+'": "'+str(arg)+'"},\n') | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this comment? |
||
| if isinstance(child,Command): | ||
| j["children"].append(child.todict()) | ||
| return j | ||
|
|
||
|
|
||
| def tosieve(self, indentlevel=0, target=sys.stdout): | ||
| """Generate the sieve syntax corresponding to this command | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you respect PEP8 please?