-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from harshitbansal05/cli-interface
Add cli interface for script adding/editing functions
- Loading branch information
Showing
13 changed files
with
206 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
*.pyc | ||
dist/ | ||
build/ | ||
retriever_recipes.egg-info | ||
apidocs | ||
*.DS_Store | ||
.cache/* | ||
|
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
from builtins import input | ||
|
||
from recipes.lib.get_opts import parser | ||
from recipes.lib.new_json import create_json | ||
from recipes.lib.edit_json import edit_json | ||
from recipes.lib.delete_json import delete_json | ||
|
||
|
||
def main(): | ||
"""This function launches the retriever-recipes.""" | ||
if len(sys.argv) == 1: | ||
# If no command line args are passed, show the help options | ||
parser.parse_args(['-h']) | ||
else: | ||
# Otherwise, parse them | ||
args = parser.parse_args() | ||
|
||
if args.command == 'new_json': | ||
# Create new JSON script | ||
create_json() | ||
return | ||
|
||
if args.command == 'edit_json': | ||
# Edit existing JSON script | ||
json_file = args.dataset.lower() | ||
edit_json(json_file) | ||
return | ||
|
||
if args.command == 'delete_json': | ||
# Delete existing JSON script | ||
confirm = input("Really remove " + args.dataset.lower() + | ||
" and all its contents? (y/N): ") | ||
if confirm.lower().strip() in ['y', 'yes']: | ||
json_file = args.dataset.lower() | ||
delete_json(json_file) | ||
return | ||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ENCODING = 'ISO-8859-1' | ||
SCRIPT_SEARCH_PATHS = ['scripts', './', '../scripts', '../'] |
File renamed without changes.
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import argparse | ||
import argcomplete | ||
|
||
from recipes.lib.utils import get_script_version | ||
from recipes.lib.defaults import SCRIPT_SEARCH_PATHS | ||
|
||
|
||
script_list = [] | ||
|
||
script_version_list = get_script_version(SCRIPT_SEARCH_PATHS) | ||
for script in script_version_list: | ||
script = script.split(',')[0] | ||
if script.endswith('.json'): | ||
script_list.append(('.'.join(script.split('.')[:-1])).replace('_', '-')) | ||
|
||
parser = argparse.ArgumentParser(prog='retriever-recipes') | ||
|
||
# .............................................................. | ||
# Subparsers | ||
# .............................................................. | ||
subparsers = parser.add_subparsers(help='sub-command help', dest='command') | ||
new_json_parser = subparsers.add_parser('new_json', help='CLI to create retriever json script') | ||
edit_json_parser = subparsers.add_parser('edit_json', help='CLI to edit retriever json script') | ||
delete_json_parser = subparsers.add_parser('delete_json', help='CLI to remove retriever json script') | ||
help_parser = subparsers.add_parser('help', help='') | ||
|
||
# .............................................................. | ||
# Subparsers With Arguments | ||
# .............................................................. | ||
edit_json_parser.add_argument('dataset', nargs=1, help='dataset name', choices=script_list) | ||
delete_json_parser.add_argument('dataset', nargs=1, help='dataset name', choices=script_list) | ||
|
||
argcomplete.autocomplete(parser) |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import platform | ||
import subprocess | ||
|
||
from setuptools import setup, find_packages | ||
|
||
|
||
current_platform = platform.system().lower() | ||
|
||
if os.path.exists(".git/hooks"): # check if we are in git repo | ||
subprocess.call("cp hooks/pre-commit .git/hooks/pre-commit", shell=True) | ||
subprocess.call("chmod +x .git/hooks/pre-commit", shell=True) | ||
|
||
def read(*names, **kwargs): | ||
return open( | ||
os.path.join(os.path.dirname(__file__), *names), | ||
).read() | ||
|
||
setup( | ||
name='retriever-recipes', | ||
version='0.0.1', | ||
description='Retriever Recieps', | ||
long_description='{a}'.format(a=read('README.md')), | ||
long_description_content_type='text/markdown', | ||
author='Harshit Bansal, Apoorva Pandey, Ben Morris, Shivam Negi, Akash Goel, Andrew Zhang, Henry Senyondo, Ethan White', | ||
author_email='[email protected]', | ||
url='https://github.com/weecology/retriever-recipes', | ||
classifiers=[ | ||
'Intended Audience :: Science/Research', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: Microsoft :: Windows', | ||
'Operating System :: POSIX', | ||
'Operating System :: Unix', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: Implementation :: PyPy', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
'Topic :: Scientific/Engineering :: GIS', | ||
'Topic :: Scientific/Engineering :: Information Analysis', | ||
'Topic :: Database', | ||
], | ||
packages=find_packages( | ||
exclude=['hooks', | ||
'docs', | ||
'tests', | ||
'scripts', | ||
'docker', | ||
".cache"]), | ||
entry_points={ | ||
'console_scripts': [ | ||
'retriever-recipes = recipes.__main__:main', | ||
], | ||
}, | ||
install_requires=[ | ||
'future', | ||
'argcomplete' | ||
], | ||
setup_requires=[], | ||
) | ||
|
||
# windows doesn't have bash. No point in using bash-completion | ||
if current_platform != "windows": | ||
# if platform is OS X use "~/.bash_profile" | ||
if current_platform == "darwin": | ||
bash_file = "~/.bash_profile" | ||
# if platform is Linux use "~/.bashrc | ||
elif current_platform == "linux": | ||
bash_file = "~/.bashrc" | ||
# else write and discard | ||
else: | ||
bash_file = "/dev/null" | ||
|
||
argcomplete_command = 'eval "$(register-python-argcomplete retriever-recipes)"' | ||
with open(os.path.expanduser(bash_file), "a+") as bashrc: | ||
bashrc.seek(0) | ||
# register retriever for arg-completion if not already registered | ||
# whenever a new shell is spawned | ||
if argcomplete_command not in bashrc.read(): | ||
bashrc.write(argcomplete_command + "\n") | ||
bashrc.close() | ||
os.system("activate-global-python-argcomplete") | ||
# register for the current shell | ||
os.system(argcomplete_command) |
This file contains 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
This file contains 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