- Create python virtual environment in a folder:
- UNIX:
python3 -m venv env
- WINDOWS:
py -m venv env
- UNIX:
- Activate Environment:
- UNIX:
source env/bin/activate
- WINDOWS:
.\env\Scripts\activate
- UNIX:
- Optional:
python -m pip install --upgrade pip
- Place
copy.py
file in directory - Run Script (within venv):
python copy.py
- Optional: To deactivate virtual environment; within the project directory type
deactivate
Last active
November 21, 2020 07:51
-
-
Save mkeneqa/60dbf7023bbf71670aba4deebeff6131 to your computer and use it in GitHub Desktop.
Simple Python Script to copy data from source to destination. This is part of my proxy workflow that fetches the corresponding full res video files for proxies within my project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
from os import path | |
from shutil import copyfile | |
import hashlib | |
VIDEO_FILES = ["//Volumes/Cinema/FOOTAGE/2018/Weddings/EricAndSarah/DJI_0180" | |
"//Volumes/Cinema/FOOTAGE/2018/Weddings/EricAndSarah/DJI_0181", | |
"//Volumes/Cinema/FOOTAGE/2018/Weddings/EricAndSarah/GH5_056"] | |
def get_dest_file_path(full_file_path): | |
file_name = os.path.basename(full_file_path) | |
dest_dir = "//Volumes/WeddingProjects/MontageFullRes" | |
return "{}/{}".format(dest_dir, file_name) | |
def get_file_checksum(file_path): | |
md5_check = hashlib.md5() | |
with open(file_path, "rb") as f: | |
for chunk in iter(lambda: f.read(900000000), b""): | |
md5_check.update(chunk) | |
return md5_check.hexdigest() | |
if __name__ == '__main__': | |
print("Starting Full-Res Copying . . . ") | |
success_count = 0 | |
error_count = 0 | |
warning_count = 0 | |
total = len(TEST_FILES) | |
for _file in TEST_FILES: | |
file_count = error_count + success_count + 1 | |
print("copying {} / {} files".format(file_count, total)) | |
mov_file = "{}.mov".format(_file) | |
mov2_file = "{}.MOV".format(_file) | |
mp4_file = "{}.mp4".format(_file) | |
mp42_file = "{}.MP4".format(_file) | |
src_file_path = False | |
if path.exists(mov_file): | |
src_file_path = mov_file | |
elif path.exists(mov2_file): | |
src_file_path = mov2_file | |
elif path.exists(mp4_file): | |
src_file_path = mp4_file | |
elif path.exists(mp42_file): | |
src_file_path = mp42_file | |
else: | |
error_count = error_count + 1 | |
print("ERR: {}".format(_file)) | |
print("FILE DOESN'T Exist!") | |
print('_______________________________________________________') | |
print(' ') | |
if src_file_path: | |
dest_file_path = get_dest_file_path(src_file_path) | |
try: | |
print("source checksum ...") | |
src_checksum = get_file_checksum(src_file_path) | |
copyfile(src_file_path, dest_file_path) | |
print("copied from: {} to: {}".format(src_file_path, dest_file_path)) | |
print("destination checksum ...") | |
dest_checksum = get_file_checksum(dest_file_path) | |
checksum_msg = 'Checksums MATCH: {}'.format(src_checksum) | |
if src_checksum != dest_checksum: | |
checksum_msg = 'WARNING: Checksums DO NOT MATCH! {} != {}'.format(src_checksum, dest_checksum) | |
warning_count = warning_count + 1 | |
print(checksum_msg) | |
print('_______________________________________________________') | |
print(" ") | |
success_count = success_count + 1 | |
except Exception as e: | |
print("ERR: Could Not Copy File! {}".format(str(e))) | |
print("ERR SRC File: {}".format(src_file_path)) | |
print("ERR DEST File: {}".format(src_file_path)) | |
print('_______________________________________________________') | |
print('') | |
error_count = error_count + 1 | |
print("___ Process Complete ___") | |
print(" ") | |
print( | |
"{} files successfully copied. | {} files had errors | {} warnings found ".format(success_count, | |
error_count, | |
warning_count)) | |
print(" ") | |
print("_______________________________________________________") | |
print(" ") | |
print("GOOD BYE!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment