We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error when running retriever license with no dataset as argument
Currently, when running `retriever license` and providing no dataset as an argument it results into `KeyError: 'No dataset named: None'`
![retriever_ls](https://user-images.githubusercontent.com/21103831/56208546-069b7b00-606f-11e9-84e5-9952be6cc097.png)

In case of `retriever citation` if no dataset is given we show the citation for retriever. 
![retriever_ct](https://user-images.githubusercontent.com/21103831/56208927-ef10c200-606f-11e9-89aa-056c1c126e33.png)

How should we handle this? Show the license for retriever by reading the `LICENSE` file or create a new `LICENSE` variable in `retriever.lib.defaults` and show it?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `retriever/__main__.py`
Content:
```
1 """Data Retriever
2 
3 This module handles the CLI for the Data retriever.
4 """
5 from __future__ import absolute_import
6 from __future__ import print_function
7 
8 import os
9 import sys
10 from builtins import input
11 
12 from retriever.engines import engine_list, choose_engine
13 from retriever.lib.datapackage import create_json, edit_json, delete_json, get_script_filename
14 from retriever.lib.datasets import datasets, dataset_names, license
15 from retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS
16 from retriever.lib.engine_tools import name_matches, reset_retriever
17 from retriever.lib.get_opts import parser
18 from retriever.lib.repository import check_for_updates
19 from retriever.lib.scripts import SCRIPT_LIST, reload_scripts, get_script
20 
21 
22 def main():
23     """This function launches the Data Retriever."""
24     if len(sys.argv) == 1:
25         # if no command line args are passed, show the help options
26         parser.parse_args(['-h'])
27 
28     else:
29         # otherwise, parse them
30         args = parser.parse_args()
31 
32         if args.command not in ['reset', 'update'] \
33         and not os.path.isdir(SCRIPT_SEARCH_PATHS[1]) \
34         and not [f for f in os.listdir(SCRIPT_SEARCH_PATHS[-1])
35             if os.path.exists(SCRIPT_SEARCH_PATHS[-1])]:
36                 check_for_updates()
37                 reload_scripts()
38         script_list = SCRIPT_LIST()
39 
40         if args.command == "install" and not args.engine:
41             parser.parse_args(['install', '-h'])
42 
43         if args.quiet:
44             sys.stdout = open(os.devnull, 'w')
45 
46         if args.command == 'help':
47             parser.parse_args(['-h'])
48 
49         if hasattr(args, 'compile') and args.compile:
50             script_list = reload_scripts()
51 
52         if args.command == 'defaults':
53             for engine_item in engine_list:
54                 print("Default options for engine ", engine_item.name)
55                 for default_opts in engine_item.required_opts:
56                     print(default_opts[0], " ", default_opts[2])
57                 print()
58             return
59 
60         if args.command == 'update':
61             check_for_updates()
62             reload_scripts()
63             return
64 
65         elif args.command == 'citation':
66             if args.dataset is None:
67                 print("\nCitation for retriever:\n")
68                 print(CITATION)
69             else:
70                 scripts = name_matches(script_list, args.dataset)
71                 for dataset in scripts:
72                     print("\nDataset:  {}".format(dataset.name))
73                     print("Citation:   {}".format(dataset.citation))
74                     print("Description:   {}\n".format(dataset.description))
75 
76             return
77 
78         elif args.command == 'license':
79             dataset_license = license(args.dataset)
80             if dataset_license:
81                 print(dataset_license)
82             else:
83                 print("There is no license information for {}".format(args.dataset))
84             return
85 
86         elif args.command == 'new':
87             f = open(args.filename, 'w')
88             f.write(sample_script)
89             f.close()
90 
91             return
92 
93         elif args.command == 'reset':
94             reset_retriever(args.scope)
95             return
96 
97         elif args.command == 'new_json':
98             # create new JSON script
99             create_json()
100             return
101 
102         elif args.command == 'edit_json':
103             # edit existing JSON script
104             json_file = get_script_filename(args.dataset.lower())
105             edit_json(json_file)
106             return
107 
108         elif args.command == 'delete_json':
109             # delete existing JSON script from home directory and or script directory if exists in current dir
110             confirm = input("Really remove " + args.dataset.lower() +
111                             " and all its contents? (y/N): ")
112             if confirm.lower().strip() in ['y', 'yes']:
113                 json_file = get_script_filename(args.dataset.lower())
114                 delete_json(json_file)
115             return
116 
117         if args.command == 'ls':
118             # scripts should never be empty because check_for_updates is run on SCRIPT_LIST init
119             if not (args.l or args.k or isinstance(args.v, list)):
120                 all_scripts = dataset_names()
121                 print("Available datasets : {}\n".format(len(all_scripts)))
122                 from retriever import lscolumns
123 
124                 lscolumns.printls(all_scripts)
125 
126             elif isinstance(args.v, list):
127                 if args.v:
128                     try:
129                         all_scripts = [get_script(dataset) for dataset in args.v]
130                     except KeyError:
131                         all_scripts = []
132                         print("Dataset(s) is not found.")
133                 else:
134                     all_scripts = datasets()
135                 count = 1
136                 for script in all_scripts:
137                     print(
138                         "{count}. {title}\n {name}\n"
139                         "{keywords}\n{description}\n"
140                         "{licenses}\n{citation}\n"
141                         "".format(
142                             count=count,
143                             title=script.title,
144                             name=script.name,
145                             keywords=script.keywords,
146                             description=script.description,
147                             licenses=str(script.licenses[0]['name']),
148                             citation=script.citation,
149                         )
150                     )
151                     count += 1
152 
153             else:
154                 param_licenses = args.l if args.l else None
155                 keywords = args.k if args.k else None
156 
157                 # search
158                 searched_scripts = datasets(keywords, param_licenses)
159                 if not searched_scripts:
160                     print("No available datasets found")
161                 else:
162                     print("Available datasets : {}\n".format(len(searched_scripts)))
163                     count = 1
164                     for script in searched_scripts:
165                         print(
166                             "{count}. {title}\n{name}\n"
167                             "{keywords}\n{licenses}\n".format(
168                                 count=count,
169                                 title=script.title,
170                                 name=script.name,
171                                 keywords=script.keywords,
172                                 licenses=str(script.licenses[0]['name']),
173                             )
174                         )
175                         count += 1
176             return
177 
178         engine = choose_engine(args.__dict__)
179 
180         if hasattr(args, 'debug') and args.debug:
181             debug = True
182         else:
183             debug = False
184             sys.tracebacklimit = 0
185 
186         if hasattr(args, 'debug') and args.not_cached:
187             engine.use_cache = False
188         else:
189             engine.use_cache = True
190 
191         if args.dataset is not None:
192             scripts = name_matches(script_list, args.dataset)
193         else:
194             raise Exception("no dataset specified.")
195         if scripts:
196             for dataset in scripts:
197                 print("=> Installing", dataset.name)
198                 try:
199                     dataset.download(engine, debug=debug)
200                     dataset.engine.final_cleanup()
201                 except KeyboardInterrupt:
202                     pass
203                 except Exception as e:
204                     print(e)
205                     if debug:
206                         raise
207             print("Done!")
208         else:
209             print("Run 'retriever ls' to see a list of currently available datasets.")
210 
211 
212 if __name__ == "__main__":
213     main()
214
```

Path: `retriever/lib/defaults.py`
Content:
```
1 import os
2 
3 from retriever._version import __version__
4 
5 VERSION = __version__
6 COPYRIGHT = "Copyright (C) 2011-2016 Weecology University of Florida"
7 REPO_URL = "https://raw.githubusercontent.com/weecology/retriever/"
8 MASTER_BRANCH = REPO_URL + "master/"
9 REPOSITORY = MASTER_BRANCH
10 ENCODING = 'ISO-8859-1'
11 HOME_DIR = os.path.expanduser('~/.retriever/')
12 SCRIPT_SEARCH_PATHS = [
13     "./",
14     'scripts',
15     os.path.join(HOME_DIR, 'scripts/')
16 ]
17 SCRIPT_WRITE_PATH = SCRIPT_SEARCH_PATHS[-1]
18 DATA_SEARCH_PATHS = [
19     "./",
20     "{dataset}",
21     "raw_data/{dataset}",
22     os.path.join(HOME_DIR, 'raw_data/{dataset}'),
23 ]
24 DATA_WRITE_PATH = DATA_SEARCH_PATHS[-1]
25 
26 # Create default data directory
27 DATA_DIR = '.'
28 sample_script = """
29 {
30     "description": "S. K. Morgan Ernest. 2003. Life history characteristics of placental non-volant mammals. Ecology 84:3402.",
31     "homepage": "http://esapubs.org/archive/ecol/E084/093/default.htm",
32     "name": "MammalLH",
33     "resources": [
34         {
35             "dialect": {},
36             "mediatype": "text/csv",
37             "name": "species",
38             "schema": {},
39             "url": "http://esapubs.org/archive/ecol/E084/093/Mammal_lifehistories_v2.txt"
40         }
41     ],
42     "title": "Mammal Life History Database - Ernest, et al., 2003"
43 }
44 """
45 CITATION = """Morris, B.D. and E.P. White. 2013. The EcoData Retriever: improving access to
46 existing ecological data. PLOS ONE 8:e65848.
47 http://doi.org/doi:10.1371/journal.pone.0065848
48 
49 @article{morris2013ecodata,
50   title={The EcoData Retriever: Improving Access to Existing Ecological Data},
51   author={Morris, Benjamin D and White, Ethan P},
52   journal={PLOS One},
53   volume={8},
54   number={6},
55   pages={e65848},
56   year={2013},
57   publisher={Public Library of Science}
58   doi={10.1371/journal.pone.0065848}
59 }
60 """
61
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/retriever/__main__.py b/retriever/__main__.py
--- a/retriever/__main__.py
+++ b/retriever/__main__.py
@@ -12,7 +12,7 @@
 from retriever.engines import engine_list, choose_engine
 from retriever.lib.datapackage import create_json, edit_json, delete_json, get_script_filename
 from retriever.lib.datasets import datasets, dataset_names, license
-from retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS
+from retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS, LICENSE
 from retriever.lib.engine_tools import name_matches, reset_retriever
 from retriever.lib.get_opts import parser
 from retriever.lib.repository import check_for_updates
@@ -76,11 +76,14 @@
             return
 
         elif args.command == 'license':
-            dataset_license = license(args.dataset)
-            if dataset_license:
-                print(dataset_license)
+            if args.dataset is None:
+                print(LICENSE)
             else:
-                print("There is no license information for {}".format(args.dataset))
+                dataset_license = license(args.dataset)
+                if dataset_license:
+                    print(dataset_license)
+                else:
+                    print("There is no license information for {}".format(args.dataset))
             return
 
         elif args.command == 'new':
diff --git a/retriever/lib/defaults.py b/retriever/lib/defaults.py
--- a/retriever/lib/defaults.py
+++ b/retriever/lib/defaults.py
@@ -4,6 +4,7 @@
 
 VERSION = __version__
 COPYRIGHT = "Copyright (C) 2011-2016 Weecology University of Florida"
+LICENSE = "MIT"
 REPO_URL = "https://raw.githubusercontent.com/weecology/retriever/"
 MASTER_BRANCH = REPO_URL + "master/"
 REPOSITORY = MASTER_BRANCH

{"golden_diff": "diff --git a/retriever/__main__.py b/retriever/__main__.py\n--- a/retriever/__main__.py\n+++ b/retriever/__main__.py\n@@ -12,7 +12,7 @@\n from retriever.engines import engine_list, choose_engine\n from retriever.lib.datapackage import create_json, edit_json, delete_json, get_script_filename\n from retriever.lib.datasets import datasets, dataset_names, license\n-from retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS\n+from retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS, LICENSE\n from retriever.lib.engine_tools import name_matches, reset_retriever\n from retriever.lib.get_opts import parser\n from retriever.lib.repository import check_for_updates\n@@ -76,11 +76,14 @@\n             return\n \n         elif args.command == 'license':\n-            dataset_license = license(args.dataset)\n-            if dataset_license:\n-                print(dataset_license)\n+            if args.dataset is None:\n+                print(LICENSE)\n             else:\n-                print(\"There is no license information for {}\".format(args.dataset))\n+                dataset_license = license(args.dataset)\n+                if dataset_license:\n+                    print(dataset_license)\n+                else:\n+                    print(\"There is no license information for {}\".format(args.dataset))\n             return\n \n         elif args.command == 'new':\ndiff --git a/retriever/lib/defaults.py b/retriever/lib/defaults.py\n--- a/retriever/lib/defaults.py\n+++ b/retriever/lib/defaults.py\n@@ -4,6 +4,7 @@\n \n VERSION = __version__\n COPYRIGHT = \"Copyright (C) 2011-2016 Weecology University of Florida\"\n+LICENSE = \"MIT\"\n REPO_URL = \"https://raw.githubusercontent.com/weecology/retriever/\"\n MASTER_BRANCH = REPO_URL + \"master/\"\n REPOSITORY = MASTER_BRANCH\n", "issue": "Error when running retriever license with no dataset as argument\nCurrently, when running `retriever license` and providing no dataset as an argument it results into `KeyError: 'No dataset named: None'`\r\n![retriever_ls](https://user-images.githubusercontent.com/21103831/56208546-069b7b00-606f-11e9-84e5-9952be6cc097.png)\r\n\r\nIn case of `retriever citation` if no dataset is given we show the citation for retriever. \r\n![retriever_ct](https://user-images.githubusercontent.com/21103831/56208927-ef10c200-606f-11e9-89aa-056c1c126e33.png)\r\n\r\nHow should we handle this? Show the license for retriever by reading the `LICENSE` file or create a new `LICENSE` variable in `retriever.lib.defaults` and show it?\n", "before_files": [{"content": "\"\"\"Data Retriever\n\nThis module handles the CLI for the Data retriever.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import print_function\n\nimport os\nimport sys\nfrom builtins import input\n\nfrom retriever.engines import engine_list, choose_engine\nfrom retriever.lib.datapackage import create_json, edit_json, delete_json, get_script_filename\nfrom retriever.lib.datasets import datasets, dataset_names, license\nfrom retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS\nfrom retriever.lib.engine_tools import name_matches, reset_retriever\nfrom retriever.lib.get_opts import parser\nfrom retriever.lib.repository import check_for_updates\nfrom retriever.lib.scripts import SCRIPT_LIST, reload_scripts, get_script\n\n\ndef main():\n    \"\"\"This function launches the Data Retriever.\"\"\"\n    if len(sys.argv) == 1:\n        # if no command line args are passed, show the help options\n        parser.parse_args(['-h'])\n\n    else:\n        # otherwise, parse them\n        args = parser.parse_args()\n\n        if args.command not in ['reset', 'update'] \\\n        and not os.path.isdir(SCRIPT_SEARCH_PATHS[1]) \\\n        and not [f for f in os.listdir(SCRIPT_SEARCH_PATHS[-1])\n            if os.path.exists(SCRIPT_SEARCH_PATHS[-1])]:\n                check_for_updates()\n                reload_scripts()\n        script_list = SCRIPT_LIST()\n\n        if args.command == \"install\" and not args.engine:\n            parser.parse_args(['install', '-h'])\n\n        if args.quiet:\n            sys.stdout = open(os.devnull, 'w')\n\n        if args.command == 'help':\n            parser.parse_args(['-h'])\n\n        if hasattr(args, 'compile') and args.compile:\n            script_list = reload_scripts()\n\n        if args.command == 'defaults':\n            for engine_item in engine_list:\n                print(\"Default options for engine \", engine_item.name)\n                for default_opts in engine_item.required_opts:\n                    print(default_opts[0], \" \", default_opts[2])\n                print()\n            return\n\n        if args.command == 'update':\n            check_for_updates()\n            reload_scripts()\n            return\n\n        elif args.command == 'citation':\n            if args.dataset is None:\n                print(\"\\nCitation for retriever:\\n\")\n                print(CITATION)\n            else:\n                scripts = name_matches(script_list, args.dataset)\n                for dataset in scripts:\n                    print(\"\\nDataset:  {}\".format(dataset.name))\n                    print(\"Citation:   {}\".format(dataset.citation))\n                    print(\"Description:   {}\\n\".format(dataset.description))\n\n            return\n\n        elif args.command == 'license':\n            dataset_license = license(args.dataset)\n            if dataset_license:\n                print(dataset_license)\n            else:\n                print(\"There is no license information for {}\".format(args.dataset))\n            return\n\n        elif args.command == 'new':\n            f = open(args.filename, 'w')\n            f.write(sample_script)\n            f.close()\n\n            return\n\n        elif args.command == 'reset':\n            reset_retriever(args.scope)\n            return\n\n        elif args.command == 'new_json':\n            # create new JSON script\n            create_json()\n            return\n\n        elif args.command == 'edit_json':\n            # edit existing JSON script\n            json_file = get_script_filename(args.dataset.lower())\n            edit_json(json_file)\n            return\n\n        elif args.command == 'delete_json':\n            # delete existing JSON script from home directory and or script directory if exists in current dir\n            confirm = input(\"Really remove \" + args.dataset.lower() +\n                            \" and all its contents? (y/N): \")\n            if confirm.lower().strip() in ['y', 'yes']:\n                json_file = get_script_filename(args.dataset.lower())\n                delete_json(json_file)\n            return\n\n        if args.command == 'ls':\n            # scripts should never be empty because check_for_updates is run on SCRIPT_LIST init\n            if not (args.l or args.k or isinstance(args.v, list)):\n                all_scripts = dataset_names()\n                print(\"Available datasets : {}\\n\".format(len(all_scripts)))\n                from retriever import lscolumns\n\n                lscolumns.printls(all_scripts)\n\n            elif isinstance(args.v, list):\n                if args.v:\n                    try:\n                        all_scripts = [get_script(dataset) for dataset in args.v]\n                    except KeyError:\n                        all_scripts = []\n                        print(\"Dataset(s) is not found.\")\n                else:\n                    all_scripts = datasets()\n                count = 1\n                for script in all_scripts:\n                    print(\n                        \"{count}. {title}\\n {name}\\n\"\n                        \"{keywords}\\n{description}\\n\"\n                        \"{licenses}\\n{citation}\\n\"\n                        \"\".format(\n                            count=count,\n                            title=script.title,\n                            name=script.name,\n                            keywords=script.keywords,\n                            description=script.description,\n                            licenses=str(script.licenses[0]['name']),\n                            citation=script.citation,\n                        )\n                    )\n                    count += 1\n\n            else:\n                param_licenses = args.l if args.l else None\n                keywords = args.k if args.k else None\n\n                # search\n                searched_scripts = datasets(keywords, param_licenses)\n                if not searched_scripts:\n                    print(\"No available datasets found\")\n                else:\n                    print(\"Available datasets : {}\\n\".format(len(searched_scripts)))\n                    count = 1\n                    for script in searched_scripts:\n                        print(\n                            \"{count}. {title}\\n{name}\\n\"\n                            \"{keywords}\\n{licenses}\\n\".format(\n                                count=count,\n                                title=script.title,\n                                name=script.name,\n                                keywords=script.keywords,\n                                licenses=str(script.licenses[0]['name']),\n                            )\n                        )\n                        count += 1\n            return\n\n        engine = choose_engine(args.__dict__)\n\n        if hasattr(args, 'debug') and args.debug:\n            debug = True\n        else:\n            debug = False\n            sys.tracebacklimit = 0\n\n        if hasattr(args, 'debug') and args.not_cached:\n            engine.use_cache = False\n        else:\n            engine.use_cache = True\n\n        if args.dataset is not None:\n            scripts = name_matches(script_list, args.dataset)\n        else:\n            raise Exception(\"no dataset specified.\")\n        if scripts:\n            for dataset in scripts:\n                print(\"=> Installing\", dataset.name)\n                try:\n                    dataset.download(engine, debug=debug)\n                    dataset.engine.final_cleanup()\n                except KeyboardInterrupt:\n                    pass\n                except Exception as e:\n                    print(e)\n                    if debug:\n                        raise\n            print(\"Done!\")\n        else:\n            print(\"Run 'retriever ls' to see a list of currently available datasets.\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "retriever/__main__.py"}, {"content": "import os\n\nfrom retriever._version import __version__\n\nVERSION = __version__\nCOPYRIGHT = \"Copyright (C) 2011-2016 Weecology University of Florida\"\nREPO_URL = \"https://raw.githubusercontent.com/weecology/retriever/\"\nMASTER_BRANCH = REPO_URL + \"master/\"\nREPOSITORY = MASTER_BRANCH\nENCODING = 'ISO-8859-1'\nHOME_DIR = os.path.expanduser('~/.retriever/')\nSCRIPT_SEARCH_PATHS = [\n    \"./\",\n    'scripts',\n    os.path.join(HOME_DIR, 'scripts/')\n]\nSCRIPT_WRITE_PATH = SCRIPT_SEARCH_PATHS[-1]\nDATA_SEARCH_PATHS = [\n    \"./\",\n    \"{dataset}\",\n    \"raw_data/{dataset}\",\n    os.path.join(HOME_DIR, 'raw_data/{dataset}'),\n]\nDATA_WRITE_PATH = DATA_SEARCH_PATHS[-1]\n\n# Create default data directory\nDATA_DIR = '.'\nsample_script = \"\"\"\n{\n    \"description\": \"S. K. Morgan Ernest. 2003. Life history characteristics of placental non-volant mammals. Ecology 84:3402.\",\n    \"homepage\": \"http://esapubs.org/archive/ecol/E084/093/default.htm\",\n    \"name\": \"MammalLH\",\n    \"resources\": [\n        {\n            \"dialect\": {},\n            \"mediatype\": \"text/csv\",\n            \"name\": \"species\",\n            \"schema\": {},\n            \"url\": \"http://esapubs.org/archive/ecol/E084/093/Mammal_lifehistories_v2.txt\"\n        }\n    ],\n    \"title\": \"Mammal Life History Database - Ernest, et al., 2003\"\n}\n\"\"\"\nCITATION = \"\"\"Morris, B.D. and E.P. White. 2013. The EcoData Retriever: improving access to\nexisting ecological data. PLOS ONE 8:e65848.\nhttp://doi.org/doi:10.1371/journal.pone.0065848\n\n@article{morris2013ecodata,\n  title={The EcoData Retriever: Improving Access to Existing Ecological Data},\n  author={Morris, Benjamin D and White, Ethan P},\n  journal={PLOS One},\n  volume={8},\n  number={6},\n  pages={e65848},\n  year={2013},\n  publisher={Public Library of Science}\n  doi={10.1371/journal.pone.0065848}\n}\n\"\"\"\n", "path": "retriever/lib/defaults.py"}], "after_files": [{"content": "\"\"\"Data Retriever\n\nThis module handles the CLI for the Data retriever.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import print_function\n\nimport os\nimport sys\nfrom builtins import input\n\nfrom retriever.engines import engine_list, choose_engine\nfrom retriever.lib.datapackage import create_json, edit_json, delete_json, get_script_filename\nfrom retriever.lib.datasets import datasets, dataset_names, license\nfrom retriever.lib.defaults import sample_script, CITATION, SCRIPT_SEARCH_PATHS, LICENSE\nfrom retriever.lib.engine_tools import name_matches, reset_retriever\nfrom retriever.lib.get_opts import parser\nfrom retriever.lib.repository import check_for_updates\nfrom retriever.lib.scripts import SCRIPT_LIST, reload_scripts, get_script\n\n\ndef main():\n    \"\"\"This function launches the Data Retriever.\"\"\"\n    if len(sys.argv) == 1:\n        # if no command line args are passed, show the help options\n        parser.parse_args(['-h'])\n\n    else:\n        # otherwise, parse them\n        args = parser.parse_args()\n\n        if args.command not in ['reset', 'update'] \\\n        and not os.path.isdir(SCRIPT_SEARCH_PATHS[1]) \\\n        and not [f for f in os.listdir(SCRIPT_SEARCH_PATHS[-1])\n            if os.path.exists(SCRIPT_SEARCH_PATHS[-1])]:\n                check_for_updates()\n                reload_scripts()\n        script_list = SCRIPT_LIST()\n\n        if args.command == \"install\" and not args.engine:\n            parser.parse_args(['install', '-h'])\n\n        if args.quiet:\n            sys.stdout = open(os.devnull, 'w')\n\n        if args.command == 'help':\n            parser.parse_args(['-h'])\n\n        if hasattr(args, 'compile') and args.compile:\n            script_list = reload_scripts()\n\n        if args.command == 'defaults':\n            for engine_item in engine_list:\n                print(\"Default options for engine \", engine_item.name)\n                for default_opts in engine_item.required_opts:\n                    print(default_opts[0], \" \", default_opts[2])\n                print()\n            return\n\n        if args.command == 'update':\n            check_for_updates()\n            reload_scripts()\n            return\n\n        elif args.command == 'citation':\n            if args.dataset is None:\n                print(\"\\nCitation for retriever:\\n\")\n                print(CITATION)\n            else:\n                scripts = name_matches(script_list, args.dataset)\n                for dataset in scripts:\n                    print(\"\\nDataset:  {}\".format(dataset.name))\n                    print(\"Citation:   {}\".format(dataset.citation))\n                    print(\"Description:   {}\\n\".format(dataset.description))\n\n            return\n\n        elif args.command == 'license':\n            if args.dataset is None:\n                print(LICENSE)\n            else:\n                dataset_license = license(args.dataset)\n                if dataset_license:\n                    print(dataset_license)\n                else:\n                    print(\"There is no license information for {}\".format(args.dataset))\n            return\n\n        elif args.command == 'new':\n            f = open(args.filename, 'w')\n            f.write(sample_script)\n            f.close()\n\n            return\n\n        elif args.command == 'reset':\n            reset_retriever(args.scope)\n            return\n\n        elif args.command == 'new_json':\n            # create new JSON script\n            create_json()\n            return\n\n        elif args.command == 'edit_json':\n            # edit existing JSON script\n            json_file = get_script_filename(args.dataset.lower())\n            edit_json(json_file)\n            return\n\n        elif args.command == 'delete_json':\n            # delete existing JSON script from home directory and or script directory if exists in current dir\n            confirm = input(\"Really remove \" + args.dataset.lower() +\n                            \" and all its contents? (y/N): \")\n            if confirm.lower().strip() in ['y', 'yes']:\n                json_file = get_script_filename(args.dataset.lower())\n                delete_json(json_file)\n            return\n\n        if args.command == 'ls':\n            # scripts should never be empty because check_for_updates is run on SCRIPT_LIST init\n            if not (args.l or args.k or isinstance(args.v, list)):\n                all_scripts = dataset_names()\n                print(\"Available datasets : {}\\n\".format(len(all_scripts)))\n                from retriever import lscolumns\n\n                lscolumns.printls(all_scripts)\n\n            elif isinstance(args.v, list):\n                if args.v:\n                    try:\n                        all_scripts = [get_script(dataset) for dataset in args.v]\n                    except KeyError:\n                        all_scripts = []\n                        print(\"Dataset(s) is not found.\")\n                else:\n                    all_scripts = datasets()\n                count = 1\n                for script in all_scripts:\n                    print(\n                        \"{count}. {title}\\n {name}\\n\"\n                        \"{keywords}\\n{description}\\n\"\n                        \"{licenses}\\n{citation}\\n\"\n                        \"\".format(\n                            count=count,\n                            title=script.title,\n                            name=script.name,\n                            keywords=script.keywords,\n                            description=script.description,\n                            licenses=str(script.licenses[0]['name']),\n                            citation=script.citation,\n                        )\n                    )\n                    count += 1\n\n            else:\n                param_licenses = args.l if args.l else None\n                keywords = args.k if args.k else None\n\n                # search\n                searched_scripts = datasets(keywords, param_licenses)\n                if not searched_scripts:\n                    print(\"No available datasets found\")\n                else:\n                    print(\"Available datasets : {}\\n\".format(len(searched_scripts)))\n                    count = 1\n                    for script in searched_scripts:\n                        print(\n                            \"{count}. {title}\\n{name}\\n\"\n                            \"{keywords}\\n{licenses}\\n\".format(\n                                count=count,\n                                title=script.title,\n                                name=script.name,\n                                keywords=script.keywords,\n                                licenses=str(script.licenses[0]['name']),\n                            )\n                        )\n                        count += 1\n            return\n\n        engine = choose_engine(args.__dict__)\n\n        if hasattr(args, 'debug') and args.debug:\n            debug = True\n        else:\n            debug = False\n            sys.tracebacklimit = 0\n\n        if hasattr(args, 'debug') and args.not_cached:\n            engine.use_cache = False\n        else:\n            engine.use_cache = True\n\n        if args.dataset is not None:\n            scripts = name_matches(script_list, args.dataset)\n        else:\n            raise Exception(\"no dataset specified.\")\n        if scripts:\n            for dataset in scripts:\n                print(\"=> Installing\", dataset.name)\n                try:\n                    dataset.download(engine, debug=debug)\n                    dataset.engine.final_cleanup()\n                except KeyboardInterrupt:\n                    pass\n                except Exception as e:\n                    print(e)\n                    if debug:\n                        raise\n            print(\"Done!\")\n        else:\n            print(\"Run 'retriever ls' to see a list of currently available datasets.\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "retriever/__main__.py"}, {"content": "import os\n\nfrom retriever._version import __version__\n\nVERSION = __version__\nCOPYRIGHT = \"Copyright (C) 2011-2016 Weecology University of Florida\"\nLICENSE = \"MIT\"\nREPO_URL = \"https://raw.githubusercontent.com/weecology/retriever/\"\nMASTER_BRANCH = REPO_URL + \"master/\"\nREPOSITORY = MASTER_BRANCH\nENCODING = 'ISO-8859-1'\nHOME_DIR = os.path.expanduser('~/.retriever/')\nSCRIPT_SEARCH_PATHS = [\n    \"./\",\n    'scripts',\n    os.path.join(HOME_DIR, 'scripts/')\n]\nSCRIPT_WRITE_PATH = SCRIPT_SEARCH_PATHS[-1]\nDATA_SEARCH_PATHS = [\n    \"./\",\n    \"{dataset}\",\n    \"raw_data/{dataset}\",\n    os.path.join(HOME_DIR, 'raw_data/{dataset}'),\n]\nDATA_WRITE_PATH = DATA_SEARCH_PATHS[-1]\n\n# Create default data directory\nDATA_DIR = '.'\nsample_script = \"\"\"\n{\n    \"description\": \"S. K. Morgan Ernest. 2003. Life history characteristics of placental non-volant mammals. Ecology 84:3402.\",\n    \"homepage\": \"http://esapubs.org/archive/ecol/E084/093/default.htm\",\n    \"name\": \"MammalLH\",\n    \"resources\": [\n        {\n            \"dialect\": {},\n            \"mediatype\": \"text/csv\",\n            \"name\": \"species\",\n            \"schema\": {},\n            \"url\": \"http://esapubs.org/archive/ecol/E084/093/Mammal_lifehistories_v2.txt\"\n        }\n    ],\n    \"title\": \"Mammal Life History Database - Ernest, et al., 2003\"\n}\n\"\"\"\nCITATION = \"\"\"Morris, B.D. and E.P. White. 2013. The EcoData Retriever: improving access to\nexisting ecological data. PLOS ONE 8:e65848.\nhttp://doi.org/doi:10.1371/journal.pone.0065848\n\n@article{morris2013ecodata,\n  title={The EcoData Retriever: Improving Access to Existing Ecological Data},\n  author={Morris, Benjamin D and White, Ethan P},\n  journal={PLOS One},\n  volume={8},\n  number={6},\n  pages={e65848},\n  year={2013},\n  publisher={Public Library of Science}\n  doi={10.1371/journal.pone.0065848}\n}\n\"\"\"\n", "path": "retriever/lib/defaults.py"}]}