Skip to content

Instantly share code, notes, and snippets.

@zeryx
Last active October 11, 2019 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeryx/eee9083d4ca2a1a6362f524c04aa903e to your computer and use it in GitHub Desktop.
Save zeryx/eee9083d4ca2a1a6362f524c04aa903e to your computer and use it in GitHub Desktop.
shim files to enable docker copy of dynamic files
import os
import sys
import json
from shutil import copy
from uuid import uuid4
def load_filenames_file(path):
with open(path) as f:
files = set(f.readlines())
return files
def find_differences(before, after):
difference = after - before
return difference
def create_export_depot(diff_files, workspace_path, manifest_path):
os.mkdir(workspace_path)
manifest = []
for original_file_path in diff_files:
original_file_path = original_file_path.replace('\n', '')
print(original_file_path)
temp_name = str(uuid4())
temp_path = "{}/{}".format(workspace_path, temp_name)
print(temp_path)
item = {'source': temp_path, 'destination': original_file_path}
manifest.append(item)
copy(original_file_path, temp_path)
with open(manifest_path, 'w') as f:
json.dump(manifest, f)
if __name__ == "__main__":
before_data_file_path = sys.argv[1]
after_data_file_path = sys.argv[2]
depot_path = sys.argv[3]
manifest_path = sys.argv[4]
before_files = load_filenames_file(before_data_file_path)
after_files = load_filenames_file(after_data_file_path)
diff_files = find_differences(before_files, after_files)
create_export_depot(diff_files, depot_path, manifest_path)
import os
import sys
import json
from shutil import copyfile
def load_manifest(file_path):
with open(file_path) as f:
manifest = json.load(f)
return manifest
def copy_from_manifest(manifest_data):
source = manifest_data['source']
destination = manifest_data['destination']
dest_dir = '/'.join(destination.split('/')[:-1])
print(dest_dir)
print(destination)
os.makedirs(dest_dir, exist_ok=True)
try:
copyfile(source, destination)
except Exception as e:
print(e)
pass
if __name__ == '__main__':
manifest_path = sys.argv[1]
manifest = load_manifest(manifest_path)
for data in manifest:
copy_from_manifest(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment