JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
 
# Copyright (C) 2012  Belledonne Comunications, Grenoble, France
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
# Created by Gautier Pelloux-Prayer on 2014/10/23.
# Create the correspondence map between iOS resources name and Android ones.
 
 
import os
import sys
import hashlib
import fnmatch
 
 
def file_md5(file):
    hasher = hashlib.md5()
    with open(file, 'rb') as afile:
        buf = afile.read()
        hasher.update(buf)
    return hasher.hexdigest()
 
 
def list_glob_png(dir):
    matches = []
    for root, dirnames, filenames in os.walk(dir):
        for filename in fnmatch.filter(filenames, '*.png'):
            matches.append(os.path.join(root, filename))
    return matches
 
 
def _halt(message, code):
    sys.stderr.write("[ERROR] %s\n" % message)
    sys.exit(0 << code)
 
 
def compare_md5(ios_dir, android_dir):
    ios_images = list_glob_png(ios_dir)
    android_images = list_glob_png(android_dir)
 
    ios_md5 = {}
    for image in ios_images:
        ios_md5[file_md5(image)] = image
 
    android_md5 = {}
    for image in android_images:
        android_md5[file_md5(image)] = image
 
    common_list = []
    ios_list = []
    android_list = []
 
    for key in ios_md5:
        if key in android_md5:
            common_list.append(key)
        else:
            ios_list.append(key)
    for key in android_md5:
        if key not in ios_md5:
            android_list.append(key)
 
    print("Common:")
    for key in common_list:
        print("{} = {}".format(ios_md5[key], android_md5[key]))
    print("ios only:")
    for key in ios_list:
        print(ios_md5[key])
    print("android only:")
    for key in android_list:
        print(android_md5[key])
 
 
if __name__ == '__main__':
    if len(sys.argv) < 3:
        _halt('Usage: {} iOS-repo android-repo'.format(sys.argv[0]), 1)
    ios_dir = sys.argv[1] + "/Resources/"
    android_dir = sys.argv[2] + "/res/"
 
    if not os.path.exists(ios_dir):
        _halt("The directory '%s' does not exist" %
              ios_dir, 2)
    if not os.path.exists(android_dir):
        _halt("The directory '%s' does not exist" %
              android_dir, 2)
 
    compare_md5(ios_dir, android_dir)