[Pkg-javascript-commits] [npm2deb] 01/07: Imported Upstream version 0.2.2
Leo Iannacone
l3on-guest at moszumanska.debian.org
Fri Oct 10 14:09:03 UTC 2014
This is an automated email from the git hooks/post-receive script.
l3on-guest pushed a commit to branch master
in repository npm2deb.
commit 37ad94a308ded32c8b53bf5e1564caf5a6af1f6c
Author: Leo Iannacone <l3on at ubuntu.com>
Date: Fri Oct 10 15:42:39 2014 +0200
Imported Upstream version 0.2.2
---
npm2deb/__init__.py | 55 +++++++++++++++++++++++++-----------
npm2deb/helper.py | 4 +--
tests/{npm_coherence.py => tests.py} | 21 ++++++++++++++
3 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index 736415b..cbe9555 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -2,6 +2,7 @@ from json import loads as _parseJSON
from datetime import datetime as _datetime
from dateutil import tz as _tz
from shutil import rmtree as _rmtree
+from urllib.request import urlopen as _urlopen
from subprocess import getstatusoutput as _getstatusoutput
import os as _os
import re as _re
@@ -9,9 +10,9 @@ import re as _re
from npm2deb import utils, templates
from npm2deb.mapper import Mapper
-VERSION = '0.2.1'
+VERSION = '0.2.2'
DEBHELPER = 8
-STANDARDS_VERSION = '3.9.5'
+STANDARDS_VERSION = '3.9.6'
class Npm2Deb(object):
@@ -23,8 +24,8 @@ class Npm2Deb(object):
self.name = module_name
elif 'node_module' in args:
self.name = args['node_module']
- self.args = args
self.json = None
+ self.args = args
self.homepage = None
self.description = None
self.upstream_author = None
@@ -51,6 +52,7 @@ class Npm2Deb(object):
if 'noclean' in args:
self.noclean = args['noclean']
+ self.read_package_info()
self.debian_name = 'node-%s' % self._debianize_name(self.name)
self.debian_author = 'FIX_ME debian author'
if 'DEBFULLNAME' in _os.environ and 'DEBEMAIL' in _os.environ:
@@ -61,7 +63,6 @@ class Npm2Deb(object):
(_os.environ['DEBFULLNAME'], _os.environ['EMAIL'])
self.debian_dest = "usr/lib/nodejs/%s" % self.name
self.date = _datetime.now(_tz.tzlocal())
- self.read_package_info()
def start(self):
self.download()
@@ -269,25 +270,45 @@ class Npm2Deb(object):
utils.create_debian_file("compat", self.debian_debhelper)
def read_package_info(self):
- utils.debug(1, "reading json - calling npm view %s" % self.name)
- info = _getstatusoutput('npm view "%s" --json 2>/dev/null' % self.name)
- # if not status 0, raise expection
- if info[0] != 0:
- info = _getstatusoutput('npm view "%s" --json' % self.name)
- exception = 'npm reports errors about %s module:\n' % self.name
- exception += info[1]
- raise ValueError(exception)
- if not info[1]:
- exception = 'npm returns empty json for %s module' % self.name
- raise ValueError(exception)
+ data = None
+ name_is = None
+ if _re.match("^(http:\/\/|https:\/\/)", self.name):
+ utils.debug(1, "reading json - opening url %s" % self.name)
+ data = _urlopen(self.name).read().decode('utf-8')
+ name_is = 'url'
+
+ elif _os.path.isfile(self.name):
+ utils.debug(1, "reading json - opening file %s" % self.name)
+ with open(self.name, 'r') as fd:
+ data = fd.read()
+ name_is = 'file'
+
+ else:
+ name_is = 'npm'
+ utils.debug(1, "reading json - calling npm view %s" % self.name)
+ info = _getstatusoutput('npm view "%s" --json 2>/dev/null' %
+ self.name)
+ # if not status 0, raise expection
+ if info[0] != 0:
+ info = _getstatusoutput('npm view "%s" --json' % self.name)
+ exception = 'npm reports errors about %s module:\n' % self.name
+ exception += info[1]
+ raise ValueError(exception)
+ if not info[1]:
+ exception = 'npm returns empty json for %s module' % self.name
+ raise ValueError(exception)
+ data = info[1]
try:
- self.json = _parseJSON(info[1])
+ self.json = _parseJSON(data)
except ValueError as value_error:
# if error during parse, try to fail graceful
if str(value_error) == 'Expecting value: line 1 column 1 (char 0)':
+ if name_is != 'npm':
+ raise ValueError("Data read from %s "
+ "is not in a JSON format." % name_is)
versions = []
- for line in info[1].split('\n'):
+ for line in data.split('\n'):
if _re.match(r"^[a-z](.*)@[0-9]", line):
version = line.split('@')[1]
versions.append(version)
diff --git a/npm2deb/helper.py b/npm2deb/helper.py
index 90b57ac..5e8c1c3 100644
--- a/npm2deb/helper.py
+++ b/npm2deb/helper.py
@@ -118,7 +118,7 @@ def search_for_dependencies(module, recursive=False, force=False,
mapper = _Mapper.get_instance()
result = {}
- keys = list(dependencies.keys())
+ keys = sorted(list(dependencies.keys()))
last_dep = False
for dep in keys:
if dep == keys[-1]:
@@ -161,7 +161,7 @@ def search_for_builddep(module):
mapper = _Mapper.get_instance()
result = {}
- for dep in builddeb:
+ for dep in sorted(builddeb.keys()):
result[dep] = {}
result[dep]['version'] = builddeb[dep]
result[dep]['debian'] = mapper.get_debian_package(dep)['repr']
diff --git a/tests/npm_coherence.py b/tests/tests.py
similarity index 89%
rename from tests/npm_coherence.py
rename to tests/tests.py
index 4f77867..6d0ccff 100644
--- a/tests/npm_coherence.py
+++ b/tests/tests.py
@@ -62,6 +62,27 @@ class npm_coherences_license(unittest.TestCase):
self.assertEqual(n.debian_license, 'GPL-3')
+class read_json(unittest.TestCase):
+
+ def test_json_via_npm(self):
+ n = Npm2Deb('serve-index')
+ self.assertEqual(n.name, 'serve-index')
+
+ def test_json_via_url(self):
+ n = Npm2Deb('https://raw.githubusercontent.com/' +
+ 'expressjs/serve-index/master/package.json')
+ self.assertEqual(n.name, 'serve-index')
+
+ def test_json_via_file(self):
+ file_name = '/tmp/test_json_via_file'
+ test_name = "test_name"
+ with open(file_name, 'w') as fd:
+ fd.write('{"name":"%s"}' % test_name)
+ n = Npm2Deb(file_name)
+ os.remove(file_name)
+ self.assertEqual(n.name, test_name)
+
+
class debian(unittest.TestCase):
def tearDown(self):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/npm2deb.git
More information about the Pkg-javascript-commits
mailing list