예제 #1
0
def _CheckOptimizePNGHashes(input_api, output_api):
    if not input_api.platform.startswith("linux"):
        return []

    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")]
        import devtools_file_hashes
    finally:
        sys.path = original_sys_path

    absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles(include_deletes=False)]
    images_src_path = input_api.os_path.join("devtools", "front_end", "Images", "src")
    image_source_file_paths = [
        path for path in absolute_local_paths if images_src_path in path and path.endswith(".svg")
    ]
    image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
    hashes_file_name = "optimize_png.hashes"
    hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_name)
    invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths)
    if len(invalid_hash_file_paths) == 0:
        return []
    invalid_hash_file_names = [input_api.os_path.basename(file_path) for file_path in invalid_hash_file_paths]
    file_paths_str = ", ".join(invalid_hash_file_names)
    error_message = (
        "The following PNG files should be optimized using optimize_png_images.py script before uploading: \n  - %s"
        % file_paths_str
    )
    return [output_api.PresubmitError(error_message)]
예제 #2
0
def _CheckOptimizePNGHashes(input_api, output_api):
    if not input_api.platform.startswith('linux'):
        return []

    original_sys_path = sys.path
    try:
        sys.path = sys.path + [
            input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts')
        ]
        import devtools_file_hashes
    finally:
        sys.path = original_sys_path

    absolute_local_paths = [
        af.AbsoluteLocalPath()
        for af in input_api.AffectedFiles(include_deletes=False)
    ]
    image_source_file_paths = [
        path for path in absolute_local_paths
        if "devtools/front_end/Images/src" in path and path.endswith(".svg")
    ]
    image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
                                                "front_end", "Images", "src")
    hashes_file_name = "optimize_png.hashes"
    hashes_file_path = image_sources_path + "/" + hashes_file_name
    invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(
        hashes_file_path, image_source_file_paths)
    if len(invalid_hash_file_paths) == 0:
        return []
    invalid_hash_file_names = [
        re.sub(".*/", "", file_path) for file_path in invalid_hash_file_paths
    ]
    file_paths_str = ", ".join(invalid_hash_file_names)
    error_message = "The following PNG files should be optimized using optimize_png_images.py script before uploading: \n  - %s" % file_paths_str
    return [output_api.PresubmitError(error_message)]
예제 #3
0
def _CheckOptimizeSVGHashes(input_api, output_api):
    if not input_api.platform.startswith('linux'):
        return [output_api.PresubmitNotifyResult('Skipping SVG hash check')]

    results = [
        output_api.PresubmitNotifyResult('Running SVG optimization check:')
    ]

    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build')]
        import devtools_file_hashes
    finally:
        sys.path = original_sys_path

    absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles(include_deletes=False)]
    images_src_path = input_api.os_path.join('devtools', 'front_end', 'Images', 'src')
    image_source_file_paths = [path for path in absolute_local_paths if images_src_path in path and path.endswith('.svg')]
    image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', 'Images', 'src')
    hashes_file_name = 'optimize_svg.hashes'
    hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_name)
    invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths)
    if len(invalid_hash_file_paths) == 0:
        return results
    invalid_hash_file_names = [input_api.os_path.basename(file_path) for file_path in invalid_hash_file_paths]
    file_paths_str = ', '.join(invalid_hash_file_names)
    error_message = 'The following SVG files should be optimized using optimize_svg_images script before uploading: \n  - %s' % file_paths_str
    results.append(output_api.PresubmitError(error_message))
    return results
예제 #4
0
def _CheckConvertSVGToPNGHashes(input_api, output_api):
    if not input_api.platform.startswith('linux'):
        return []

    original_sys_path = sys.path
    try:
        sys.path = sys.path + [
            input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts',
                                   'build')
        ]
        import devtools_file_hashes
    finally:
        sys.path = original_sys_path

    absolute_local_paths = [
        af.AbsoluteLocalPath()
        for af in input_api.AffectedFiles(include_deletes=False)
    ]
    images_src_path = input_api.os_path.join("devtools", "front_end", "Images",
                                             "src")
    image_source_file_paths = [
        path for path in absolute_local_paths
        if images_src_path in path and path.endswith(".svg")
    ]
    image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
                                                "front_end", "Images", "src")
    hashes_file_name = "svg2png.hashes"
    hashes_file_path = input_api.os_path.join(image_sources_path,
                                              hashes_file_name)
    invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(
        hashes_file_path, image_source_file_paths)
    if len(invalid_hash_file_paths) == 0:
        return []
    invalid_hash_file_names = [
        input_api.os_path.basename(file_path)
        for file_path in invalid_hash_file_paths
    ]
    file_paths_str = ", ".join(invalid_hash_file_names)
    error_message = "The following SVG files should be converted to PNG using convert_svg_images_png.py script before uploading: \n  - %s" % file_paths_str
    return [output_api.PresubmitError(error_message)]
예제 #5
0
def _CheckConvertSVGToPNGHashes(input_api, output_api):
    if not input_api.platform.startswith('linux'):
        return []

    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts')]
        import devtools_file_hashes
    finally:
        sys.path = original_sys_path

    absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles(include_deletes=False)]
    image_source_file_paths = [path for path in absolute_local_paths if "devtools/front_end/Images/src" in path and path.endswith(".svg")]
    image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
    hashes_file_name = "svg2png.hashes"
    hashes_file_path = image_sources_path + "/" + hashes_file_name
    invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths)
    if len(invalid_hash_file_paths) == 0:
        return []
    invalid_hash_file_names = [re.sub(".*/", "", file_path) for file_path in invalid_hash_file_paths]
    file_paths_str = ", ".join(invalid_hash_file_names)
    error_message = "The following SVG files should be converted to PNG using convert_svg_images_png.py script before uploading: \n  - %s" % file_paths_str
    return [output_api.PresubmitError(error_message)]
예제 #6
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_optimization_failures = [optimize_svg(svg_file_path) for svg_file_path in svg_file_paths]
if any(svg_optimization_failures):
    sys.exit(1)

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"
    processes[name] = convert_svg_to_png(name, name, 90)
예제 #7
0
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_optimization_failures = [
    optimize_svg(svg_file_path) for svg_file_path in svg_file_paths
]
if any(svg_optimization_failures):
    sys.exit(1)

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)
예제 #8
0
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)
예제 #9
0
    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 = devtools_path + "/front_end"
images_path = devtools_frontend_path + "/Images"
image_sources_path = images_path + "/src"
hashes_file_name = "optimize_png.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_optimize = 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_optimize]

optimize_script_path = "tools/resources/optimize-png-files.sh"


def check_installed(app_name, package, how_to):
    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
        if how_to:
            print how_to
        else:
            print "To install execute the following command: sudo apt-get install %s" % package
        sys.exit(1)