def show_restore(self): Utility.clear() backupfile = self._xmlfile + ".back" if os.path.isfile(backupfile): # Validate backup file before continue. if Utility.validate(self._xsdfile, backupfile) != 0: print("'{}' is not a valid library file.".format( self._xmlfile)) print("Nothing has changed.") input("Press 'Enter' to continue: ") return # Ask user for overwriting existing library file. overwrite = Utility.get_answer_yn( "This operation will overwrite existing library if any. Continue?" ) # Making sure that only Y or y will overwrite the backup. if overwrite != "y": print("Nothing has changed.") input("Press 'Enter' to continue: ") return # Restore library file, overwriting existing one if any. if self.restore() == 0: print("Library file has been restored successfully.") else: print("Library restoration process has failed.") print( "Make sure a [valid] '{}' file exists and you have write privilege in containing folder." .format(backupfile)) else: print("No backup file has been found.") input("Press 'Enter' to continue: ")
def validate_configuration(self): # Validate configuration. if Utility.validate(self.__confxsd, self.__confxml) == 0: # Validation was successful. print("Validates") else: # Validation has failed. print("Configuration does not validate.") # Ask user for creating new configuration. newconf = "" while newconf != "y" and newconf != "n": newconf = Utility.get_answer_yn( "Create new configuration files (will overwrite existed files)?" ) if newconf == "y": # Create new configuration. self.configure()
def __invalid_configuration_exit(self): # Load configuration if Utility.validate(self.__confxsd, self.__confxml) != 0: # Validation has failed. print("Invalid configuration. Please reconfigure the application") sys.exit(2)
def validate(self): return Utility.validate(self._xsdfile, self._xmlfile)