def parseFile(self, filePath): try: data = common.readFileEncodingSafe(filePath) dataList = data.split('\n') return self.parseList(dataList) except OSError.FileNotFoundError: raise NoteworthyTranslateException('cannot open %s: ' % filePath)
def write(self, filePath, rst): # ''' Write ``rst`` (a unicode string) to ``filePath``, a pathlib.Path() only overwriting an existing file if the content differs. ''' shouldWrite = True if filePath.exists(): oldRst = common.readFileEncodingSafe(filePath, firstGuess='utf-8') if rst == oldRst: shouldWrite = False else: pass ## uncomment for help in figuring out why a file keeps being different... #import difflib #print(common.relativepath(filePath)) #print('\n'.join(difflib.ndiff(rst.split('\n'), oldRst.split('\n')))) if shouldWrite: with filePath.open('w', encoding='utf-8') as f: try: f.write(rst) except UnicodeEncodeError as uee: raise DocumentationWritersException( "Could not write %s with rst:\n%s" % (filePath, rst)) from uee print('\tWROTE {0}'.format(common.relativepath(filePath))) else: print('\tSKIPPED {0}'.format(common.relativepath(filePath)))
def write(self, filePath, rst): # ''' Write ``rst`` (a unicode string) to ``filePath``, only overwriting an existing file if the content differs. ''' shouldWrite = True if os.path.exists(filePath): oldRst = common.readFileEncodingSafe(filePath, firstGuess='utf-8') if rst == oldRst: shouldWrite = False else: pass ## uncomment for help in figuring out why a file keeps being different... #import difflib #print(common.relativepath(filePath)) #print('\n'.join(difflib.ndiff(rst.split('\n'), oldRst.split('\n')))) if shouldWrite: with io.open(filePath, 'w', encoding='utf-8') as f: try: f.write(rst) except UnicodeEncodeError as uee: six.raise_from(DocumentationWritersException("Could not write %s with rst:\n%s" % (filePath, rst)), uee) print('\tWROTE {0}'.format(common.relativepath(filePath))) else: print('\tSKIPPED {0}'.format(common.relativepath(filePath)))
def write(self, filePath, rst): # ''' Write ``rst`` (a unicode string) to ``filePath``, only overwriting an existing file if the content differs. ''' shouldWrite = True if os.path.exists(filePath): oldRst = common.readFileEncodingSafe(filePath, firstGuess='utf-8') if rst == oldRst: shouldWrite = False if shouldWrite: with open(filePath, 'w') as f: f.write(rst) print('\tWROTE {0}'.format(common.relativepath(filePath))) else: print('\tSKIPPED {0}'.format(common.relativepath(filePath)))
def write(self, filePath, rst): # ''' Write ``rst`` (a unicode string) to ``filePath``, only overwriting an existing file if the content differs. ''' shouldWrite = True if os.path.exists(filePath): oldRst = common.readFileEncodingSafe(filePath, firstGuess='utf-8') if rst == oldRst: shouldWrite = False if shouldWrite: with codecs.open(filePath, 'w', 'utf-8') as f: try: f.write(rst) except UnicodeEncodeError as uee: six.raise_from(DocumentationWritersException("Could not write %s with rst:\n%s" % (filePath, rst)), uee) print('\tWROTE {0}'.format(common.relativepath(filePath))) else: print('\tSKIPPED {0}'.format(common.relativepath(filePath)))
def write(self, filePath, rst): # ''' Write ``rst`` (a unicode string) to ``filePath``, only overwriting an existing file if the content differs. ''' shouldWrite = True if os.path.exists(filePath): oldRst = common.readFileEncodingSafe(filePath, firstGuess='utf-8') if rst == oldRst: shouldWrite = False if shouldWrite: with codecs.open(filePath, 'w', 'utf-8') as f: try: f.write(rst) except UnicodeEncodeError as uee: six.raise_from( DocumentationWritersException( "Could not write %s with rst:\n%s" % (filePath, rst)), uee) print('\tWROTE {0}'.format(common.relativepath(filePath))) else: print('\tSKIPPED {0}'.format(common.relativepath(filePath)))