Skip to content

Instantly share code, notes, and snippets.

Last active September 1, 2016 10:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import click
from os import walk, makedirs
from os.path import join
from shutil import copy
@click.option('--source', help="""Path to the grails 2 project""", type=file)
help="""Path to the bootstrapped grails 3 project""", type=file)
def migrate(source, destination):
def migrate_folder(old_folder, new_folder, destination_root):
Both old_folder and new_folder are expected to be paths (str)
destination_root has to be an absolute one.
will move files present in old_folder but not in new_folder.
old_files, old_folders = gather_paths(old_folder)
new_files, new_folders = gather_paths(new_folder)
create_folders(old_folders, new_folders)
move_files(old_files, new_files)
def get_diff(paths1, paths2):
Returns paths present in paths1 but absent in paths2
diff = [p for p in paths1 if not p in paths2]
return diff
def move_files(old_files, new_files, destination_root):
diff = get_diff(old_files, new_files)
diff = [(p,join(destination_root, p)) for p in diff]
for old_path, new_path in diff:
copy(old_path, new_path)
def create_folders(old_folders, new_folders, destination_root):
diff = get_diff(old_folders, new_folders)
diff = [join(destination_root, p) for p in diff]
for p in diff:
def gather_paths(folder):
For given path returns tuple:
files, folders
each being a list of paths relative to folder
files_present = []
folders_present = []
for root, dirs, files in walk(folder):
for name in files:
files_present.append(os.path.join(root, name))
for name in dirs:
folders_present.append(os.path.join(root, name))
return files_present, folders_present
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment