import simplejson as json

scripts_path = os.path.dirname(os.path.abspath(__file__))
devtools_path = os.path.dirname(scripts_path)
blink_source_path = os.path.dirname(devtools_path)
blink_path = os.path.dirname(blink_source_path)
chromium_src_path = os.path.dirname(os.path.dirname(blink_path))
devtools_frontend_path = os.path.join(devtools_path, "front_end")
images_path = os.path.join(devtools_frontend_path, "Images")
image_sources_path = os.path.join(images_path, "src")
HASHES_FILE_NAME = "optimize_svg.hashes"
HASHES_FILE_PATH = os.path.join(image_sources_path, HASHES_FILE_NAME)

file_names = os.listdir(image_sources_path)
svg_file_paths = [os.path.join(image_sources_path, file_name) for file_name in file_names if file_name.endswith(".svg")]
SVG_FILE_PATHS_TO_OPTIMIZE = devtools_file_hashes.files_with_invalid_hashes(HASHES_FILE_PATH, svg_file_paths)
SVG_FILE_NAMES = [os.path.basename(file_path) for file_path in SVG_FILE_PATHS_TO_OPTIMIZE]


def check_installed(app_name):
    proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell=True)
    proc.communicate()
    if proc.returncode != 0:
        print "This script needs \"%s\" to be installed." % app_name
        sys.exit(1)


check_installed("npx")


def optimize_svg(svg_input_path):
Exemplo n.º 2
0
scripts_path = os.path.dirname(os.path.abspath(__file__))
devtools_path = os.path.dirname(scripts_path)
devtools_frontend_path = devtools_path + "/front_end"
images_path = devtools_frontend_path + "/Images"
image_sources_path = images_path + "/src"
hashes_file_name = "svg2png.hashes"
hashes_file_path = image_sources_path + "/" + hashes_file_name

file_names = os.listdir(image_sources_path)
svg_file_paths = [
    image_sources_path + "/" + file_name for file_name in file_names
    if file_name.endswith(".svg")
]

svg_file_paths_to_convert = devtools_file_hashes.files_with_invalid_hashes(
    hashes_file_path, svg_file_paths)
svg_file_names = [
    re.sub(".svg$", "", re.sub(".*/", "", file_path))
    for file_path in svg_file_paths_to_convert
]


def convert_svg_to_png(svg_file_name, png_file_name, dpi):
    svg_full_path = image_sources_path + "/" + svg_file_name + ".svg"
    png_full_path = images_path + "/" + png_file_name + ".png"
    convert_command = "inkscape -f %s -e %s -d %s" % (svg_full_path,
                                                      png_full_path, dpi)
    proc = subprocess.Popen(convert_command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            shell=True)

check_installed("inkscape")

scripts_path = os.path.dirname(os.path.abspath(__file__))
devtools_path = os.path.dirname(scripts_path)
devtools_frontend_path = devtools_path + "/front_end"
images_path = devtools_frontend_path + "/Images"
image_sources_path = images_path + "/src"
hashes_file_name = "svg2png.hashes"
hashes_file_path = image_sources_path + "/" + hashes_file_name

file_names = os.listdir(image_sources_path)
svg_file_paths = [image_sources_path + "/" + file_name for file_name in file_names if file_name.endswith(".svg")]

svg_file_paths_to_convert = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, svg_file_paths)
svg_file_names = [re.sub(".svg$", "", re.sub(".*/", "", file_path)) for file_path in svg_file_paths_to_convert]


def convert_svg_to_png(svg_file_name, png_file_name, dpi):
    svg_full_path = image_sources_path + "/" + svg_file_name + ".svg"
    png_full_path = images_path + "/" + png_file_name + ".png"
    convert_command = "inkscape -f %s -e %s -d %s" % (svg_full_path, png_full_path, dpi)
    proc = subprocess.Popen(convert_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
    return proc


processes = {}
for file_name in svg_file_names:
    name = re.sub(".svg$", "", file_name)
    name2x = name + "_2x"
    import simplejson as json

scripts_path = os.path.dirname(os.path.abspath(__file__))
devtools_path = os.path.dirname(scripts_path)
blink_source_path = os.path.dirname(devtools_path)
blink_path = os.path.dirname(blink_source_path)
chromium_src_path = os.path.dirname(os.path.dirname(blink_path))
devtools_frontend_path = os.path.join(devtools_path, "front_end")
images_path = os.path.join(devtools_frontend_path, "Images")
image_sources_path = os.path.join(images_path, "src")
hashes_file_name = "optimize_png.hashes"
hashes_file_path = os.path.join(image_sources_path, hashes_file_name)

file_names = os.listdir(image_sources_path)
svg_file_paths = [os.path.join(image_sources_path, file_name) for file_name in file_names if file_name.endswith(".svg")]
svg_file_paths_to_optimize = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, svg_file_paths)
svg_file_names = [os.path.basename(file_path) for file_path in svg_file_paths_to_optimize]


def check_installed(app_name):
    proc = subprocess.Popen("which %s" % app_name, stdout=subprocess.PIPE, shell=True)
    proc.communicate()
    if proc.returncode != 0:
        print "This script needs \"%s\" to be installed." % app_name
        print "Run sudo gem install image_optim image_optim_pack"
        sys.exit(1)

check_installed("image_optim")

def optimize_png(file_name):
    png_full_path = os.path.join(images_path, file_name + ".png")