-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrestore_html_files.py
More file actions
53 lines (43 loc) · 1.38 KB
/
restore_html_files.py
File metadata and controls
53 lines (43 loc) · 1.38 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
53
#! /usr/bin/env python
"""
this file mv html files from original to updating projects
"""
import os
import sys
import pprint
from shutil import copy2
if len(sys.argv) != 3:
print "usage: python restore_html_files.py ${from_paths} ${to_paths}"
sys.exit()
from_paths = sys.argv[1]
to_paths = sys.argv[2]
if not to_paths.endswith("/"):
to_paths += '/'
html_files = []
for root, dirs, files in os.walk("%s"%from_paths):
for file in files:
# cause we got django in the project
if "/django/" not in root and (file.endswith(".html") or\
file.endswith(".htm")):
html_files.append(os.path.join(root, file))
if to_paths == "findsomething/":
for html in html_files:
with open(html, "r") as file:
for line in file:
if line.strip().startswith("{% load staticfiles"):
print html
sys.exit()
# change file to relative paths
if os.path.isdir(to_paths):
for html in html_files:
pprint.pprint(html)
to_html = to_paths + '/'.join(html.split('/')[5:])
if not os.path.exists(to_html):
try:
to_html = to_html.replace("media", "static")
file = open(to_html, "w")
file.close()
except:print "what the hell"
copy2(html, to_html)
if __name__ == "__main__":
pass