[Pkg-javascript-commits] [npm2deb] 01/03: Imported Upstream version 0.1.3

Leo Iannacone l3on-guest at moszumanska.debian.org
Mon Jun 9 10:28:51 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 f8412635c9b523764e74cfa98a36001d3dfc9b09
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Mon Jun 9 12:28:02 2014 +0200

    Imported Upstream version 0.1.3
---
 npm2deb/__init__.py    | 49 ++++++++++++++++++++++++++++++-------------------
 npm2deb/helper.py      |  9 +++++++--
 npm2deb/mapper.py      | 10 ++++++++--
 npm2deb/scripts.py     |  8 ++++----
 npm2deb/templates.py   | 22 ++++++++++++++++++----
 npm2deb/utils.py       |  8 ++++++++
 tests/npm_coherence.py | 31 +++++++++++++++++++++++++++++++
 7 files changed, 106 insertions(+), 31 deletions(-)

diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index bb2d710..a259c5c 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -68,9 +68,6 @@ class Npm2Deb(object):
         self.date = datetime.now(tz.tzlocal())
         self.read_package_info()
 
-    def show_itp(self):
-        print self._get_ITP()
-
     def start(self):
         self.download()
         utils.change_dir(self.debian_name)
@@ -93,7 +90,7 @@ class Npm2Deb(object):
 
     def create_itp_bug(self):
         utils.debug(1, "creating wnpp bug template")
-        utils.create_file('%s_itp.mail' % self.debian_name, self._get_ITP())
+        utils.create_file('%s_itp.mail' % self.debian_name, self.get_ITP())
 
     def clean(self):
         utils.debug(1, "cleaning directory")
@@ -111,16 +108,29 @@ class Npm2Deb(object):
 
     def create_watch(self):
         args = {}
-        if self.upstream_repo_url and \
-                self.upstream_repo_url.find('github') >= 0:
-            args['homepage'] = self.upstream_repo_url
-            args['debian_name'] = self.debian_name
-            content = templates.WATCH_GITHUB % args
-        else:
-            content = "# FIX_ME Please take a look " \
-                "at https://wiki.debian.org/debian/watch/\n" \
-                "Homepage is %s\n" % self.homepage
-        utils.create_debian_file('watch', content)
+        args['debian_name'] = self.debian_name
+        args['dversionmangle'] = 's/\?(debian|dfsg|ds|deb)\d*$//'
+        args['url'] = self.upstream_repo_url
+        args['module'] = self.name
+        try:
+            if self.upstream_repo_url.find('github') >= 0:
+                content = utils.get_watch('github') % args
+            else:
+                # if not supported, got to fakeupstream
+                raise ValueError
+
+            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))
+            if info[0] != 0:
+                raise ValueError
+
+        except ValueError:
+            content = utils.get_watch('fakeupstream') % args
+            utils.create_debian_file('watch', content)
 
     def create_examples(self):
         if os.path.isdir('examples'):
@@ -135,10 +145,11 @@ class Npm2Deb(object):
     def create_links(self):
         links = []
         dest = self.debian_dest
-        if os.path.isdir('bin'):
-            for script in os.listdir('bin'):
-                links.append("%s/bin/%s usr/bin/%s" %
-                            (dest, script, script.replace('.js', '')))
+        if 'bin' in self.json:
+            for script in self.json['bin']:
+                orig = os.path.normpath(self.json['bin'][script])
+                links.append("%s/%s usr/bin/%s" %
+                            (dest, orig, script))
         if len(links) > 0:
             content = '\n'.join(links)
             utils.create_debian_file('links', content)
@@ -308,7 +319,7 @@ class Npm2Deb(object):
             utils.debug(2, "renaming %s to %s" % (self.name, self.debian_name))
             os.rename(self.name, self.debian_name)
 
-    def _get_ITP(self):
+    def get_ITP(self):
         args = {}
         args['debian_author'] = self.debian_author
         args['debian_name'] = self.debian_name
diff --git a/npm2deb/helper.py b/npm2deb/helper.py
index 5edd4d7..341c0e6 100644
--- a/npm2deb/helper.py
+++ b/npm2deb/helper.py
@@ -1,12 +1,17 @@
 # -*- coding: utf-8 -*-
-from commands import getstatusoutput
 from json import loads as parseJSON
-from urllib2 import urlopen
 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
+
 DO_PRINT = False
 
 
diff --git a/npm2deb/mapper.py b/npm2deb/mapper.py
index 3de2e90..d40296f 100644
--- a/npm2deb/mapper.py
+++ b/npm2deb/mapper.py
@@ -1,9 +1,15 @@
-from urllib2 import urlopen
 from json import loads as parseJSON
-from commands import getstatusoutput
 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
+
+
 DB_URL = 'https://wiki.debian.org/Javascript/Nodejs/Database'
 
 
