-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilerestore.py
59 lines (43 loc) · 1.62 KB
/
filerestore.py
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
53
54
55
56
57
58
59
import filecmp, os
import json
og_dir="/var/encircle/docker/permaculture/drupal/sites/default/files"
target_dir="/var/encircle/docker/live-permaculture/drupal/site/web/sites/default/files"
#og_dir="/var/encircle/docker/pca-stage/drupal/site/test1"
#target_dir="/var/encircle/docker/pca-stage/drupal/site/test2"
ignore_dirs_raw=[]
with open("./ignore_dirs.json") as iff:
ignore_dirs_raw=json.load(iff)
ignore_dirs=[]
for idir in ignore_dirs_raw:
stripper=og_dir+"/"+idir.removeprefix("public://").strip("/")
ignore_dirs.append(stripper)
missing_files=[]
ignoring_files=[]
def walk_cmp(cmp: filecmp.dircmp):
for id in ignore_dirs:
if id==cmp.left:
return
for left_only in cmp.left_only:
left_only_abs=cmp.left+"/"+left_only
if os.path.isdir(left_only_abs):
continue
if left_only_abs.endswith(".jpg") or left_only_abs.endswith(".jpeg") or left_only_abs.endswith(".png") or left_only_abs.endswith(".gif") or left_only_abs.endswith(".JPG"):
right_target_abs= cmp.right + "/" + left_only
missing_files.append("cp '"+left_only_abs+"' '"+right_target_abs+"'")
else:
ignoring_files.append(left_only_abs)
if cmp.subdirs:
for subdirname,subdirobj in cmp.subdirs.items():
walk_cmp(subdirobj)
cmp=filecmp.dircmp(og_dir,target_dir)
cmp.report_full_closure()
walk_cmp(cmp)
with open("restore_files.sh","w") as f:
for line in missing_files:
f.write(line)
f.write("\n")
with open("missing_files_ignored.log","w") as f:
for line in ignoring_files:
f.write(line)
f.write("\n")
pass