Пример #1
0
 def __init__(self, bower_json_path):
   with open(bower_json_path) as f:
     bower_json = json.load(f)
   self.name = bower_json['name']
   self.version = bower_json['version']
   self.deps = bower_json.get('dependencies', {})
   self.license = bower_json['license']
   self.sha1 = util.hash_bower_component(
       hashlib.sha1(), os.path.dirname(bower_json_path)).hexdigest()
Пример #2
0
 def __init__(self, bower_json_path):
     with open(bower_json_path) as f:
         bower_json = json.load(f)
     self.name = bower_json['name']
     self.version = bower_json['version']
     self.deps = bower_json.get('dependencies', {})
     self.license = bower_json['license']
     self.sha1 = util.hash_bower_component(
         hashlib.sha1(), os.path.dirname(bower_json_path)).hexdigest()
Пример #3
0
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, _ = opts.parse_args()

  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 = util.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