def share_files(srcdir, dstdir, interpreter, options): """Try to move as many files from srcdir to dstdir as possible.""" for i in os.listdir(srcdir): fpath1 = join(srcdir, i) if not options.no_ext_rename and splitext(i)[-1] == '.so': # try to rename extension here as well (in :meth:`scan` info about # Python version is gone) version = interpreter.parse_public_dir(srcdir) # if version is True it means it's unversioned dist-packages dir if version and version is not True: # note that if ver is empty, default Python version will be used fpath1_orig = fpath1 new_name = interpreter.check_extname(i, version) if new_name: fpath1 = join(srcdir, new_name) if exists(fpath1): log.warn('destination file exist, ' 'cannot rename %s to %s', fpath1_orig, fpath1) else: log.info('renaming %s to %s', fpath1_orig, fpath1) os.renames(fpath1_orig, fpath1) i = new_name fpath2 = join(dstdir, i) if not isdir(fpath1) and not exists(fpath2): # do not rename directories here - all .so files have to be renamed first os.renames(fpath1, fpath2) continue if isdir(fpath1): share_files(fpath1, fpath2, interpreter, options) elif cmpfile(fpath1, fpath2, shallow=False): os.remove(fpath1) # XXX: check symlinks if exists(srcdir) and not os.listdir(srcdir): os.rmdir(srcdir)
def share_files(srcdir, dstdir, interpreter, options): """Try to move as many files from srcdir to dstdir as possible.""" for i in os.listdir(srcdir): fpath1 = join(srcdir, i) if not options.no_ext_rename and splitext(i)[-1] == '.so': # try to rename extension here as well (in :meth:`scan` info about # Python version is gone) version = interpreter.parse_public_version(srcdir) if version: # note that if ver is empty, default Python version will be used fpath1_orig = fpath1 new_name = interpreter.check_extname(i, version) if new_name: fpath1 = join(srcdir, new_name) if exists(fpath1): log.warn( 'destination file exist, ' 'cannot rename %s to %s', fpath1_orig, fpath1) else: log.info('renaming %s to %s', fpath1_orig, fpath1) os.renames(fpath1_orig, fpath1) i = new_name fpath2 = join(dstdir, i) if not isdir(fpath1) and not exists(fpath2): # do not rename directories here - all .so files have to be renamed first os.renames(fpath1, fpath2) continue if isdir(fpath1): share_files(fpath1, fpath2, interpreter, options) elif cmpfile(fpath1, fpath2, shallow=False): os.remove(fpath1) # XXX: check symlinks if exists(srcdir) and not os.listdir(srcdir): os.rmdir(srcdir)
def assertEqualToReference(self, result): reference = path_to_diagram_reference(os.path.basename(result)) if not os.path.exists(result): raise self.failureException("Result file was not generated.") if not os.path.exists(reference): copyfile(result, reference) if cmpfile(reference, result): os.remove(result) else: raise self.failureException("Result and reference do not match.")
def share_files(srcdir, dstdir, interpreter, options): """Try to move as many files from srcdir to dstdir as possible.""" for i in os.listdir(srcdir): fpath1 = join(srcdir, i) if not lexists(fpath1): # removed in rename_ext continue if i.endswith('.pyc'): # f.e. when tests were invoked on installed files os.remove(fpath1) continue if not options.no_ext_rename and splitext(i)[-1] == '.so': # try to rename extension here as well (in :meth:`scan` info about # Python version is gone) version = interpreter.parse_public_dir(srcdir) if version and version is not True: fpath1 = Scan.rename_ext(fpath1, interpreter, version) i = split(fpath1)[-1] fpath2 = join(dstdir, i) if not isdir(fpath1) and not exists(fpath2): # do not rename directories here - all .so files have to be renamed first os.renames(fpath1, fpath2) continue if islink(fpath1): # move symlinks without changing them if they point to the same place if not exists(fpath2): os.renames(fpath1, fpath2) elif realpath(fpath1) == realpath(fpath2): os.remove(fpath1) elif isdir(fpath1): share_files(fpath1, fpath2, interpreter, options) elif cmpfile(fpath1, fpath2, shallow=False): os.remove(fpath1) else: # The files differed so we cannot collapse them. log.warn('Paths differ: %s and %s', fpath1, fpath2) if options.verbose and not i.endswith('.so'): with open(fpath1) as fp1: fromlines = fp1.readlines() with open(fpath2) as fp2: tolines = fp2.readlines() diff = difflib.unified_diff(fromlines, tolines, fpath1, fpath2) sys.stderr.writelines(diff) try: os.removedirs(srcdir) except OSError: pass
def share_files(srcdir, dstdir, interpreter, options): """Try to move as many files from srcdir to dstdir as possible.""" for i in os.listdir(srcdir): fpath1 = join(srcdir, i) if not options.no_ext_rename and splitext(i)[-1] == '.so': # try to rename extension here as well (in :meth:`scan` info about # Python version is gone) version = interpreter.parse_public_dir(srcdir) # if version is True it means it's unversioned dist-packages dir if version and version is not True: # note that if ver is empty, default Python version will be used fpath1_orig = fpath1 new_name = interpreter.check_extname(i, version) if new_name: fpath1 = join(srcdir, new_name) if exists(fpath1): log.warn( 'destination file exist, ' 'cannot rename %s to %s', fpath1_orig, fpath1) else: log.info('renaming %s to %s', fpath1_orig, fpath1) os.renames(fpath1_orig, fpath1) i = new_name fpath2 = join(dstdir, i) if not isdir(fpath1) and not exists(fpath2): # do not rename directories here - all .so files have to be renamed first os.renames(fpath1, fpath2) continue if islink(fpath1): # move symlinks without changing them if they point to the same place if not exists(fpath2): os.renames(fpath1, fpath2) elif realpath(fpath1) == realpath(fpath2): os.remove(fpath1) elif isdir(fpath1): share_files(fpath1, fpath2, interpreter, options) elif cmpfile(fpath1, fpath2, shallow=False): os.remove(fpath1) try: os.removedirs(srcdir) except OSError: pass