Skip to content

Instantly share code, notes, and snippets.

@Nathaniel100
Created August 22, 2017 05:51
Show Gist options
  • Save Nathaniel100/2b0cf3197daeb5f4485646c77fe0d4fa to your computer and use it in GitHub Desktop.
Save Nathaniel100/2b0cf3197daeb5f4485646c77fe0d4fa to your computer and use it in GitHub Desktop.
将scratch中导出的图片放入至对应的drawable目录下
"""
python scratch_android.py <WORKING_DIR> <OUTPUT_DIR>
"""
import sys
from os import path
from os import makedirs
from os import listdir
from os.path import isfile, join
import shutil
def usage():
""" Usage """
print "python scratch_android.py <WORKING_DIR> <OUTPUT_DIR>"
def main(argv=None):
""" Main """
if argv is None:
argv = sys.argv
if len(argv) != 3:
usage()
return
working_dir = argv[1]
output_dir = argv[2]
drawable_hdpi = join(output_dir, "drawable-hdpi")
drawable_xhdpi = join(output_dir, "drawable-xhdpi")
drawable_xxhdpi = join(output_dir, "drawable-xxhdpi")
drawable_mdpi = join(output_dir, "drawable-mdpi")
if not path.exists(drawable_hdpi):
makedirs(drawable_hdpi)
if not path.exists(drawable_xhdpi):
makedirs(drawable_xhdpi)
if not path.exists(drawable_xxhdpi):
makedirs(drawable_xxhdpi)
if not path.exists(drawable_mdpi):
makedirs(drawable_mdpi)
files = [f for f in listdir(working_dir) if isfile(join(working_dir, f))]
for f in files:
file = join(working_dir, f)
if "@1.5x" in f:
shutil.copy2(file, join(drawable_hdpi, f.replace("@1.5x", "")))
elif "@2x" in f:
shutil.copy2(file, join(drawable_xhdpi, f.replace("@2x", "")))
elif "@3x" in f:
shutil.copy2(file, join(drawable_xxhdpi, f.replace("@3x", "")))
elif "@1x" in f:
shutil.copy2(file, join(drawable_mdpi, f.replace("@1x", "")))
elif ".png" in f and "@" not in f:
shutil.copy2(file, drawable_mdpi)
else:
print f
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment