def setUp(self): self.valid = Validator() self.bookRepo = RepoData() self.undoService = UndoService() self.rentalRepo = RepoData() self.book_service = BookService(self.valid, self.bookRepo, self.undoService, self.rentalRepo)
def __get_pep8_formatted_data(path, get_data): raw_data = get_data(path) if Validator.contains_multiple_class(raw_data) is not False: return raw_data else: print(f'Data Extraction has stopped as more than 1 class ' f'definition was found in \n{abspath(path)}') return ''
def setUp(self): self.clientRepo = RepoData() self.valid = Validator() self.UndoService = UndoService() self.rentalRepo = RepoData() self.bookRepo = RepoData() self.serviceClient = ClientService(self.valid, self.clientRepo, self.UndoService, self.rentalRepo, self.bookRepo)
def __init__(self): self.args = self.get_arguments() self.size = None self.puzzle = [] if self.args.file: self.file = Validator.read_file(self.args.file.name) self.read_puzzle_from_file() elif self.args.random_number: self.size = self.args.random_number else: Validator.print_error_message("No puzzle - no program, sorry") self.puzzle_len = self.size**2 self.target = [0 for _ in range(self.puzzle_len)] self.create_target() self.moves = self.get_moves() if len(self.puzzle) == 0: self.puzzle = self.target[:] self.create_random_puzzle() elif not self.solvable(): Validator.print_error_message("Puzzle not solvable")
def read_from_folder(path): data = [] for root, dirs, files in os.walk(path): for file in files: if file.endswith('.py'): file_path = os.path.abspath(os.path.join(root, file)) valid = Validator.validate(file_path) if valid == 'ok': raw_data = FileReader.read(file_path) if Validator.contains_multiple_class( raw_data) is not False: data.append(raw_data) else: print( 'Data Extraction has stopped as more than 1 class definition was found in \n' + file_path) data = [] break elif valid == 'f': raw_data = Pep8Formatter.format_pep8(file_path) if Validator.contains_multiple_class( raw_data) is not False: data.append(raw_data) else: print( 'Data Extraction has stopped as more than 1 class definition was found in \n' + file_path) data = [] break else: print( 'Not a valid Python code in ', file_path, ' Extraction process has been stopped! Fix the file and try again' ) data = [] break return data
def read_from_file(path): result = "" if path.endswith('.py'): valid = Validator.validate(path) if valid == 'ok': raw_data = FileReader.read(path) if Validator.contains_multiple_class(raw_data) is not False: result = raw_data else: print( 'Data Extraction has stopped as more than 1 class definition was found in \n' + path) elif valid == 'f': raw_data = Pep8Formatter.format_pep8(path) if Validator.contains_multiple_class(raw_data) is not False: result = raw_data else: print( 'Data Extraction has stopped as more than 1 class definition was found in \n' + path) else: print('Not a valid Python code in ', path, ' Fix the file and try again') return result
def setUp(self): self.bookRepo = RepoData() self.clientRepo = RepoData() self.rentalRepo = RepoData() self.valid = Validator() self.undoService = UndoService() self.serviceBook = BookService(self.valid, self.bookRepo, self.undoService, self.rentalRepo) self.serviceClient = ClientService(self.valid, self.clientRepo, self.undoService, self.rentalRepo, self.bookRepo) self.serviceRental = RentalService(self.valid, self.rentalRepo, self.serviceBook, self.serviceClient, self.undoService)
def __try_read_data(path): valid_functions = { 'ok': FileReader.read, 'f': Pep8Formatter.format_pep8 } valid = Validator.validate(path) if valid not in valid_functions.keys(): print(f'Not a valid Python code in {abspath(path)} ' f'Extraction process has been stopped! ' f'Fix the file and try again') return '' return FileReader.__get_pep8_formatted_data(path, valid_functions[valid])
def __readAllFromFileTxt(self): try: with open(self.__file_name_settings, "r") as file: lines = file.readlines() dict_of_lines = {} for line in lines: lst = line.split("=") dict_of_lines[lst[0].strip()] = lst[1].strip().strip('"') except FileNotFoundError: print("Inexistent file : " + self.__file_name_settings) if dict_of_lines['repository'] == 'inmemory': pass elif dict_of_lines['repository'] == 'text files': bookRepo = FileBookRepository(dict_of_lines['books']) clientRepo = FileClientRepository(dict_of_lines['clients']) rentalRepo = FileRentalRepository(dict_of_lines['rentals']) elif dict_of_lines['repository'] == 'binary files': bookRepo = FileBookRepositoryBinary(dict_of_lines['books']) clientRepo = FileClientRepositoryBinary(dict_of_lines['clients']) rentalRepo = FileRentalRepositoryBinary(dict_of_lines['rentals']) valid = Validator() undoService = UndoService() serviceBook = BookService(valid, bookRepo, undoService, rentalRepo) serviceClient = ClientService(valid, clientRepo, undoService, rentalRepo, bookRepo) serviceRental = RentalService(valid, rentalRepo, serviceBook, serviceClient, undoService) if dict_of_lines['ui'] == 'gui': ui = Console(serviceBook, serviceClient, serviceRental, undoService) else: ui = Console(serviceBook, serviceClient, serviceRental, undoService) ui.runUI()
def read_puzzle_from_file(self): for row in self.file: row = row.strip() if row.startswith("#"): continue arr = row.split() if self.size is None: if len(arr) == 1: self.size = Validator.parse_int(arr[0]) continue else: if arr[1].startswith("#"): self.size = Validator.parse_int(arr[0]) continue else: Validator.print_error_message( "Cannot parse matrix size") if self.size < 3: Validator.print_error_message( "Matrix size should be more or equal to 3") if self.size != 0: if len(arr) < self.size: Validator.print_error_message("Not valid puzzle") if len(arr) > self.size and not arr[self.size].startswith("#"): Validator.print_error_message("Not valid puzzle") for index, value in enumerate(arr[0:self.size]): num = Validator.validate_element( Validator.parse_int(value), self.size) if num in self.puzzle: Validator.print_error_message("Not valid puzzle") self.puzzle.append( Validator.validate_element(num, self.size))
#!/Users/pkolomiy/.brew/bin/python3 import sys from Validation.NPuzzle import NPuzzle from Validation.Parser import Parser from Validation.Validator import Validator from AStar import AStar if __name__ == '__main__': if len(sys.argv) < 2: Validator.print_error_message(Parser.usage()) n_puzzle = NPuzzle() AStar(n_puzzle).algorithm()