Пример #1
0
    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: ")
Пример #2
0
    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()
Пример #3
0
 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)
Пример #4
0
 def validate(self):
     return Utility.validate(self._xsdfile, self._xmlfile)