def save_changes(self): if self._path is None or self._path == '': raise Exception('Cannot save writer without path') if not Writers.writer_exists(fileops.get_basename(self._path)): self.create() else: self._write_datafile()
def create(self): if self._path is None or self._path == '': raise Exception('Cannot create writer without path') fileops.make(self._path, fileops.FileType.DIRECTORY) fileops.make(self._get_datafile_path(), fileops.FileType.FILE) Writers.add_writer(fileops.get_basename(self._path)) self._write_datafile()
def load_from_path(path): """ Creates a new Solution object from a file at path and returns it """ newSolution = Solution(solutionPath=path) filename = fileops.get_basename_less_extension(path) filenameMatcher = Definitions.get_value_matcher(Solution.NAMING_DEFINITION_KEY) newSolution.problemNumber = filenameMatcher.get_variable_value( filename, Variables.get_variable_key_name(Variables.NAME_PROBLEM_NUMBER) ) from util.writer import Writer newSolution.solutionWriter = fileops.get_basename(fileops.get_parent_dir(path)) newSolution.solutionLanguage = Languages.get_language_from_extension(fileops.get_extension(path)) return newSolution
def get_applied_language(cls, solutionPath, solutionLanguage): if solutionPath in cls._appliedLanguages: return cls._appliedLanguages[solutionPath] variableDictionary = { Variables.get_variable_key_name(Variables.NAME_FILENAME): fileops.get_basename(solutionPath), Variables.get_variable_key_name(Variables.NAME_FILENAME_LESS_EXT): fileops.get_basename_less_extension(solutionPath), Variables.get_variable_key_name(Variables.NAME_DIRECTORY): fileops.get_parent_dir(solutionPath) } cls._appliedLanguages[solutionPath] = AppliedLanguage(solutionLanguage.name, cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileExtension), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileCommand), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileArguments), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runExtension), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runCommand), cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runArguments), solutionPath) return cls._appliedLanguages[solutionPath]
def delete(self): if self._path is None or self._path == '': raise Exception('Cannot delete writer without path') fileops.remove(self._path, fileops.FileType.DIRECTORY) Writers.delete_writer(fileops.get_basename(self._path))