def _main(): """\ Unit-testing function. It is using previously build modules as a necessary wrapping. """ from parameters import Parameters from input_output import InputOutput from tables_builder import NamesConflict settings = Parameters().process() interface = InputOutput(settings) input_tree, valid_tree = interface.read_trees() analyser = XMLAnalyser(settings, input_tree, valid_tree) try: result = analyser.run() except NamesConflict: sys.stderr.write("Conflicting names detected!\n") sys.exit(90) except ValidationFail: sys.stderr.write("ValidationFail exception catched!\n") sys.exit(91) interface.write(result) return 0
def main(): """\ Wrapping main function for invocation purposes only. """ # Getting script parameters: settings = Parameters().process() # Initializing Input-Output interface: interface = InputOutput(settings) # Reading and parsing the script input: input_tree, valid_tree = interface.read_trees() # Initializing the script analyser: analyser = XMLAnalyser(settings, input_tree, valid_tree) # Running the analysis: try: database = analyser.run() except KeywordError: prog = os.path.basename(sys.argv[0]) msg = "reserved SQL keyword detected as an element name" sys.stderr.write("%s: ERROR: %s\n" % (prog, msg)) sys.exit(EXIT_CODES["error_format"]) except NamesConflict: prog = os.path.basename(sys.argv[0]) msg = "collisions between attribute and element names detected" sys.stderr.write("%s: ERROR: %s\n" % (prog, msg)) sys.exit(EXIT_CODES["error_names_conflict"]) except ValidationFail: prog = os.path.basename(sys.argv[0]) msg = "database structure can't store the validation file data" sys.stderr.write("%s: ERROR: %s\n" % (prog, msg)) sys.exit(EXIT_CODES["error_validation_fail"]) # Converting the result of analysis to another XML representation if # requested: if settings.g: DBaseToXML(database).run() interface.write(database) return EXIT_CODES["no_error"]