diff --git a/npm2deb/scripts.py b/npm2deb/scripts.py
index cf2c873..4e6e346 100644
--- a/npm2deb/scripts.py
+++ b/npm2deb/scripts.py
@@ -181,7 +181,7 @@ def print_view(args):
 
 
 def print_itp(args):
-    get_npm2deb_instance(args).show_itp()
+    print(get_npm2deb_instance(args).get_ITP())
 
 
 def print_license(args, prefix=""):
@@ -216,7 +216,7 @@ def show_dependencies(args):
 
     if args.binary:
         if 'dependencies' in json and json['dependencies']:
-            print "Dependencies:"
+            print("Dependencies:")
             helper.print_formatted_dependency("NPM", "Debian")
             module_ver = npm2deb_instance.upstream_version
             module_deb = Mapper.get_instance()\
@@ -233,7 +233,7 @@ def show_dependencies(args):
 
     if args.builddeb:
         if 'devDependencies' in json and json['devDependencies']:
-            print "Build dependencies:"
+            print("Build dependencies:")
             helper.print_formatted_dependency("NPM", "Debian")
             helper.search_for_builddep(npm2deb_instance)
             print("")
@@ -280,7 +280,7 @@ def get_npm2deb_instance(args):
     try:
         return Npm2Deb(args=vars(args))
     except ValueError as value_error:
-        print value_error
+        print(value_error)
         exit(1)
 
 
diff --git a/npm2deb/templates.py b/npm2deb/templates.py
index 1c93a45..42a7ed1 100644
--- a/npm2deb/templates.py
+++ b/npm2deb/templates.py
@@ -66,7 +66,9 @@ License: %(debian_license_name)s
 %(debian_license)s
 """
 
-WNPP = """Subject: ITP: %(debian_name)s -- %(description)s
+WNPP = """To: submit at bugs.debian.org
+Subject: ITP: %(debian_name)s -- %(description)s
+
 Package: wnpp
 Severity: wishlist
 Owner: %(debian_author)s
@@ -256,9 +258,21 @@ LICENSES['Expat'] = """Expat
  SOFTWARE.
 """
 
-WATCH_GITHUB = """version=3
+WATCH = {}
+
+WATCH['github'] = """version=3
 opts=\\
-dversionmangle=s/\?(debian|dfsg|ds|deb)\d*$//,\\
+dversionmangle=%(dversionmangle)s,\\
 filenamemangle=s/.*\/v?([\d\.-]+)\.tar\.gz/%(debian_name)s-$1.tar.gz/ \\
- %(homepage)s/tags .*/archive/v?([\d\.]+).tar.gz
+ %(url)s/tags .*/archive/v?([\d\.]+).tar.gz
+"""
+
+WATCH['fakeupstream'] = """version=3
+# It is not recommended use fakeupstream. Please investigate more.
+# Origin url: %(url)s
+# 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 \\
+ http://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=npmjs/%(module)s .*=%(module)s-(\d.*)\.(?:tgz|tar\.(?:gz|bz2|xz))
 """
diff --git a/npm2deb/utils.py b/npm2deb/utils.py
index bf47f42..d16f9ae 100644
--- a/npm2deb/utils.py
+++ b/npm2deb/utils.py
@@ -35,6 +35,14 @@ def get_template(filename):
         result = templates.WNPP
     return result
 
+def get_watch(which):
+    if which == 'github':
+        return templates.WATCH['github']
+    elif which == 'bitbucket':
+        return templates.WATCH['bitbucket']
+    else:
+        return templates.WATCH['fakeupstream']
+
 
 def get_license(license):
     result = None
diff --git a/tests/npm_coherence.py b/tests/npm_coherence.py
index 6449e09..a3d59d1 100644
--- a/tests/npm_coherence.py
+++ b/tests/npm_coherence.py
@@ -105,5 +105,36 @@ class debian(unittest.TestCase):
         n.create_manpages()
         self.assertEqual(self._get_debfile_line('manpages', 'jade.1'), "jade.1")
 
+    def test_watch_github(self):
+        n = Npm2Deb('serve-static')
+        n.create_base_debian()
+        n.create_watch()
+        line = self._get_debfile_line('watch', '/tags')
+        self.assertTrue(line is not None and len(line) > 0)
+
+    def test_watch_fakeupstream(self):
+        # must create a fakeupstream since we do not know about git url
+        n = Npm2Deb('yg-panache')
+        n.create_base_debian()
+        n.create_watch()
+        line = self._get_debfile_line('watch', '/fakeupstream')
+        self.assertTrue(line is not None and len(line) > 0)
+
+    def test_watch_github_with_no_tags(self):
+        # must fallback on fakeupstream if no tags in github
+        n = Npm2Deb('security')
+        n.create_base_debian()
+        n.create_watch()
+        line = self._get_debfile_line('watch', '/fakeupstream')
+        self.assertTrue(line is not None and len(line) > 0)
+
+    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')
+
+
 if __name__ == '__main__':
     unittest.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