Ejemplo n.º 1
0
 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)))
Ejemplo n.º 2
0
    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)))
Ejemplo n.º 3
0
 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)))
Ejemplo n.º 4
0
 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)))