forked from osmandapp/OsmAnd-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-resources-list.py
executable file
·85 lines (72 loc) · 3.5 KB
/
gen-resources-list.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
import os
import zlib
import re
# =============================================================================
# =============================================================================
# =============================================================================
class OsmAndCoreResourcesListGenerator(object):
# -------------------------------------------------------------------------
def __init__(self):
return
# -------------------------------------------------------------------------
def generate(self, root, resourcesSubpaths, rules, outputFilename):
# Open output file
try:
outputFile = open(outputFilename, "w")
except IOError:
print("Failed to open '%s' for writing" % (outputFilename))
return False
# List all files
print("Looking for files...")
filenames = []
for subpath in resourcesSubpaths:
for resourcesRoot, dirs, files in os.walk(os.path.join(root, subpath)):
if resourcesRoot.startswith('.'):
print("Ignoring '%s'" % (resourcesRoot))
continue
print("Listing '%s' with %d files" % (resourcesRoot, len(files)))
for filename in files:
filepath = os.path.join(resourcesRoot, filename)
filenames.append(os.path.relpath(filepath, root))
print("Found %d files to test" % (len(filenames)))
# Apply each rule to each file entry
for rule in rules:
print("Processing rule '%s' => '%s' rule:" % (rule[0], rule[1]))
processed = []
for filename in filenames:
if re.match(rule[0], filename) == None:
continue
listname = re.sub(rule[0], rule[1], filename);
processed.append(filename);
outputFile.write("/%s:%s\n" % (filename, listname));
print("\t '%s' => '%s'" % (filename, listname))
print("\t%d processed" % (len(processed)))
filenames[:] = [filename for filename in filenames if not filename in processed]
print("%d unmatched" % (len(filenames)))
outputFile.flush()
outputFile.close()
return True
# =============================================================================
# =============================================================================
# =============================================================================
if __name__=='__main__':
# Get root directory of entire project
rootDir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
rules = [
[r'resources/rendering_styles/default\.render\.xml', r'map/styles/default.render.xml'],
[r'resources/rendering_styles/style-icons/drawable-mdpi/h_(.*shield.*)\.png', r'map/shields/\1.png'],
[r'resources/rendering_styles/style-icons/drawable-mdpi/h_(.*)\.png', r'map/shaders/\1.png'],
[r'resources/rendering_styles/style-icons/drawable-mdpi/mm_(.*)\.png', r'map/map_icons/\1.png'],
[r'resources/rendering_styles/stubs/(.*)\.png', r'map/stubs/\1.png'],
[r'resources/routing/routing\.xml', r'routing/routing.xml'],
[r'core/externals/icu4c/upstream\.data/icudt\d+([lb])\.dat', r'icu4c/icu-data-\1.xml'],
]
resourcesSubpaths = [
"resources",
"core/externals/icu4c/upstream.data"
]
resourcesListFilename = rootDir + "/core/embed-resources.list";
generator = OsmAndCoreResourcesListGenerator()
ok = generator.generate(rootDir, resourcesSubpaths, rules, resourcesListFilename)
sys.exit(0 if ok else -1)