Skip to content

Instantly share code, notes, and snippets.

@amitport
Last active September 12, 2020 06:16
Show Gist options
  • Save amitport/1bc57bb0c039f2e3f98f1c2095d28352 to your computer and use it in GitHub Desktop.
Save amitport/1bc57bb0c039f2e3f98f1c2095d28352 to your computer and use it in GitHub Desktop.
import errno
import os
import shutil
from pathlib import Path
from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_string("tff", default=None, help="Relative Path to tff repo folder.")
flags.mark_flag_as_required("tff")
def copydir(src, dest):
try:
shutil.copytree(src, dest)
except OSError as e:
# If the error was caused because the source wasn't a directory
if e.errno == errno.ENOTDIR:
shutil.copy(src, dest)
else:
print('Directory not copied. Error: %s' % e)
def main(argv):
del argv # Unused.
dirname = os.path.dirname(__file__)
tff_python_dir = Path(FLAGS.tff).resolve() / 'tensorflow_federated' / 'python'
def copy_tff_subdir(subdir):
srcdir = str(tff_python_dir / subdir)
dstdir = os.path.join(dirname, f'tensorflow_federated_{subdir}')
if os.path.exists(dstdir):
shutil.rmtree(dstdir)
copydir(srcdir, dstdir)
for dname, dirs, files in os.walk(dstdir):
for fname in files:
ext = fname.split(".")[-1]
if ext in ['BUILD', 'py', 'ipynb', 'md', 'txt', 'sh']:
fpath = os.path.join(dname, fname)
with open(fpath, encoding="utf8") as f:
s = f.read()
s = s.replace(f'tensorflow_federated.python.{subdir}', f'tensorflow_federated_{subdir}').replace(
f'tensorflow_federated/python/{subdir}', f'tensorflow_federated_{subdir}')
with open(fpath, "w", encoding='utf8') as f:
f.write(s)
copy_tff_subdir('examples')
copy_tff_subdir('research')
if __name__ == '__main__':
app.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment