Ejemplo n.º 1
0
def strip_private_fields():
    # npm adds private fields which need to be stripped.
    pattern = path.join(devtools_paths.node_modules_path(), 'package.json')
    packages = []
    for root, dirnames, filenames in os.walk(
            devtools_paths.node_modules_path()):
        for filename in filter(lambda f: f == 'package.json', filenames):
            packages.append(path.join(root, filename))

    for pkg in packages:
        with open(pkg, 'r+') as pkg_file:
            try:
                pkg_data = json.load(pkg_file)

                # Remove anything that begins with an underscore, as these are
                # the private fields in a package.json
                for key in pkg_data.keys():
                    if key.find(u'_') == 0:
                        pkg_data.pop(key)

                pkg_file.truncate(0)
                pkg_file.seek(0)
                json.dump(pkg_data,
                          pkg_file,
                          indent=2,
                          sort_keys=True,
                          separators=(',', ': '))
            except:
                print('Unable to fix: %s' % pkg)
                return True

    return False
Ejemplo n.º 2
0
def addClangFormat():
    with open(path.join(devtools_paths.node_modules_path(), '.clang-format'), 'w+') as clang_format_file:
        try:
            clang_format_file.write('DisableFormat: true\n')
        except:
            print('Unable to write .clang-format file')
            return True
    return False
Ejemplo n.º 3
0
def clean_node_modules():
    # Clean the node_modules folder first. That way only the packages listed above
    # (and their deps) are installed.
    try:
        shutil.rmtree(path.realpath(devtools_paths.node_modules_path()))
    except OSError as err:
        print('Error removing node_modules: %s, %s' %
              (err.filename, err.strerror))
Ejemplo n.º 4
0
def addOwnersFile():
    with open(path.join(devtools_paths.node_modules_path(), 'OWNERS'),
              'w+') as owners_file:
        try:
            owners_file.write('file://config/owner/INFRA_OWNERS\n')
        except:
            print('Unable to write OWNERS file')
            return True
    return False
Ejemplo n.º 5
0
def addChromiumReadme():
    with open(path.join(devtools_paths.node_modules_path(), 'README.chromium'),
              'w+') as readme_file:
        try:
            readme_file.write('This directory hosts all packages downloaded from NPM that are used in either the build system or infrastructure scripts.\n')
            readme_file.write('If you want to make any changes to this directory, please see "scripts/deps/manage_node_deps.py".\n')
        except:
            print('Unable to write README.chromium file')
            return True
    return False
Ejemplo n.º 6
0
def run_tests():
    karma_errors_found = False
    karmaconfig_path = os.path.join(devtools_path, 'karma.conf.js')
    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.karma_path(), 'start',
        to_platform_path_exact(karmaconfig_path)
    ]

    env = {'NODE_PATH': devtools_paths.node_modules_path()}
    if (chrome_binary is not None):
        env['CHROME_BIN'] = chrome_binary

    karma_proc = popen(exec_command, cwd=devtools_path, env=env)

    (karma_proc_out, _) = karma_proc.communicate()
    if karma_proc.returncode != 0:
        karma_errors_found = True
    else:
        print('Karma exited successfully')

    print(karma_proc_out)
    return karma_errors_found