Stuart Scott | 296fa26 | 2013-12-02 11:25:07 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2014 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an 'AS IS' BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | import hashlib |
| 18 | import os |
| 19 | import subprocess |
| 20 | import sys |
| 21 | |
| 22 | densities = [ |
| 23 | "ldpi", |
| 24 | "mdpi", |
| 25 | "tvdpi", |
| 26 | "hdpi", |
| 27 | "xhdpi", |
| 28 | "400dpi", |
| 29 | "xxhdpi", |
| 30 | "xxxhdpi" |
| 31 | ] |
| 32 | |
| 33 | # A script to find holo images which are duplicated in the landscape and |
| 34 | # portrait folder. The landscape images will then be deleted as Android will |
| 35 | # look up landscape resources in the portrait folder if it doesn't exist in the |
| 36 | # landscape folder. This will reduce the size of the Holo test case. |
| 37 | def main(argv): |
| 38 | run(True) |
| 39 | run(False) |
| 40 | |
| 41 | def run(sw): |
| 42 | for density in densities: |
| 43 | portDir = getDirName(density, sw, False) |
| 44 | landDir = getDirName(density, sw, True) |
| 45 | portrait = getAllHashes(portDir) |
| 46 | landscape = getAllHashes(landDir) |
| 47 | for f in portrait: |
| 48 | if f in landscape and landscape[f] == portrait[f]: |
| 49 | subprocess.call(["rm", landDir + "/" + f]) |
| 50 | |
| 51 | def getAllHashes(dirName): |
| 52 | files = {} |
| 53 | for f in os.listdir(dirName): |
| 54 | if f.endswith(".png"): |
| 55 | files[f] = getHash(open(dirName + "/" + f, 'rb')) |
| 56 | return files |
| 57 | |
| 58 | def getHash(f): |
| 59 | return hashlib.sha1(f.read()).hexdigest() |
| 60 | |
| 61 | def getDirName(density, sw, land): |
| 62 | name = "drawable-" |
| 63 | if sw: |
| 64 | name += "sw600dp-" |
| 65 | if land: |
| 66 | name += "land-" |
| 67 | return name + density |
| 68 | |
| 69 | if __name__ == '__main__': |
| 70 | main(sys.argv) |