-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_to_python_github_folder.py
More file actions
52 lines (45 loc) · 2.18 KB
/
backup_to_python_github_folder.py
File metadata and controls
52 lines (45 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from android_scripts_python.library.main_functions import myPythonScripts
from android_scripts_python.library.text_formatting import pbold
from android_scripts_python.library.machine_file_operations import compare_machine_files
def ensure_dir(path):
if not os.path.isdir(path):
os.makedirs(path, exist_ok=True)
def compare_and_copy_machine_files(src_folder, dest_folder, pattern):
# Copy all files matching pattern from src_folder to dest_folder if they differ
for root, files in os.walk(src_folder):
for file in files:
if pattern == '*.*' or pattern in file:
src_file = os.path.join(root, file)
rel_path = os.path.relpath(src_file, src_folder)
dest_file = os.path.join(dest_folder, rel_path)
ensure_dir(os.path.dirname(dest_file))
if not os.path.exists(dest_file) or compare_machine_files(src_file, dest_file) == 'diff':
pbold(f"Copying {src_file} to {dest_file}\n")
try:
import shutil
shutil.copy2(src_file, dest_file)
except Exception as e:
print(f"Error copying {src_file} to {dest_file}: {e}")
def backup_files(source_folder, dest_folder):
print(f" Source: {source_folder}")
print(f" Destination: {dest_folder}")
ensure_dir(dest_folder)
compare_and_copy_machine_files(source_folder, dest_folder, '*.*')
def main():
gitHubFolder = os.path.expanduser('~/Setup/GitHub')
gitHubFolder_python = os.path.join(gitHubFolder, 'android-python-scripts')
print(">> Checking Library Files ...")
sourceFolder = os.path.join(myPythonScripts, 'library')
destFolder = os.path.join(gitHubFolder_python, 'library')
backup_files(sourceFolder, destFolder)
print(">> Done checking Library Files\n")
print(">> Checking Script Files ...")
sourceFolder = myPythonScripts
destFolder = gitHubFolder_python
backup_files(sourceFolder, destFolder)
print(">> Done checking Script Files\n")
if __name__ == "__main__":
main()