# ex:ts=4:sw=4:sts=4:et # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- """ BitBake 'Fetch' NPM implementation The NPM fetcher is used to retrieve files from the npmjs repository Usage in the recipe: SRC_URI = "npm://registry.npmjs.org/;name=${PN};version=${PV}" Suported SRC_URI options are: - name - version npm://registry.npmjs.org/${PN}/-/${PN}-${PV}.tgz would become npm://registry.npmjs.org;name=${PN};version=${PV} The fetcher all triggers off the existence of ud.localpath. If that exists and has the ".done" stamp, its assumed the fetch is good/done """ import os import sys import urllib.request, urllib.parse, urllib.error import json import subprocess import signal import bb from bb.fetch2 import FetchMethod from bb.fetch2 import FetchError from bb.fetch2 import ChecksumError from bb.fetch2 import runfetchcmd from bb.fetch2 import logger from bb.fetch2 import UnpackError from bb.fetch2 import ParameterError def subprocess_setup(): # Python installs a SIGPIPE handler by default. This is usually not what # non-Python subprocesses expect. # SIGPIPE errors are known issues with gzip/bash signal.signal(signal.SIGPIPE, signal.SIG_DFL) class Npm(FetchMethod): """Class to fetch urls via 'npm'""" def init(self, d): pass def supports(self, ud, d): """ Check to see if a given url can be fetched with npm """ return ud.type in ['npm'] def debug(self, msg): logger.debug(1, "NpmFetch: %s", msg) def clean(self, ud, d): logger.debug(2, "Calling cleanup %s" % ud.pkgname) bb.utils.remove(ud.localpath, False) bb.utils.remove(ud.pkgdatadir, True) bb.utils.remove(ud.fullmirror, False) def urldata_init(self, ud, d): """ init NPM specific variable within url data """ if 'downloadfilename' in ud.parm: ud.basename = ud.parm['downloadfilename'] else: ud.basename = os.path.basename(ud.path) # can't call it ud.name otherwise fetcher base class will start doing sha1stuff # TODO: find a way to get an sha1/sha256 manifest of pkg & all deps ud.pkgname = ud.parm.get("name", None) if not ud.pkgname: raise ParameterError("NPM fetcher requires a name parameter", ud.url) ud.version = ud.parm.get("version", None) if not ud.version: raise ParameterError("NPM fetcher requires a version parameter", ud.url) ud.bbnpmmanifest = "%s-%s.deps.json" % (ud.pkgname, ud.version) ud.bbnpmmanifest = ud.bbnpmmanifest.replace('/', '-') ud.registry = "http://%s" % (ud.url.replace('npm://', '', 1).split(';'))[0] prefixdir = "npm/%s" % ud.pkgname ud.pkgdatadir = d.expand("${DL_DIR}/%s" % prefixdir) if not os.path.exists(ud.pkgdatadir): bb.utils.mkdirhier(ud.pkgdatadir) ud.localpath = d.expand("${DL_DIR}/npm/%s" % ud.bbnpmmanifest) self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -O -t 2 -T 30 -nv --passive-ftp --no-check-certificate " ud.prefixdir = prefixdir ud.write_tarballs = ((d.getVar("BB_GENERATE_MIRROR_TARBALLS") or "0") != "0") mirrortarball = 'npm_%s-%s.tar.xz' % (ud.pkgname, ud.version) mirrortarball = mirrortarball.replace('/', '-') ud.fullmirror = os.path.join(d.getVar("DL_DIR"), mirrortarball) ud.mirrortarballs = [mirrortarball] def need_update(self, ud, d): if os.path.exists(ud.localpath): return False return True def _runwget(self, ud, d, command, quiet): logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command)) bb.fetch2.check_network_access(d, command, ud.url) dldir = d.getVar("DL_DIR") runfetchcmd(command, d, quiet, workdir=dldir) def _unpackdep(self, ud, pkg, data, destdir, dldir, d): file = data[pkg]['tgz'] logger.debug(2, "file to extract is %s" % file) if file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'): cmd = 'tar xz --strip 1 --no-same-owner --warning=no-unknown-keyword -f %s/%s' % (dldir, file) else: bb.fatal("NPM package %s downloaded not a tarball!" % file) # Change to subdir before executing command if not os.path.exists(destdir): os.makedirs(destdir) path = d.getVar('PATH') if path: cmd = "PATH=\"%s\" %s" % (path, cmd) bb.note("Unpacking %s to %s/" % (file, destdir)) ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True, cwd=destdir) if ret != 0: raise UnpackError("Unpack command %s failed with return value %s" % (cmd, ret), ud.url) if 'deps' not in data[pkg]: return for dep in data[pkg]['deps']: self._unpackdep(2013-01-15gitignore: only ignore meta- directoriesEric BĂ©nard 2012-12-14gitignore: Add hob-image-*.bbRichard Purdie 2012-10-11gitignore: Add meta-hob, drop meta-demoappsRichard Purdie 2012-06-21gitignore: ignore build*/ entirelyRoss Burton 2012-06-11gitignore: add wildcard to match toplevel patch filesPaul Gortmaker 2012-05-11.gitignore: add /bitbake to the ignore list for external distributionsJason Wessel 2012-03-15.gitignore: expand pyshtables.py ignoringLauri Hintsala 2011-10-04Update gitignore to ignore all meta-* directoriesMatthew McClintock 2011-07-22.gitignore: Update build ignores to have wildcardKumar Gala 2011-04-20Rename the remaining poky-* scripts to oe-* or runqemu-*Richard Purdie 2011-04-20.gitignore: Drop stale entriesRichard Purdie 2010-12-10poky/.gitignore: updated the lines for the kernel manualScott Rifenbark 2010-12-10poky/.git/.gitignore: added the yocto-project-kernel-manual.pdf fileScott Rifenbark 2010-12-10.git/.gitignore: Added files for the new kernel document.Scott Rifenbark 2010-11-18.gitignore: update for new bsp-guide locationSaul Wold 2010-11-14gitignore: ignore the default downloads directoryJoshua Lock 2010-11-06.gitignore: Update after documentation layout changesRichard Purdie 2010-10-15documentation: Complete poky-handbook -> poky-ref-manual renameRichard Purdie 2010-10-12Update gitignoreJoshua Lock 2010-10-02gitignore: Add meta-extras and meta-m2Richard Purdie 2010-06-08.gitignore: Ignore the built bsp-guideJoshua Lock 2010-03-26.gitignore: Add packaged staging directory to ignore listJoshua Lock 2010-03-23.gitignore: ignore bblayers.confJoshua Lock 2010-03-19.gitignore: Add handbook generated files to the ignore listRichard Purdie 2010-02-01Add *~ to .gitignoreRichard Purdie 2009-08-26Add poky-autobuilder to .gitignoreRichard Purdie 2008-12-17gitignore: Update entries to match various meta repositoriesRichard Purdie 2008-11-06.gitignore: Add extra entriesRichard Purdie 2008-11-04.gitignore: Add build/conf/local.confRichard Purdie 2008-11-03.gitignore: Fix directory reference issueRichard Purdie 2008-10-22Add meta-moblin-internal to gitignoreSamuel Ortiz 2008-10-17Update the ignore file so that it also includes VIM swap filesRobert Bradford 2008-10-17Add .gitignoreRobert Bradford