[Pkg-javascript-commits] [npm2deb] 01/08: Imported Upstream version 0.2.0
Leo Iannacone
l3on-guest at moszumanska.debian.org
Sun Jul 6 16:22:54 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 0def83fa7d56b6e803e078f5016305987bada5f6
Author: Leo Iannacone <l3on at ubuntu.com>
Date: Sun Jul 6 17:27:47 2014 +0200
Imported Upstream version 0.2.0
---
Changelog.md | 36 +++++++++--
README.md | 12 ++--
npm2deb.py | 2 +-
npm2deb/__init__.py | 165 +++++++++++++++++++++++++++----------------------
npm2deb/helper.py | 128 +++++++++++++++++---------------------
npm2deb/mapper.py | 25 +++-----
npm2deb/scripts.py | 99 ++++++++++++++++-------------
npm2deb/templates.py | 18 +++++-
npm2deb/utils.py | 68 ++++++++++----------
setup.py | 4 +-
tests/npm_coherence.py | 24 ++++++-
11 files changed, 329 insertions(+), 252 deletions(-)
diff --git a/Changelog.md b/Changelog.md
index 1ff743b..f01a6ff 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,6 +1,34 @@
-## 0.1.1 (2014-05-07)
+## 0.2.0 (2014-07-04)
+
+ * [new] - only python3 is now supported
+ * [new] - use wnpp-check instead of external service wnpp.debian.net
+ * [new] - add support to autopkgtest - make a simple module require check
+ * [new] - on create add option --upstream-homepage
+ * [new] - on create add option --upstream-author
+ * [new] - forward ITP to debian-devel at lists.debian.org
+
+ * [fix] - correctly set filenamemangle for fakeupstream.cgi
+ * [fix] - correctly localized module location and node_modules path
+ * [fix] - don't expose extenal modules while import Npm2Deb
+ * [fix] - update dversionmangle according with uscan wiki page
+ * [fix] - support repositories defined as str in package.json
+ * [fix] - check if module version is valid before parse it - closes #10
+ * [fix] - check if readmeFilename is not a emtpy value in json before use it
+
- * [FIX] - prevent infinite loop looking for reverse dependencies
+## 0.1.3 (2014-06-04)
+ * [new] - set email headers in ITP template
+ * [fix] - fallback on qa.debian.org/fakeupstream.cgi when uscan fail
+
+## 0.1.2 (2014-05-12)
+ * [new] - add a dversionmangle option to watch by default
+ * [fix] - get builddeps required by the correct version of the module
+ * [fix] - catch KeyboardInterrupt - fail nicely if contrl+c detected
+
+## 0.1.1 (2014-05-07)
+ * [fix] - prevent infinite loop looking for reverse dependencies
+ * [fix] - lintian warning about bsd licenses
+ * [fix] - PEP-8 compliance
-## 0.1.0
-Initial release
+## 0.1.0
+ * Initial release
diff --git a/README.md b/README.md
index eb84f24..167e303 100644
--- a/README.md
+++ b/README.md
@@ -4,15 +4,15 @@ npm2deb
a script to make faster and easier packaging nodejs modules
## Requirements
-You need **npm** installed on your system:
+You need to install these dependencies on your system:
```
-sudo apt-get install npm
+sudo apt-get install devscripts npm python3-dateutil node-github-url-from-git
```
Please, take care to have defined **DEBEMAIL** (or **EMAIL**) and **DEBFULLNAME** environment variables correctly.
## Install
```
-sudo python setup.py install
+sudo python3 setup.py install
```
## Usage
@@ -42,7 +42,9 @@ commands:
```
### Example
-In the most of cases a simple command like this is enough:
+A workflow example is showed here: [wiki.debian.org/Javascript/Nodejs/Npm2Deb](https://wiki.debian.org/Javascript/Nodejs/Npm2Deb)
+
+In the most cases a simple command like this may be enough:
```
-$ npm2deb create bytes
+$ npm2deb create node-module
```
diff --git a/npm2deb.py b/npm2deb.py
index f670f81..7cf7e5e 100755
--- a/npm2deb.py
+++ b/npm2deb.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
import sys
from npm2deb.scripts import main
diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index a259c5c..1986344 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -1,22 +1,15 @@
-#!/usr/bin/python
-
-from json import loads as parseJSON
-from datetime import datetime
-from dateutil import tz
-from shutil import rmtree
-import os
-import re
-
-# python 3 import
-try:
- from commands import getstatusoutput
-except ImportError:
- from subprocess import getstatusoutput
+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 subprocess import getstatusoutput as _getstatusoutput
+import os as _os
+import re as _re
from npm2deb import utils, templates
from npm2deb.mapper import Mapper
-VERSION = '0.1.2'
+VERSION = '0.2.0'
DEBHELPER = 8
STANDARDS_VERSION = '3.9.5'
@@ -45,6 +38,10 @@ class Npm2Deb(object):
if args:
if 'upstream_license' in args and args['upstream_license']:
self.upstream_license = args['upstream_license']
+ if 'upstream_author' in args and args['upstream_author']:
+ self.upstream_author = args['upstream_author']
+ if 'upstream_homepage' in args and args['upstream_homepage']:
+ self.homepage = args['upstream_homepage']
if 'debian_license' in args and args['debian_license']:
self.debian_license = args['debian_license']
if 'standards_version' in args and args['standards_version']:
@@ -56,22 +53,21 @@ class Npm2Deb(object):
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:
+ if 'DEBFULLNAME' in _os.environ and 'DEBEMAIL' in _os.environ:
self.debian_author = "%s <%s>" % \
- (os.environ['DEBFULLNAME'].decode('utf-8'),
- os.environ['DEBEMAIL'].decode('utf-8'))
- elif 'DEBFULLNAME' in os.environ and 'EMAIL' in os.environ:
+ (_os.environ['DEBFULLNAME'], _os.environ['DEBEMAIL'])
+ elif 'DEBFULLNAME' in _os.environ and 'EMAIL' in _os.environ:
self.debian_author = "%s <%s>" % \
- (os.environ['DEBFULLNAME'].decode('utf-8'),
- os.environ['EMAIL'].decode('utf-8'))
+ (_os.environ['DEBFULLNAME'], _os.environ['EMAIL'])
self.debian_dest = "usr/lib/nodejs/%s" % self.name
- self.date = datetime.now(tz.tzlocal())
+ self.date = _datetime.now(_tz.tzlocal())
self.read_package_info()
def start(self):
self.download()
utils.change_dir(self.debian_name)
self.create_base_debian()
+ self.create_tests()
self.create_rules()
self.create_changelog()
self.create_copyright()
@@ -94,22 +90,22 @@ class Npm2Deb(object):
def clean(self):
utils.debug(1, "cleaning directory")
- for filename in os.listdir('.'):
+ for filename in _os.listdir('.'):
if filename != 'debian':
- if os.path.isdir(filename):
- rmtree(filename)
+ if _os.path.isdir(filename):
+ _rmtree(filename)
else:
- os.remove(filename)
+ _os.remove(filename)
def create_manpages(self):
if 'man' in self.json:
- content = os.path.normpath(self.json['man'])
+ content = _os.path.normpath(self.json['man'])
utils.create_debian_file('manpages', content)
def create_watch(self):
args = {}
args['debian_name'] = self.debian_name
- args['dversionmangle'] = 's/\?(debian|dfsg|ds|deb)\d*$//'
+ args['dversionmangle'] = 's/\+(debian|dfsg|ds|deb)(\.\d+)?$//'
args['url'] = self.upstream_repo_url
args['module'] = self.name
try:
@@ -121,10 +117,10 @@ class Npm2Deb(object):
utils.create_debian_file('watch', content)
# test watch with uscan, raise exception if status is not 0
- info = getstatusoutput('uscan --watchfile "debian/watch" '
- '--package "{}" '
- '--upstream-version 0 --no-download'
- .format(self.debian_name))
+ info = _getstatusoutput('uscan --watchfile "debian/watch" '
+ '--package "{}" '
+ '--upstream-version 0 --no-download'
+ .format(self.debian_name))
if info[0] != 0:
raise ValueError
@@ -133,12 +129,12 @@ class Npm2Deb(object):
utils.create_debian_file('watch', content)
def create_examples(self):
- if os.path.isdir('examples'):
+ if _os.path.isdir('examples'):
content = 'examples/*'
utils.create_debian_file('examples', content)
def create_dirs(self):
- if os.path.isdir('bin'):
+ if _os.path.isdir('bin'):
content = 'usr/bin'
utils.create_debian_file('dirs', content)
@@ -147,7 +143,7 @@ class Npm2Deb(object):
dest = self.debian_dest
if 'bin' in self.json:
for script in self.json['bin']:
- orig = os.path.normpath(self.json['bin'][script])
+ orig = _os.path.normpath(self.json['bin'][script])
links.append("%s/%s usr/bin/%s" %
(dest, orig, script))
if len(links) > 0:
@@ -157,20 +153,20 @@ class Npm2Deb(object):
def create_install(self):
content = ''
libs = ['package.json']
- if os.path.isdir('bin'):
+ if _os.path.isdir('bin'):
libs.append('bin')
- if os.path.isdir('lib'):
+ if _os.path.isdir('lib'):
libs.append('lib')
# install main if not in a subpath
if 'main' in self.json:
main = self.json['main']
- main = os.path.normpath(main)
+ main = _os.path.normpath(main)
if main == 'index':
main = 'index.js'
if not main.find('/') > 0:
- libs.append(os.path.normpath(main))
+ libs.append(_os.path.normpath(main))
else:
- if os.path.exists('index.js'):
+ if _os.path.exists('index.js'):
libs.append('index.js')
else:
libs.append('*.js')
@@ -180,10 +176,10 @@ class Npm2Deb(object):
def create_docs(self):
docs = []
- if 'readmeFilename' in self.json:
+ if 'readmeFilename' in self.json and self.json['readmeFilename']:
docs.append(self.json['readmeFilename'])
else:
- for name in os.listdir('.'):
+ for name in _os.listdir('.'):
if name.lower().startswith('readme'):
docs.append(name)
break
@@ -246,14 +242,24 @@ class Npm2Deb(object):
def create_rules(self):
args = {}
args['overrides'] = ''
- for filename in os.listdir('.'):
+ for filename in _os.listdir('.'):
if filename.lower().startswith('history'):
args['overrides'] += "override_dh_installchangelogs:\n" + \
"\tdh_installchangelogs -k %s\n" % filename
break
content = utils.get_template('rules') % args
utils.create_debian_file("rules", content)
- os.system('chmod +x debian/rules')
+ _os.system('chmod +x debian/rules')
+
+ def create_tests(self):
+ utils.create_dir("debian/tests")
+ args = {}
+ args['name'] = self.name
+ args['debian_name'] = self.debian_name
+ control = utils.get_template('tests/control') % args
+ utils.create_debian_file("tests/control", control)
+ require = utils.get_template("tests/require") % args
+ utils.create_debian_file("tests/require", require)
def create_base_debian(self):
utils.debug(1, "creating debian files")
@@ -264,10 +270,10 @@ class Npm2Deb(object):
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)
+ 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)
+ info = _getstatusoutput('npm view "%s" --json' % self.name)
exception = 'npm reports errors about %s module:\n' % self.name
exception += info[1]
raise ValueError(exception)
@@ -276,13 +282,13 @@ class Npm2Deb(object):
raise ValueError(exception)
try:
- self.json = parseJSON(info[1])
+ self.json = _parseJSON(info[1])
except ValueError as value_error:
# if error during parse, try to fail graceful
- if str(value_error) == 'No JSON object could be decoded':
+ if str(value_error) == 'Expecting value: line 1 column 1 (char 0)':
versions = []
for line in info[1].split('\n'):
- if re.match(r"^[a-z](.*)@[0-9]", line):
+ if _re.match(r"^[a-z](.*)@[0-9]", line):
version = line.split('@')[1]
versions.append(version)
if len(versions) > 0:
@@ -304,20 +310,24 @@ class Npm2Deb(object):
def download(self):
utils.debug(1, "downloading %s via npm" % self.name)
- info = getstatusoutput('npm install "%s"' % self.name)
+ info = _getstatusoutput('npm install "%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 node_modules
- os.rename('node_modules/%s' % self.name, self.name)
- rmtree('node_modules')
+ # 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)
+ if _os.path.isdir("%s/node_modules" % self.name):
+ _rmtree("%s/node_modules" % self.name)
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)
+ _os.rename(self.name, self.debian_name)
def get_ITP(self):
args = {}
@@ -364,10 +374,12 @@ class Npm2Deb(object):
self.description = 'FIX_ME description'
def _get_json_author(self):
+ if self.upstream_author:
+ return
result = 'FIX_ME upstream author'
if 'author' in self.json:
author = self.json['author']
- if isinstance(author, (str, unicode)):
+ if isinstance(author, str):
result = author
elif isinstance(author, dict):
if 'name' in author and 'email' in author:
@@ -380,23 +392,29 @@ class Npm2Deb(object):
result = 'FIX_ME repo url'
if 'repository' in self.json:
repository = self.json['repository']
- if 'type' in repository and 'url' in repository:
+ if isinstance(repository, str):
+ url = repository
+ elif isinstance(repository, dict) and 'url' in repository:
url = repository['url']
- if repository['type'] == 'git':
- if url.find('github') >= 0:
- tmp = self._get_github_url_from_git(url)
- if tmp:
- result = tmp
- else:
- url = re.sub(r'^git@(.*):', r'http://\1/', url)
- url = re.sub(r'^git://', 'http://', url)
- url = re.sub(r'\.git$', '', url)
- result = url
+ if url.startswith('git') or (isinstance(repository, dict) and
+ 'type' in repository and
+ repository['type'] == 'git'):
+ if url.find('github') >= 0:
+ tmp = self._get_github_url_from_git(url)
+ if tmp:
+ result = tmp
else:
+ url = _re.sub(r'^git@(.*):', r'http://\1/', url)
+ url = _re.sub(r'^git://', 'http://', url)
+ url = _re.sub(r'\.git$', '', url)
result = url
+ else:
+ result = url
self.upstream_repo_url = result
def _get_json_homepage(self):
+ if self.homepage:
+ return
result = 'FIX_ME homepage'
if 'homepage' in self.json:
result = self.json['homepage']
@@ -417,10 +435,11 @@ class Npm2Deb(object):
mapper.append_warning('error', dep, 'dependency %s '
'not in debian' % (name))
version = dependencies[dep].replace('~', '')
- if version[0].isdigit():
- version = '>= %s' % version
- elif version == '*' or version == 'latest':
- version = None
+ if version:
+ if version[0].isdigit():
+ version = '>= %s' % version
+ elif version == '*' or version == 'latest':
+ version = None
if version:
dep_debian = "%s (%s)" % (name, version)
else:
@@ -433,7 +452,7 @@ class Npm2Deb(object):
return name.replace('_', '-')
def _get_github_url_from_git(self, url):
- result = getstatusoutput(
+ result = _getstatusoutput(
"nodejs -e "
"\"console.log(require('github-url-from-git')"
"('%s'));\"" % url)[1]
diff --git a/npm2deb/helper.py b/npm2deb/helper.py
index 341c0e6..90b57ac 100644
--- a/npm2deb/helper.py
+++ b/npm2deb/helper.py
@@ -1,27 +1,25 @@
# -*- coding: utf-8 -*-
-from json import loads as parseJSON
-from xml.dom import minidom
-from npm2deb import Npm2Deb
-from npm2deb.utils import debug
-from npm2deb.mapper import Mapper
-
-try:
- from urllib.request import urlopen
- from subprocess import getstatusoutput
-except ImportError:
- from commands import getstatusoutput
- from urllib2 import urlopen
+from json import loads as _parseJSON
+from xml.dom import minidom as _minidom
+from urllib.request import urlopen as _urlopen
+from subprocess import getstatusoutput as _getstatusoutput
+import re as _re
+
+from npm2deb import Npm2Deb as _Npm2Deb
+from npm2deb.utils import debug as _debug
+from npm2deb.mapper import Mapper as _Mapper
+
DO_PRINT = False
def my_print(what):
if DO_PRINT:
- print(what.encode('utf-8'))
+ print(what)
def search_for_repository(module):
- if isinstance(module, Npm2Deb):
+ if isinstance(module, _Npm2Deb):
module = module.name
repositories = ['collab-maint', 'pkg-javascript']
formatted = " {0:40} -- {1}"
@@ -29,11 +27,11 @@ def search_for_repository(module):
result = {}
my_print("Looking for existing repositories:")
for repo in repositories:
- debug(1, "search for %s in %s" % (module, repo))
+ _debug(1, "search for %s in %s" % (module, repo))
url_base = "http://anonscm.debian.org/gitweb"
- data = urlopen("%s/?a=project_list&pf=%s&s=%s" %
- (url_base, repo, module)).read()
- dom = minidom.parseString(data)
+ data = _urlopen("%s/?a=project_list&pf=%s&s=%s" %
+ (url_base, repo, module)).read()
+ dom = _minidom.parseString(data)
for row in dom.getElementsByTagName('tr')[1:]:
try:
columns = row.getElementsByTagName('td')
@@ -51,55 +49,45 @@ def search_for_repository(module):
def search_for_bug(module):
- if isinstance(module, Npm2Deb):
+ if isinstance(module, _Npm2Deb):
module = module.name
- url = 'http://wnpp.debian.net/'
- '?type%5B%5D=ITA&type%5B%5D=ITP&type%5B%5D=O&type%5B%5D=RFA' \
- '&type%5B%5D=RFH&type%5B%5D=RFP&project=&description=&owner%5B%5D=yes' \
- '&owner%5B%5D=no&col%5B%5D=type&col%5B%5D=description&sort=project'
my_print('Looking for wnpp bugs:')
- debug(1, "getting bugs from http://wnpp.debian.net")
- data = urlopen(url).read()
- rows = data.split('class="data_table">')[1].split('</table>')[0].split('\n')
- found = False
- formatted = " #{0} {1:>3}: {2:25} -- {3}"
- result = []
- for row in rows:
- row = row.replace(' ', '')
- if len(row) > 0:
+ _debug(1, "calling wnpp-check")
+ info = _getstatusoutput('wnpp-check %s' % module)
+ if info[0] == 0:
+ my_print(' None')
+ return []
+ else:
+ lines = info[1].split('\n')
+ formatted = " #{0} {1:>3}: {2:25} -- {3}"
+ result = []
+ for line in lines:
try:
bug = {}
- dom = minidom.parseString(row)
- tmp = dom.getElementsByTagName('a')[0]
- bug["num"] = tmp.getAttribute('href').split('?bug=')[1]
- bug["package"] = tmp.childNodes[0].data
- tmp = dom.getElementsByTagName('td')[-1]
- bug["type"] = tmp.getAttribute('class')
- bug["description"] = tmp.childNodes[0].childNodes[0].data
- if bug["package"].find(module) >= 0 or \
- bug["description"].find(module) >= 0:
- found = True
- result.append(bug)
- my_print(formatted.format(bug["num"],
- bug["type"],
- bug["package"],
- bug["description"]))
+ match = _re.match('\((.*) - #(\d+).*\) (.*) (.*)$', line)
+ bug['num'] = match.group(2)
+ bug['type'] = match.group(1)
+ bug['package'] = match.group(4)
+ bug['url'] = match.group(3)
+ result.append(bug)
+ my_print(formatted.format(bug["num"],
+ bug["type"],
+ bug["package"],
+ bug["url"]))
except:
- continue
- if not found:
- my_print(' None')
- return result
+ continue
+ return result
def search_for_reverse_dependencies(module):
- if isinstance(module, Npm2Deb):
+ if isinstance(module, _Npm2Deb):
module = module.name
url = "http://registry.npmjs.org/-/_view/dependedUpon?startkey=" \
+ "[%%22%(name)s%%22]&endkey=[%%22%(name)s%%22,%%7B%%7D]&group_level=2"
url = url % {'name': module}
- debug(1, "opening url %s" % url)
- data = urlopen(url).read()
- data = parseJSON(data)
+ _debug(1, "opening url %s" % url)
+ data = _urlopen(url).read().decode('utf-8')
+ data = _parseJSON(data)
result = []
if 'rows' in data and len(data['rows']) > 0:
my_print("Reverse Depends:")
@@ -115,22 +103,22 @@ def search_for_reverse_dependencies(module):
def search_for_dependencies(module, recursive=False, force=False,
prefix=u'', expanded_dependencies=[]):
try:
- if not isinstance(module, Npm2Deb):
- debug(1, 'getting dependencies - calling npm view %s' % module)
- npm_out = getstatusoutput('npm view "%s" '
- 'dependencies --json 2>/dev/null'
- % module)[1]
- dependencies = parseJSON(npm_out)
+ if not isinstance(module, _Npm2Deb):
+ _debug(1, 'getting dependencies - calling npm view %s' % module)
+ npm_out = _getstatusoutput('npm view "%s" '
+ 'dependencies --json 2>/dev/null'
+ % module)[1]
+ dependencies = _parseJSON(npm_out)
else:
dependencies = module.json['dependencies']
module = module.name
except ValueError:
return None
- mapper = Mapper.get_instance()
+ mapper = _Mapper.get_instance()
result = {}
- keys = dependencies.keys()
+ keys = list(dependencies.keys())
last_dep = False
for dep in keys:
if dep == keys[-1]:
@@ -158,19 +146,19 @@ def search_for_dependencies(module, recursive=False, force=False,
def search_for_builddep(module):
try:
- if not isinstance(module, Npm2Deb):
- debug(1, 'getting builddep - calling npm view %s' % module)
- npm_out = getstatusoutput('npm view "%s" '
- 'devDependencies --json 2>/dev/null'
- % module)[1]
- builddeb = parseJSON(npm_out)
+ if not isinstance(module, _Npm2Deb):
+ _debug(1, 'getting builddep - calling npm view %s' % module)
+ npm_out = _getstatusoutput('npm view "%s" '
+ 'devDependencies --json 2>/dev/null'
+ % module)[1]
+ builddeb = _parseJSON(npm_out)
else:
builddeb = module.json['devDependencies']
module = module.name
except ValueError:
return None
- mapper = Mapper.get_instance()
+ mapper = _Mapper.get_instance()
result = {}
for dep in builddeb:
diff --git a/npm2deb/mapper.py b/npm2deb/mapper.py
index d40296f..5a7e26f 100644
--- a/npm2deb/mapper.py
+++ b/npm2deb/mapper.py
@@ -1,14 +1,9 @@
-from json import loads as parseJSON
-from re import findall
-from npm2deb.utils import debug
-
-try:
- from urllib.request import urlopen
- from subprocess import getstatusoutput
-except ImportError:
- from commands import getstatusoutput
- from urllib2 import urlopen
+from json import loads as _parseJSON
+from re import findall as _findall
+from urllib.request import urlopen as _urlopen
+from subprocess import getstatusoutput as _getstatusoutput
+from npm2deb.utils import debug as _debug
DB_URL = 'https://wiki.debian.org/Javascript/Nodejs/Database'
@@ -20,10 +15,10 @@ class Mapper(object):
if self.INSTANCE is not None:
raise ValueError("Mapper is a Singleton. "
"Please use get_instance method.")
- debug(2, 'loading database from %s' % DB_URL)
- data = findall('{{{(.*)}}}', urlopen("%s?action=raw"
- % DB_URL).read().replace('\n', ''))[0]
- self.json = parseJSON(data)
+ _debug(2, 'loading database from %s' % DB_URL)
+ data = _findall('{{{(.*)}}}', _urlopen("%s?action=raw"
+ % DB_URL).read().decode('utf-8').replace('\n', ''))[0]
+ self.json = _parseJSON(data)
self._warnings = {}
self.reset_warnings()
@@ -60,7 +55,7 @@ class Mapper(object):
if not result['name']:
return result
- madison = getstatusoutput(
+ madison = _getstatusoutput(
'apt-cache madison "%s" | grep Sources' % result['name'])
if madison[0] != 0:
diff --git a/npm2deb/scripts.py b/npm2deb/scripts.py
index 4e6e346..b908216 100644
--- a/npm2deb/scripts.py
+++ b/npm2deb/scripts.py
@@ -1,22 +1,24 @@
-#!/usr/bin/python
+from argparse import ArgumentParser as _ArgumentParser
+from subprocess import call as _call
+import os as _os
+import sys as _sys
-from argparse import ArgumentParser
-from npm2deb import Npm2Deb, utils, templates, helper, \
- DEBHELPER, STANDARDS_VERSION, VERSION
-from npm2deb.mapper import Mapper
-from subprocess import call
-import os
-import sys
+from npm2deb import Npm2Deb as _Npm2Deb
+from npm2deb import utils as _utils
+from npm2deb import templates as _templates
+from npm2deb import helper as _helper
+from npm2deb import Mapper as _Mapper
+import npm2deb as _
def main(argv=None):
if not argv:
- argv = sys.argv
- parser = ArgumentParser(prog='npm2deb')
+ argv = _sys.argv
+ parser = _ArgumentParser(prog='npm2deb')
parser.add_argument('-D', '--debug', type=int, help='set debug level')
parser.add_argument(
'-v', '--version', action='version',
- version='%(prog)s ' + VERSION)
+ version='%(prog)s ' + _.VERSION)
subparsers = parser.add_subparsers(title='commands')
@@ -27,12 +29,18 @@ def main(argv=None):
'-n', '--noclean', action="store_true",
default=False, help='do not remove files downloaded with npm')
parser_create.add_argument(
- '--debhelper', default=DEBHELPER,
+ '--debhelper', default=_.DEBHELPER,
help='specify debhelper version [default: %(default)s]')
parser_create.add_argument(
- '--standards-version', default=STANDARDS_VERSION,
+ '--standards-version', default=_.STANDARDS_VERSION,
help='set standards-version [default: %(default)s]')
parser_create.add_argument(
+ '--upstream-author', default=None,
+ help='set upstream author if not automatically recognized')
+ parser_create.add_argument(
+ '--upstream-homepage', default=None,
+ help='set upstream homepage if not automatically recognized')
+ parser_create.add_argument(
'--upstream-license', default=None,
help='set upstream license if not automatically recognized')
parser_create.add_argument(
@@ -118,16 +126,18 @@ def main(argv=None):
help='the license name to show')
parser_license.set_defaults(func=print_license)
- args = parser.parse_args(argv[1:])
-
- if args.debug:
- utils.DEBUG_LEVEL = args.debug
+ if len(argv) == 1:
+ parser.error("Please specify an option.")
+ else:
+ args = parser.parse_args(argv[1:])
+ if args.debug:
+ _utils.DEBUG_LEVEL = args.debug
- args.func(args)
+ args.func(args)
def search_for_module(args):
- helper.DO_PRINT = True
+ _helper.DO_PRINT = True
# enable all by default
if not args.bug and not args.debian and not args.repository:
args.bug = True
@@ -136,14 +146,14 @@ def search_for_module(args):
node_module = get_npm2deb_instance(args).name
if args.debian:
print("\nLooking for similiar package:")
- mapper = Mapper.get_instance()
+ mapper = _Mapper.get_instance()
print(" %s" % mapper.get_debian_package(node_module)['repr'])
if args.repository:
print("")
- helper.search_for_repository(node_module)
+ _helper.search_for_repository(node_module)
if args.bug:
print("")
- helper.search_for_bug(node_module)
+ _helper.search_for_bug(node_module)
print("")
_show_mapper_warnings()
@@ -171,7 +181,7 @@ def print_view(args):
print(formatted.format("%s:" % key.capitalize(),
getattr(npm2deb_instance, attr_key, None)))
- mapper = Mapper.get_instance()
+ mapper = _Mapper.get_instance()
print(formatted.format("Debian:", mapper
.get_debian_package(npm2deb_instance.name)['repr']))
@@ -186,15 +196,16 @@ def print_itp(args):
def print_license(args, prefix=""):
if args.list:
+ licenses = sorted(_templates.LICENSES.keys())
print("%s Available licenses are: %s." %
- (prefix, ', '.join(sorted(templates.LICENSES.keys())).lower()))
+ (prefix, ', '.join(licenses).lower()))
else:
if args.name is None:
print("You have to specify a license name")
args.list = True
print_license(args)
else:
- template_license = utils.get_license(args.name)
+ template_license = _utils.get_license(args.name)
if not template_license.startswith('FIX_ME'):
print(template_license)
else:
@@ -204,7 +215,7 @@ def print_license(args, prefix=""):
def show_dependencies(args):
- helper.DO_PRINT = True
+ _helper.DO_PRINT = True
# enable all by default
if not args.binary and not args.builddeb:
args.binary = True
@@ -217,16 +228,16 @@ def show_dependencies(args):
if args.binary:
if 'dependencies' in json and json['dependencies']:
print("Dependencies:")
- helper.print_formatted_dependency("NPM", "Debian")
+ _helper.print_formatted_dependency("NPM", "Debian")
module_ver = npm2deb_instance.upstream_version
- module_deb = Mapper.get_instance()\
+ module_deb = _Mapper.get_instance()\
.get_debian_package(module_name)["repr"]
- helper.print_formatted_dependency("%s (%s)" %
+ _helper.print_formatted_dependency("%s (%s)" %
(module_name, module_ver),
- module_deb)
- helper.search_for_dependencies(npm2deb_instance,
- args.recursive,
- args.force)
+ module_deb)
+ _helper.search_for_dependencies(npm2deb_instance,
+ args.recursive,
+ args.force)
print("")
else:
print("Module %s has no dependencies." % module_name)
@@ -234,8 +245,8 @@ def show_dependencies(args):
if args.builddeb:
if 'devDependencies' in json and json['devDependencies']:
print("Build dependencies:")
- helper.print_formatted_dependency("NPM", "Debian")
- helper.search_for_builddep(npm2deb_instance)
+ _helper.print_formatted_dependency("NPM", "Debian")
+ _helper.search_for_builddep(npm2deb_instance)
print("")
else:
print("Module %s has no build dependencies." % module_name)
@@ -244,19 +255,19 @@ def show_dependencies(args):
def show_reverse_dependencies(args):
- helper.DO_PRINT = True
+ _helper.DO_PRINT = True
node_module = get_npm2deb_instance(args).name
- helper.search_for_reverse_dependencies(node_module)
+ _helper.search_for_reverse_dependencies(node_module)
def create(args):
npm2deb = get_npm2deb_instance(args)
try:
- saved_path = os.getcwd()
- utils.create_dir(npm2deb.name)
- utils.change_dir(npm2deb.name)
+ saved_path = _os.getcwd()
+ _utils.create_dir(npm2deb.name)
+ _utils.change_dir(npm2deb.name)
npm2deb.start()
- utils.change_dir(saved_path)
+ _utils.change_dir(saved_path)
except OSError as os_error:
print(str(os_error))
exit(1)
@@ -266,7 +277,7 @@ def create(args):
print("""
This is not a crystal ball, so please take a look at auto-generated files.\n
You may want fix first these issues:\n""")
- call('/bin/grep --color=auto FIX_ME -r %s/*' % debian_path, shell=True)
+ _call('/bin/grep --color=auto FIX_ME -r %s/*' % debian_path, shell=True)
print ("\nUse uscan to get orig source files. Fix debian/watch and then run\
\n$ uscan --download-current-version\n")
@@ -278,14 +289,14 @@ def get_npm2deb_instance(args):
print('please specify a node_module.')
exit(1)
try:
- return Npm2Deb(args=vars(args))
+ return _Npm2Deb(args=vars(args))
except ValueError as value_error:
print(value_error)
exit(1)
def _show_mapper_warnings():
- mapper = Mapper.get_instance()
+ mapper = _Mapper.get_instance()
if mapper.has_warnings():
print("Warnings occured:")
mapper.show_warnings()
diff --git a/npm2deb/templates.py b/npm2deb/templates.py
index 42a7ed1..cd44337 100644
--- a/npm2deb/templates.py
+++ b/npm2deb/templates.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python
-
CHANGELOG = """%(debian_name)s (%(version)s-1) unstable; urgency=low
* Initial release (Closes: #nnnn)
@@ -21,6 +19,7 @@ Standards-Version: %(Standards-Version)s
Homepage: %(Homepage)s
Vcs-Git: %(Vcs-Git)s
Vcs-Browser: %(Vcs-Browser)s
+XS-Testsuite: autopkgtest
Package: %(Package)s
Architecture: all
@@ -72,6 +71,7 @@ Subject: ITP: %(debian_name)s -- %(description)s
Package: wnpp
Severity: wishlist
Owner: %(debian_author)s
+X-Debbugs-CC: debian-devel at lists.debian.org
* Package name : %(debian_name)s
Version : %(version)s
@@ -273,6 +273,18 @@ WATCH['fakeupstream'] = """version=3
# Take a look at https://wiki.debian.org/debian/watch/
# See also fakeupstream: http://anonscm.debian.org/viewvc/qa/trunk/cgi-bin/fakeupstream.cgi?view=markup
opts=\\
-dversionmangle=%(dversionmangle)s \\
+dversionmangle=%(dversionmangle)s,\\
+filenamemangle=s/.*=// \\
http://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=npmjs/%(module)s .*=%(module)s-(\d.*)\.(?:tgz|tar\.(?:gz|bz2|xz))
"""
+
+TESTS = {}
+
+TESTS['control'] = """Tests: require
+Depends: %(debian_name)s
+"""
+
+TESTS['require'] = """#!/bin/sh
+set -e
+nodejs -e "require('%(name)s');"
+"""
diff --git a/npm2deb/utils.py b/npm2deb/utils.py
index d16f9ae..6e80286 100644
--- a/npm2deb/utils.py
+++ b/npm2deb/utils.py
@@ -1,14 +1,9 @@
-#!/usr/bin/python
+from subprocess import getstatusoutput as _getstatusoutput
+import codecs as _codecs
+import os as _os
-from npm2deb import templates
-import codecs
-import os
+from npm2deb import templates as _templates
-# python 3 import
-try:
- from commands import getstatusoutput
-except ImportError:
- from subprocess import getstatusoutput
DEBUG_LEVEL = 0
@@ -19,52 +14,57 @@ def debug(level, msg):
def get_npm_version(module_name):
- return getstatusoutput(
+ return _getstatusoutput(
'npm view "%s" version' % module_name)[1].split('\n')[-2].strip()
def get_template(filename):
result = None
- if filename is 'control':
- result = templates.CONTROL
- elif filename is 'copyright':
- result = templates.COPYRIGHT
- elif filename is 'rules':
- result = templates.RULES
- elif filename is 'wnpp':
- result = templates.WNPP
+ if filename == 'control':
+ result = _templates.CONTROL
+ elif filename == 'copyright':
+ result = _templates.COPYRIGHT
+ elif filename == 'rules':
+ result = _templates.RULES
+ elif filename == 'wnpp':
+ result = _templates.WNPP
+ elif filename == 'tests/control':
+ result = _templates.TESTS['control']
+ elif filename == 'tests/require':
+ result = _templates.TESTS['require']
return result
+
def get_watch(which):
if which == 'github':
- return templates.WATCH['github']
+ return _templates.WATCH['github']
elif which == 'bitbucket':
- return templates.WATCH['bitbucket']
+ return _templates.WATCH['bitbucket']
else:
- return templates.WATCH['fakeupstream']
+ return _templates.WATCH['fakeupstream']
def get_license(license):
result = None
name = license.lower().replace('-', '')
if name.startswith('gpl2'):
- result = templates.LICENSES['GPL-2']
+ result = _templates.LICENSES['GPL-2']
elif name.startswith('gpl3'):
- result = templates.LICENSES['GPL-3']
+ result = _templates.LICENSES['GPL-3']
elif name.startswith('lgpl2'):
- result = templates.LICENSES['LGPL-2']
+ result = _templates.LICENSES['LGPL-2']
elif name.startswith('lgpl3'):
- result = templates.LICENSES['LGPL-3']
+ result = _templates.LICENSES['LGPL-3']
elif name.startswith('mit'):
- result = templates.LICENSES['MIT']
+ result = _templates.LICENSES['MIT']
elif name.startswith('expat'):
- result = templates.LICENSES['Expat']
+ result = _templates.LICENSES['Expat']
elif name.startswith('bsd'):
- result = templates.LICENSES['BSD']
+ result = _templates.LICENSES['BSD']
elif name.startswith('artistic'):
- result = templates.LICENSES['Artistic']
+ result = _templates.LICENSES['Artistic']
elif name.startswith('apache'):
- result = templates.LICENSES['Apache']
+ result = _templates.LICENSES['Apache']
else:
result = 'FIX_ME please specify a license description'
return result
@@ -73,7 +73,7 @@ def get_license(license):
def change_dir(dir):
debug(2, "moving to directory %s" % dir)
try:
- os.chdir(dir)
+ _os.chdir(dir)
except OSError as oserror:
raise OSError("OSError [%d]: %s at %s" %
(oserror.errno, oserror.strerror, oserror.filename))
@@ -86,16 +86,16 @@ def create_debian_file(filename, content):
def create_file(filename, content):
debug(2, "creating file %s" % filename)
content = u'%s' % content
- if content[-1] != '\n':
+ if len(content) > 0 and content[-1] != '\n':
content += '\n'
- with codecs.open(filename, 'w', 'utf-8') as writer:
+ with _codecs.open(filename, 'w', 'utf-8') as writer:
writer.write(content)
def create_dir(dir):
debug(2, "creating directory %s" % dir)
try:
- os.mkdir(dir)
+ _os.mkdir(dir)
except OSError as oserror:
raise OSError("Error: directory %s already exists." %
oserror.filename)
diff --git a/setup.py b/setup.py
index bac15e8..30ceea7 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
+
from distutils.core import setup
from distutils.command.install_scripts import install_scripts
from npm2deb import VERSION
@@ -21,7 +22,6 @@ setup(name='npm2deb',
license='GNU GPL-3',
scripts=['npm2deb.py'],
packages=['npm2deb'],
- dependencies=['dateutil'],
data_files=[
('share/man/man1', ['man/npm2deb.1']),
('share/doc/npm2deb', ['README.md', 'AUTHORS']),
diff --git a/tests/npm_coherence.py b/tests/npm_coherence.py
index a3d59d1..4f77867 100644
--- a/tests/npm_coherence.py
+++ b/tests/npm_coherence.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
import sys
import os
import inspect
@@ -128,12 +130,32 @@ class debian(unittest.TestCase):
line = self._get_debfile_line('watch', '/fakeupstream')
self.assertTrue(line is not None and len(line) > 0)
+ def test_repository_defined_as_string(self):
+ n = Npm2Deb('ipaddr.js')
+ self.assertEqual(n.upstream_repo_url,
+ 'https://github.com/whitequark/ipaddr.js')
+
def test_install_bin(self):
n = Npm2Deb('mocha')
n.create_base_debian()
n.create_links()
line = self._get_debfile_line('links', 'mocha')
- self.assertTrue(line == 'usr/lib/nodejs/mocha/bin/mocha usr/bin/mocha')
+ self.assertEqual(line, 'usr/lib/nodejs/mocha/bin/mocha usr/bin/mocha')
+
+ def test_write_tests(self):
+ n = Npm2Deb('debug')
+ n.create_base_debian()
+ n.create_tests()
+ line = self._get_debfile_line('tests/control', 'node-debug')
+ self.assertEqual(line, 'Depends: node-debug')
+ line = self._get_debfile_line('tests/require', 'debug')
+ self.assertEqual(line, """nodejs -e "require('debug');\"""")
+
+ ## Issues fixed
+ def test_issue_10(self):
+ n = Npm2Deb('lastfm')
+ n.create_base_debian()
+ n.create_control()
if __name__ == '__main__':
--
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