-
Notifications
You must be signed in to change notification settings - Fork 5
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
Corrected project to conform to PEP8 style. Passed pep8, py27, cover … #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,46 @@ | ||
""" | ||
cli.py constructs a cli interface of commands, options, and subcommands in argparse, given data structures from commands.py | ||
""" | ||
import argparse | ||
import json | ||
from pybluedot.commands import cmd, subcmd | ||
from pybluedot.commands import cmd_arg | ||
from pybluedot.commands import sub_cmd | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def cmd_to_args(cmd_arg): | ||
"""creates argparse arguments from commands.cmd dict. | ||
return argparse object. | ||
""" | ||
all_args = argparse.ArgumentParser() | ||
for arg in cmd_arg: | ||
for i in sorted(arg.keys()): | ||
# TODO(gamefiend) | ||
pass | ||
return all_args | ||
|
||
|
||
def cmd_to_subs(sub_cmd): | ||
"""creates subcommand arguments from commands.subcmd dict. | ||
returns argparse object. | ||
""" | ||
all_subs = argparse.ArgumentParser() | ||
for sub in sub_cmd: | ||
for i in sorted(sub): | ||
# TODO(gamefiend) | ||
pass | ||
return all_subs | ||
|
||
|
||
if __name__ == "__main__": | ||
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. See https://github.com/commitmas/pybluedot/blob/master/setup.cfg#L24 and study up on the setuptools configuration. In short, none of the Python files we develop will be called directly - that role will be fulfilled by a console script ("binary") generated by setuptools. What you should do is create a "main()" function here so that the current setuptools configuration knows what to grab. Then, running this is simple:
|
||
bdot_args = cmd_to_args(cmd_arg) | ||
bdot_subcmds = cmd_to_subs(sub_cmd) | ||
bdot_args.parse() | ||
bdot_subcmds.parse() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,39 @@ | ||
""" commands.py contains the data structures that cli.py uses to construct the arguments/subcommand structure. | ||
""" | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# global arguments and flags to the command, like '--verbose' or '--debug' | ||
cmd_arg = [ | ||
{ | ||
name: "verbose", | ||
action: "store_const" | ||
}, | ||
{ | ||
name: "debug", | ||
action: "store_const" | ||
} | ||
] | ||
|
||
# subcommands used by the program, like 'bdot init' or 'bdot search'. | ||
# Subcommands are tied to functions, so you must specify a function to use with each subcommand. | ||
sub_cmd = [ | ||
{ | ||
name: "init", | ||
help: "create a pybluedot configuration file", | ||
options: [ | ||
{ | ||
name: "--force", | ||
action: "store_const" | ||
}, | ||
{ | ||
name: "--display", | ||
action: "store_const" | ||
} | ||
], | ||
function: "init" | ||
}, | ||
{ | ||
name: "sounds", | ||
help: "just useless boilerplate atm!", | ||
options: [], | ||
function: "sounds" | ||
} | ||
] | ||
cmd_arg = [{ | ||
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. Honestly, this approach of having args in a list like this may be more trouble than it's worth. Just a gut feeling - you may consider seeing what @jeorryb did here: #13 on args, and try to gel this approach with that one. It's possible do to it, but you would have to use the same options for each arg, which you may not want. |
||
'name': 'verbose', | ||
'action': 'store_const' | ||
}, { | ||
'name': 'debug', | ||
'action': 'store_const' | ||
}] | ||
|
||
# subcommands used by the program, like 'bdot init' | ||
sub_cmd = [{ | ||
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. I consider this format less readable than the previous way you had written this. I know it probably seems overly verbose, but at a glance, I could easily see what was a dict, what was a list, etc. Now, I can't. |
||
'name': 'init', | ||
'help': 'create a pybluedot configuration file', | ||
'options': [{ | ||
'name': '--force', | ||
'action': 'store_const' | ||
}, { | ||
'name': '--display', | ||
'action': 'store_const' | ||
}], | ||
'function': 'init' | ||
}, { | ||
'name': 'sounds', | ||
'help': 'just useless boilerplate atm!', | ||
'options': [], | ||
'function': 'sounds' | ||
}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
from pybluedot.tests import base | ||
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. No unit tests for the functions you've created? 😄 |
||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class SampleTestSuite(base.DietTestCase): | ||
"""This test suite provides some common things relevant to the | ||
|
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.
For all files, could you move this licensing statement above the imports? Should be the first thing at the top so you don't have to jump over this to see your imports.