Example #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', help='short name of component')
    parser.add_argument('-b', help='bower command')
    parser.add_argument('-p', help='full package name of component')
    parser.add_argument('-v', help='version number')
    parser.add_argument('-s', help='expected content sha1')
    parser.add_argument('-o', help='output file location')
    args = parser.parse_args()

    assert args.p
    assert args.v
    assert args.n

    cwd = os.getcwd()
    outzip = os.path.join(cwd, args.o)
    cached = cache_entry(args.n, args.p, args.v, args.s)

    if not os.path.exists(cached):
        info = bower_info(args.b, args.n, args.p, args.v)
        ignore_deps(info)
        subprocess.check_call(
            bower_cmd(
                args.b, '--quiet', 'install', '%s#%s' % (args.p, args.v)))
        bc = os.path.join(cwd, 'bower_components')
        subprocess.check_call(
            ['zip', '-q', '--exclude', '.bower.json', '-r', cached, args.n],
            cwd=bc)

        if args.s:
            path = os.path.join(bc, args.n)
            sha1 = bowerutil.hash_bower_component(
                hashlib.sha1(), path).hexdigest()
            if args.s != sha1:
                print((
                    '%s#%s:\n'
                    'expected %s\n'
                    'received %s\n') % (args.p, args.v, args.s, sha1),
                    file=sys.stderr)
                try:
                    os.remove(cached)
                except OSError as err:
                    if path.exists(cached):
                        print('error removing %s: %s' % (cached, err),
                              file=sys.stderr)
                return 1

    shutil.copyfile(cached, outzip)
    return 0
Example #2
0
def interpret_bower_json(seeds, ws_out, build_out):
    out = subprocess.check_output(
        ["find", "bower_components/", "-name", ".bower.json"])

    data = []
    for f in sorted(out.split('\n')):
        if not f:
            continue
        pkg = json.load(open(f))
        pkg_name = pkg["name"]

        pkg["bazel-sha1"] = bowerutil.hash_bower_component(
            hashlib.sha1(), os.path.dirname(f)).hexdigest()
        license = pkg.get("license", None)
        if type(license) == type([]):
            # WTF? Some package specify a list of licenses. ("GPL", "MIT")
            pick = license[0]
            sys.stderr.write(
                "package %s has multiple licenses: %s, picking %s" %
                (pkg_name, ", ".join(license), pick))
            license = pick

        if license:
            license = license_map.get(license, license)
        else:
            if pkg_name not in package_licenses:
                msg = "package %s does not specify license: %s" % (pkg_name,
                                                                   pkg)
                sys.stderr.write(msg)
                raise Exception(msg)
            license = package_licenses[pkg_name]

        pkg["bazel-license"] = license

        # TODO(hanwen): bower packages can also have 'fully qualified'
        # names, ("PolymerElements/iron-ajax") as well as short names
        # ("iron-ajax").  It is possible for bower.json files to refer to
        # long names as their dependencies. If any package does this, we
        # will have to either 1) strip off the prefix (typically github
        # user?), or 2) build a map of short name <=> fully qualified
        # name. For now, we just ignore the problem.
        pkg["normalized-name"] = pkg["name"]
        data.append(pkg)

    dump_workspace(data, seeds, ws_out)
    dump_build(data, seeds, build_out)
def main(args):
  opts = optparse.OptionParser()
  opts.add_option('-n', help='short name of component')
  opts.add_option('-b', help='bower command')
  opts.add_option('-p', help='full package name of component')
  opts.add_option('-v', help='version number')
  opts.add_option('-s', help='expected content sha1')
  opts.add_option('-o', help='output file location')
  opts, args_ = opts.parse_args(args)

  assert opts.p
  assert opts.v
  assert opts.n

  cwd = os.getcwd()
  outzip = os.path.join(cwd, opts.o)
  cached = cache_entry(opts.n, opts.p, opts.v, opts.s)

  if not os.path.exists(cached):
    info = bower_info(opts.b, opts.n, opts.p, opts.v)
    ignore_deps(info)
    subprocess.check_call(
        bower_cmd(opts.b, '--quiet', 'install', '%s#%s' % (opts.p, opts.v)))
    bc = os.path.join(cwd, 'bower_components')
    subprocess.check_call(
        ['zip', '-q', '--exclude', '.bower.json', '-r', cached, opts.n],
        cwd=bc)

    if opts.s:
      path = os.path.join(bc, opts.n)
      sha1 = bowerutil.hash_bower_component(hashlib.sha1(), path).hexdigest()
      if opts.s != sha1:
        print((
          '%s#%s:\n'
          'expected %s\n'
          'received %s\n') % (opts.p, opts.v, opts.s, sha1), file=sys.stderr)
        try:
          os.remove(cached)
        except OSError as err:
          if path.exists(cached):
            print('error removing %s: %s' % (cached, err), file=sys.stderr)
        return 1

  shutil.copyfile(cached, outzip)
  return 0
Example #4
0
def interpret_bower_json(seeds, ws_out, build_out):
  out = subprocess.check_output(["find", "bower_components/", "-name", ".bower.json"])

  data = []
  for f in sorted(out.split('\n')):
    if not f:
      continue
    pkg = json.load(open(f))
    pkg_name = pkg["name"]

    pkg["bazel-sha1"] = bowerutil.hash_bower_component(
      hashlib.sha1(), os.path.dirname(f)).hexdigest()
    license = pkg.get("license", None)
    if type(license) == type([]):
      # WTF? Some package specify a list of licenses. ("GPL", "MIT")
      pick = license[0]
      sys.stderr.write("package %s has multiple licenses: %s, picking %s" % (pkg_name, ", ".join(license), pick))
      license = pick

    if license:
      license = license_map.get(license, license)
    else:
      if pkg_name not in package_licenses:
        msg = "package %s does not specify license." % pkg_name
        sys.stderr.write(msg)
        raise Exception(msg)
      license = package_licenses[pkg_name]

    pkg["bazel-license"] = license

    # TODO(hanwen): bower packages can also have 'fully qualified'
    # names, ("PolymerElements/iron-ajax") as well as short names
    # ("iron-ajax").  It is possible for bower.json files to refer to
    # long names as their dependencies. If any package does this, we
    # will have to either 1) strip off the prefix (typically github
    # user?), or 2) build a map of short name <=> fully qualified
    # name. For now, we just ignore the problem.
    pkg["normalized-name"] = pkg["name"]
    data.append(pkg)

  dump_workspace(data, seeds, ws_out)
  dump_build(data, seeds, build_out)
Example #5
0
def interpret_bower_json(seeds, ws_out, build_out):
  out = subprocess.check_output(["find", "bower_components/", "-name", ".bower.json"])

  data = []
  for f in sorted(out.split('\n')):
    if not f:
      continue
    pkg = json.load(open(f))
    pkg_name = pkg["name"]

    pkg["bazel-sha1"] = bowerutil.hash_bower_component(
      hashlib.sha1(), os.path.dirname(f)).hexdigest()
    license = package_licenses.get(pkg_name, "DO_NOT_DISTRIBUTE")

    pkg["bazel-license"] = license
    pkg["normalized-name"] = pkg["_originalSource"]
    data.append(pkg)

  dump_workspace(data, seeds, ws_out)
  dump_build(data, seeds, build_out)