<commit_before>#!/usr/bin/env python
import subprocess
import datetime
import sys
import os

try:
    from PIL import Image
except ImportError:
    error = "Failed importing PIL"
    sys.exit(error)


SCRIPT, SOURCE, DEST = sys.argv

specs = [{
    "name": "xxhdpi",
    "size": 144
}, {
    "name": "xhdpi",
    "size": 96
}, {
    "name": "hdpi",
    "size": 72
}, {
    "name": "mdpi",
    "size": 48
}, {
    "name": "ldpi",
    "size": 36
}]

file_name = "ic_launcher.png"

try:
    src = Image.open(SOURCE)
except IOError:
    error = "Cannot load source file: %s" % SOURCE
    sys.exit(error)

original_size = 512

if src.size != (original_size, original_size):
    error = "Wrong source dimension: (%s, %s)" % (src.size[0], src.size[1])
    sys.exit(error)
else:
    print "Source file: %s verified" % SOURCE
    pass


print "Begin making..."
begin_time = datetime.datetime.now()
count = 0

for spec in specs:
    dest_dir = os.path.join(DEST, "drawable-" + spec["name"])
    dest_path = os.path.join(dest_dir, file_name)

    resized = src.resize((spec["size"], spec["size"]), Image.ANTIALIAS)
    resized.save(dest_path)

    count += 1
    print "Made %s" % spec["name"]


print "Running optimization..."

imgoptim_path = "/Applications/ImageOptim.app/Contents/MacOS/ImageOptim"
dist_path = DEST + "/**.png"
shell_cmd = "%s 2>/dev/null %s" % (imgoptim_path, dist_path)

subprocess.Popen(
    shell_cmd,
    shell=True,
    stdout=subprocess.PIPE
).communicate()

duration = datetime.datetime.now() - begin_time

print "Made %s icons in %s.%s sec" % (
    count, duration.seconds, duration.microseconds
)

sys.exit(0)
<commit_msg>Cleanup android icon runner<commit_after>#!/usr/bin/env python
import subprocess, datetime, sys, os


try:
    from PIL import Image
except ImportError:
    sys.exit("Cannot import PIL")


SCRIPT, SOURCE, DEST = sys.argv

specs = [
    {"name": "xxxhdpi", "size": 192},
    {"name": "xxhdpi", "size": 144},
    {"name": "xhdpi", "size": 96},
    {"name": "hdpi", "size": 72},
    {"name": "mdpi", "size": 48},
    {"name": "ldpi", "size": 36}
]

file_name = "ic_launcher.png"

try:
    src = Image.open(SOURCE)
except IOError:
    sys.exit("Cannot load source: %s" % SOURCE)

original_size = 512

if src.size != (original_size, original_size):
    sys.exit("Invalid source size: (%s, %s)" % (src.size[0], src.size[1]))
else:
    pass


print "Begin..."

begin_time = datetime.datetime.now()
count = 0

for spec in specs:
    dest_dir = os.path.join(DEST, "drawable-" + spec["name"])
    dest_path = os.path.join(dest_dir, file_name)

    resized = src.resize((spec["size"], spec["size"]), Image.ANTIALIAS)
    resized.save(dest_path)

    count += 1


print "Optimizing..."

optimizer_path = "/Applications/ImageOptim.app/Contents/MacOS/ImageOptim"
dist_path = DEST + "/**.png"

subprocess.Popen("%s 2>/dev/null %s" % (optimizer_path, dist_path),
    stdout=subprocess.PIPE,
    shell=True
).communicate()

cost = datetime.datetime.now() - begin_time

print "%s icons, %s.%s seconds." % (count, cost.seconds, cost.microseconds)

sys.exit(0)

{'fraction_non_alphanumeric': 0.17261518494484102, 'fraction_numerical': 0.013951979234263466, 'mean_word_length': 3.5741839762611276, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6560884', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1128, 'n_words': 275}