From 4caf917c36a3e487b97b878f68a42215157c625e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 12 Jan 2015 12:22:18 +0100 Subject: [PATCH] Simplified try/except with docopt --- EMSL_api.py | 14 +++++------- setup.py | 59 ------------------------------------------------- src/__init__.py | 0 3 files changed, 5 insertions(+), 68 deletions(-) delete mode 100755 setup.py create mode 100644 src/__init__.py diff --git a/EMSL_api.py b/EMSL_api.py index c3e1837..74afdb0 100755 --- a/EMSL_api.py +++ b/EMSL_api.py @@ -33,14 +33,10 @@ version = "0.2.0" import sys -try: - from docopt import docopt - from EMSL_utility import EMSL_dump - from EMSL_utility import format_dict - from EMSL_utility import EMSL_local -except: - print "Run setup.py then source EMSL_api.rc" - sys.exit(1) +from src.docopt import docopt +from src.EMSL_utility import EMSL_dump +from src.EMSL_utility import format_dict +from src.EMSL_utility import EMSL_local if __name__ == '__main__': @@ -50,7 +46,7 @@ if __name__ == '__main__': db_path = arguments["--db_path"] else: import os - db_path = os.path.dirname(sys.argv[0]) + "/db/Gamess-us.db" + db_path = os.path.dirname(__file__) + "/db/Gamess-us.db" # _ _ _ ______ _ #| | (_) | | | ___ \ (_) diff --git a/setup.py b/setup.py deleted file mode 100755 index 92cb5f0..0000000 --- a/setup.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys -import os - -ins = False - -d = {'y': True, - 'n': False} - -try: - import requests -except: - print "You need requests for dowload the basis, without you still can read a existing DB" - - while True: - choice = raw_input('Do you want to install it ? [Y/N]') - try: - ins = d[choice.lower()] - break - except: - print "not a valid choice" - - -if ins: - try: - import pip - pip.main(['install', "requests"]) - except: - print "You need pip, (http://pip.readthedocs.org/en/latest/installing.html)" - sys.exit(1) - -path = os.path.split(os.path.abspath(sys.argv[0]))[0] - - -completion_function = \ - """ -function _mycomplete_() -{ - local word=${COMP_WORDS[COMP_CWORD]} - - if [ $COMP_CWORD -eq 1 ]; then - opt="%s" - COMPREPLY=( $(compgen -W "${opt}" -- $word)) - else - COMPREPLY=() - fi -} - -complete -o default -F _mycomplete_ ./EMSL_api.py -""" % " ".join(["get_list_basis", "get_list_elements", "get_basis_data", "get_list_formats", "create_db", "-h", "--help", "--version"]) - -with open(path + "/EMSL_api.rc", "w") as f: - f.write("export EMSL_API_ROOT=%s" % path + "\n") - f.write("export PYTHONPATH=${PYTHONPATH}:${EMSL_API_ROOT}/src" + "\n") - f.write(completion_function) - -print "Source EMSL_api.rc, pls" diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29