Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
oldpath = srcpath
dstpath = srcpath.replace(srctree, dsttree, 1)
if not dstpath.startswith(dsttree):
raise ValueError("%s not a subdirectory of %s" %
(dstpath, dsttree))
os.makedirs(dstpath)
srcfname = os.path.join(srcpath, fname)
logging.info('Converting ' + srcfname)
try:
srcast = parsefile(srcfname)
except handled_exceptions:
badfiles.add(srcfname)
continue
dsttxt = to_source(srcast)
if not readonly:
dstfname = os.path.join(dstpath, fname)
with open(dstfname, 'w') as f:
f.write(dsttxt)
# As a sanity check, make sure that ASTs themselves
# round-trip OK
dstast = ast.parse(dsttxt) if readonly else parsefile(dstfname)
srcast = striplinecol(srcast)
dstast = striplinecol(dstast)
if srcast != dstast:
broken.append((srcfname, srcast, dstast))
if badfiles:
logging.warning('')