Skip to content

Commit

Permalink
Merge pull request #35 from shanavas786/use-npm-pack
Browse files Browse the repository at this point in the history
Use npm pack to download module files
  • Loading branch information
shanavas786 authored Nov 9, 2016
2 parents 7636425 + da316f0 commit f9c4fc6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions npm2deb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from subprocess import getstatusoutput as _getstatusoutput
import os as _os
import re as _re
import tarfile

from npm2deb import utils, templates
from npm2deb.mapper import Mapper
Expand Down Expand Up @@ -350,22 +351,23 @@ def read_package_info(self):
self._get_json_license()

def download(self):
utils.debug(1, "downloading %s via npm" % self.name)
info = _getstatusoutput('npm install "%s"' % self.name)
utils.debug(1, "downloading %s tarball from npm registry" % self.name)
info = _getstatusoutput('npm pack "%s"' % self.name)
if info[0] is not 0:
exception = "Error downloading package %s\n" % self.name
exception += info[1]
raise ValueError(exception)
# move dir from npm root
root = _getstatusoutput('npm root')[1].strip('\n')
_os.rename(_os.path.join(root, self.name), self.name)
try:
_os.rmdir(root) # remove only if empty
except OSError:
pass
# remove any dependency downloaded via npm
if _os.path.isdir("%s/node_modules" % self.name):
_rmtree("%s/node_modules" % self.name)

tarball_file = info[1].strip('\n')
tarball = tarfile.open(tarball_file)
tarball.extractall()
tarball.close()

# rename extracted directory
_os.rename('package', self.name)
# remove tarball file
_os.remove(tarball_file)

if self.name is not self.debian_name:
utils.debug(2, "renaming %s to %s" % (self.name, self.debian_name))
_os.rename(self.name, self.debian_name)
Expand Down

0 comments on commit f9c4fc6

Please sign in to comment.