1 # Copyright (c) 2017 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """CSIT Presentation and analytics layer.
16 TODO: Write the description.
18 TODO: Write the description and specification of YAML configuration file.
26 from errors import PresentationError
27 from environment import Environment, clean_environment
28 from configuration import Configuration
29 from inputs import download_data_files, unzip_files
30 from data import InputData
34 """Parse arguments from cmd line.
36 :returns: Parsed arguments.
37 :rtype: ArgumentParser
40 parser = argparse.ArgumentParser(description=__doc__,
41 formatter_class=argparse.
42 RawDescriptionHelpFormatter)
43 parser.add_argument("-c", "--configuration",
45 type=argparse.FileType('r'),
46 help="Configuration YAML file.")
47 parser.add_argument("-l", "--logging",
48 choices=["DEBUG", "INFO", "WARNING",
51 help="Logging level.")
52 parser.add_argument("-f", "--force",
54 help="Force removing the old build(s) if present.")
56 return parser.parse_args()
62 log_levels = {"NOTSET": logging.NOTSET,
63 "DEBUG": logging.DEBUG,
65 "WARNING": logging.WARNING,
66 "ERROR": logging.ERROR,
67 "CRITICAL": logging.CRITICAL}
70 logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s',
71 datefmt='%Y/%m/%d %H:%M:%S',
72 level=log_levels[args.logging])
74 logging.info("Application started.")
76 config = Configuration(args.configuration)
78 except PresentationError:
79 logging.critical("Finished with error.")
83 env = Environment(config.environment, args.force)
87 if config.debug["input-format"] == "zip":
90 download_data_files(config)
92 data = InputData(config)
93 data.parse_input_data()
95 logging.info("Successfully finished.")
97 except (KeyError, ValueError, PresentationError) as err:
98 logging.info("Finished with an error.")
99 logging.critical(str(err))
100 except Exception as err:
101 logging.info("Finished with an error.")
102 logging.critical(str(err))
105 if config is not None and not config.is_debug:
106 clean_environment(config.environment)
110 if __name__ == '__main__':