1 | #!/usr/bin/env python |
||
2 | """Fuel dataset downloading utility.""" |
||
3 | import argparse |
||
4 | import importlib |
||
5 | import os |
||
6 | |||
7 | import fuel |
||
8 | from fuel import downloaders |
||
9 | from fuel.downloaders.base import NeedURLPrefix |
||
10 | |||
11 | url_prefix_message = """ |
||
0 ignored issues
–
show
|
|||
12 | Some files for this dataset do not have a download URL. |
||
13 | |||
14 | Provide a URL prefix with --url-prefix to prepend to the filenames, |
||
15 | e.g. http://path.to/files/ |
||
16 | """.strip() |
||
17 | |||
18 | |||
19 | def main(args=None): |
||
20 | """Entry point for `fuel-download` script. |
||
21 | |||
22 | This function can also be imported and used from Python. |
||
23 | |||
24 | Parameters |
||
25 | ---------- |
||
26 | args : iterable, optional (default: None) |
||
27 | A list of arguments that will be passed to Fuel's downloading |
||
28 | utility. If this argument is not specified, `sys.argv[1:]` will |
||
29 | be used. |
||
30 | |||
31 | """ |
||
32 | built_in_datasets = dict(downloaders.all_downloaders) |
||
33 | if fuel.config.extra_downloaders: |
||
34 | for name in fuel.config.extra_downloaders: |
||
35 | extra_datasets = dict( |
||
36 | importlib.import_module(name).all_downloaders) |
||
37 | if any(key in built_in_datasets for key in extra_datasets.keys()): |
||
38 | raise ValueError('extra downloaders conflict in name with ' |
||
39 | 'built-in downloaders') |
||
40 | built_in_datasets.update(extra_datasets) |
||
41 | parser = argparse.ArgumentParser( |
||
42 | description='Download script for built-in datasets.') |
||
43 | parent_parser = argparse.ArgumentParser(add_help=False) |
||
44 | parent_parser.add_argument( |
||
45 | "-d", "--directory", help="where to save the downloaded files", |
||
46 | type=str, default=os.getcwd()) |
||
47 | parent_parser.add_argument( |
||
48 | "--clear", help="clear the downloaded files", action='store_true') |
||
49 | subparsers = parser.add_subparsers() |
||
50 | download_functions = {} |
||
51 | for name, fill_subparser in built_in_datasets.items(): |
||
52 | subparser = subparsers.add_parser( |
||
53 | name, parents=[parent_parser], |
||
54 | help='Download the {} dataset'.format(name)) |
||
55 | # Allows the parser to know which subparser was called. |
||
56 | subparser.set_defaults(which_=name) |
||
57 | download_functions[name] = fill_subparser(subparser) |
||
58 | args = parser.parse_args() |
||
59 | args_dict = vars(args) |
||
60 | download_function = download_functions[args_dict.pop('which_')] |
||
61 | try: |
||
62 | download_function(**args_dict) |
||
63 | except NeedURLPrefix: |
||
64 | parser.error(url_prefix_message) |
||
65 | |||
66 | |||
67 | if __name__ == "__main__": |
||
68 | main() |
||
69 |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.