[Pkg-javascript-commits] [npm2deb] 01/07: New upstream version 0.2.7

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Wed Jun 21 11:02:08 UTC 2017


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository npm2deb.

commit 6543cd688aa327cc62f28341ed87aa833e08e3f9
Author: Pirate Praveen <praveen at debian.org>
Date:   Wed Jun 21 16:16:13 2017 +0530

    New upstream version 0.2.7
---
 .editorconfig                 | 11 ++++++
 etc/bash_completion.d/npm2deb |  1 -
 npm2deb/__init__.py           | 83 +++++++++++++++++--------------------------
 npm2deb/helper.py             | 39 +++++---------------
 npm2deb/mapper.py             | 13 ++++++-
 npm2deb/scripts.py            | 23 ++++++------
 npm2deb/templates.py          | 32 +++++++++++++----
 npm2deb/utils.py              | 75 +++++++++++++++++++++++++++++++++++++-
 8 files changed, 173 insertions(+), 104 deletions(-)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..4b97472
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+root = true
+
+[**]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+
+# 4 space indentation
+[*.py]
+indent_style = space
+indent_size = 4
diff --git a/etc/bash_completion.d/npm2deb b/etc/bash_completion.d/npm2deb
index 62fd346..a66ea40 100644
--- a/etc/bash_completion.d/npm2deb
+++ b/etc/bash_completion.d/npm2deb
@@ -1,4 +1,3 @@
-have npm2deb &&
 _npm2deb()
 {
     local cur prev options
diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index 0ac807b..3f7c187 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -29,7 +29,7 @@ class Npm2Deb(object):
         self.json = None
         self.args = args
         self.homepage = None
-        self.description = None
+        self.upstream_description = None
         self.upstream_author = None
         self.upstream_license = None
         self.upstream_version = None
@@ -115,6 +115,7 @@ You may want fix first these issues:\n""")
 
         utils.change_dir(saved_path)
         _call('/bin/grep --color=auto FIX_ME -r %s/*' % debian_path, shell=True)
+        _call('/bin/grep --color=auto FIX_ME -r -H %s/*_itp.mail' % self.name, shell=True)
 
         if uscan_info[0] != 0:
             print ("\nUse uscan to get orig source files. Fix debian/watch and then run\
@@ -173,9 +174,13 @@ and may not include tests.\n""")
                     _os.remove(filename)
 
     def create_manpages(self):
-        if 'man' in self.json:
-            content = _os.path.normpath(self.json['man'])
-            utils.create_debian_file('manpages', content)
+        if not 'man' in self.json:
+            return
+        mans = self.json['man']
+        if not isinstance(mans, (list, tuple)):
+            mans = [mans]
+        paths = [_os.path.normpath(manpath) for manpath in mans]
+        utils.create_debian_file('manpages', "\n".join(paths))
 
     def create_watch(self):
         args = {}
@@ -226,42 +231,9 @@ and may not include tests.\n""")
 
     def create_install(self):
         content = ''
-        libs = {'package.json'}
-        if _os.path.isdir('bin'):
-            libs.add('bin')
-        if _os.path.isdir('lib'):
-            libs.add('lib')
-
-        # install files from directories field
-        if 'directories' in self.json:
-            directories = self.json['directories']
-            if 'bin' in directories:
-                libs.add(directories['bin'])
-            if 'lib' in directories:
-                libs.add(directories['lib'])
-
-        # install files from files field
-        if 'files' in self.json:
-            files = self.json['files']
-            # npm v1.4 returns string if files field has only one entry
-            if isinstance(files, str):
-                libs.add(files)
-            else:
-                libs = libs.union(files)
-
-        # install main if not in a subpath
-        if 'main' in self.json:
-            main = self.json['main']
-            main = _os.path.normpath(main)
-            if main == 'index':
-                main = 'index.js'
-            if not main.find('/') > 0:
-                libs.add(_os.path.normpath(main))
-        else:
-            if _os.path.exists('index.js'):
-                libs.add('index.js')
-            else:
-                libs.add('*.js')
+        libs = _os.listdir()
+        # remove debian directory
+        libs.remove('debian')
 
         for filename in libs:
             content += "%s %s/\n" % (filename, self.debian_dest)
@@ -295,8 +267,8 @@ and may not include tests.\n""")
                               % self.debian_name
         args['Package'] = self.debian_name
         args['Depends'] = self._get_Depends()
-        args['Description'] = self.description
-        args['Description_Long'] = 'FIX_ME long description'
+        args['Description'] = 'FIX_ME write the Debian package description'
+        args['upstream_description'] = self.upstream_description
         template = utils.get_template('control')
         utils.create_debian_file('control', template % args)
 
@@ -433,11 +405,18 @@ and may not include tests.\n""")
 
         tarball_file = info[1].strip('\n')
         tarball = tarfile.open(tarball_file)
+        # get the root directory name
+        root_dir = tarball.getnames()[0]
+        # extract root directory name if memberfile contains '/'
+        index_of_slash = root_dir.find('/')
+        if index_of_slash != -1:
+            root_dir = root_dir[:index_of_slash]
+
         tarball.extractall()
         tarball.close()
 
         # rename extracted directory
-        _os.rename('package', self.name)
+        _os.rename(root_dir, self.name)
         # remove tarball file
         _os.remove(tarball_file)
 
@@ -451,7 +430,8 @@ and may not include tests.\n""")
         args['debian_name'] = self.debian_name
         args['upstream_author'] = self.upstream_author
         args['homepage'] = self.homepage
-        args['description'] = self.description
+        args['description'] = 'FIX_ME write the Debian package description'
+        args['upstream_description'] = self.upstream_description
         args['version'] = self.upstream_version
         args['license'] = self.upstream_license
         content = utils.get_template('wnpp')
@@ -485,9 +465,9 @@ and may not include tests.\n""")
 
     def _get_json_description(self):
         if 'description' in self.json:
-            self.description = self.json['description']
+            self.upstream_description = self.json['description']
         else:
-            self.description = 'FIX_ME description'
+            self.upstream_description = 'FIX_ME no upstream package description'
 
     def _get_json_author(self):
         if self.upstream_author:
@@ -535,13 +515,14 @@ and may not include tests.\n""")
     def _get_json_homepage(self):
         if self.homepage:
             return
-        result = 'FIX_ME homepage'
+
         if 'homepage' in self.json:
-            result = self.json['homepage']
+            self.homepage = self.json['homepage']
         elif self.upstream_repo_url and not \
-                self.upstream_repo_url.find('FIX_ME') >= 0:
-            result = self.upstream_repo_url
-        self.homepage = result
+             self.upstream_repo_url.find('FIX_ME') >= 0:
+            self.homepage = self.upstream_repo_url
+        else:
+            self.homepage = utils.get_npmjs_homepage(self.name)
 
     def _get_Depends(self):
         depends = ['nodejs']
diff --git a/npm2deb/helper.py b/npm2deb/helper.py
index c51a3a5..86f7e77 100644
--- a/npm2deb/helper.py
+++ b/npm2deb/helper.py
@@ -6,7 +6,7 @@ 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.utils import debug as _debug, debianize_name as _debianize_name
 from npm2deb.mapper import Mapper as _Mapper
 
 
@@ -17,10 +17,12 @@ def my_print(what):
     if DO_PRINT:
         print(what)
 
-
 def search_for_repository(module):
     if isinstance(module, _Npm2Deb):
-        module = module.name
+        module = module.debian_name
+    else:
+        module = 'node-%s' % _debianize_name(module)
+
     repositories = ['collab-maint', 'pkg-javascript']
     formatted = "  {0:40} -- {1}"
     found = False
@@ -50,7 +52,10 @@ def search_for_repository(module):
 
 def search_for_bug(module):
     if isinstance(module, _Npm2Deb):
-        module = module.name
+        module = module.debian_name
+    else:
+        module = 'node-%s' % _debianize_name(module)
+
     my_print('Looking for wnpp bugs:')
     _debug(1, "calling wnpp-check")
     info = _getstatusoutput('wnpp-check %s' % module)
@@ -78,32 +83,6 @@ def search_for_bug(module):
                     continue
         return result
 
-def search_in_new(module):
-    if isinstance(module, _Npm2Deb):
-        module = module.name
-    my_print('Looking for packages in NEW:')
-    _debug(1, "calling new-check")
-    found = False
-    formatted = "  {0:20} {1:>3}"
-    url = "https://api.ftp-master.debian.org/sources_in_suite/new"
-    _debug(1, "opening url %s" % url)
-    data = _urlopen(url).read().decode('utf-8')
-    data = _parseJSON(data)
-    result = []
-    for package in data:
-        name = package['source']
-        version = package['version']
-        if not module in name:
-            continue
-        found = True
-        result.append(package)
-        my_print(formatted.format(package['source'],
-                                  package['version']
-                                 ))
-    if not found:
-        my_print("  None")
-    return result
-
 def search_for_reverse_dependencies(module):
     if isinstance(module, _Npm2Deb):
         module = module.name
diff --git a/npm2deb/mapper.py b/npm2deb/mapper.py
index 8c38728..65eac5f 100644
--- a/npm2deb/mapper.py
+++ b/npm2deb/mapper.py
@@ -2,6 +2,7 @@ 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 fnmatch import fnmatch as _fnmatch
 
 from npm2deb.utils import debug as _debug
 from npm2deb.utils import debianize_name as _debianize_name
@@ -35,10 +36,19 @@ class Mapper(object):
         result['info'] = None
         result['name'] = None
         result['version'] = None
+        result['suite'] = None
         result['repr'] = None
+        db_package = None
 
         if node_module in self.json:
             db_package = self.json[node_module]
+        else:
+            for pattern in self.json.keys():
+                if _fnmatch(node_module, pattern):
+                    db_package = self.json[pattern]
+                    break
+
+        if db_package:
             if 'replace' in db_package:
                 result['name'] = db_package['replace']
             if 'info' in db_package:
@@ -58,7 +68,7 @@ class Mapper(object):
             return result
 
         madison = _getstatusoutput(
-            'rmadison -s sid "%s" | grep source' % result['name'])
+            'rmadison -u debian "%s" | grep source' % result['name'])
 
         if madison[0] != 0:
             result['name'] = None
@@ -68,6 +78,7 @@ class Mapper(object):
         if len(tmp) >= 2:
             result['name'] = tmp[0].strip()
             result['version'] = tmp[1].strip()
+            result['suite'] = tmp[2].strip()
             result['repr'] = '%s (%s)' % (result['name'], result['version'])
 
         return result
diff --git a/npm2deb/scripts.py b/npm2deb/scripts.py
index 9580123..804ff1b 100644
--- a/npm2deb/scripts.py
+++ b/npm2deb/scripts.py
@@ -12,6 +12,8 @@ import npm2deb as _
 
 
 def main(argv=None):
+    # verify utf8 support
+    _utils.verify_python3_env()
     if not argv:
         argv = _sys.argv
     parser = _ArgumentParser(prog='npm2deb')
@@ -100,9 +102,6 @@ def main(argv=None):
         '-d', '--debian', action="store_true",
         default=False, help='search for existing package in debian')
     parser_search.add_argument(
-        '-n', '--new', action="store_true",
-        default=False, help='search for existing package in NEW queue')
-    parser_search.add_argument(
         '-r', '--repository', action="store_true",
         default=False, help='search for existing repository in alioth')
     parser_search.add_argument(
@@ -142,25 +141,22 @@ def main(argv=None):
 def search_for_module(args):
     _helper.DO_PRINT = True
     # enable all by default
-    if not args.bug and not args.debian and not args.repository and not args.new:
+    if not (args.bug or args.debian or args.repository):
         args.bug = True
         args.debian = True
         args.repository = True
-        args.new = True
     node_module = get_npm2deb_instance(args).name
     if args.debian:
-        print("\nLooking for similiar package:")
+        print("\nLooking for similar package:")
         mapper = _Mapper.get_instance()
-        print("  %s" % mapper.get_debian_package(node_module)['repr'])
+        pkg_info = mapper.get_debian_package(node_module)
+        print("  %s (%s)" % (pkg_info['repr'], pkg_info['suite']))
     if args.repository:
         print("")
         _helper.search_for_repository(node_module)
     if args.bug:
         print("")
         _helper.search_for_bug(node_module)
-    if args.new:
-        print("")
-        _helper.search_in_new(node_module)
     print("")
 
     _show_mapper_warnings()
@@ -189,8 +185,9 @@ def print_view(args):
                   getattr(npm2deb_instance, attr_key, None)))
 
         mapper = _Mapper.get_instance()
-        print(formatted.format("Debian:", mapper
-              .get_debian_package(npm2deb_instance.name)['repr']))
+        pkg_info = mapper.get_debian_package(npm2deb_instance.name)
+        print(formatted.format("Debian:",
+                               "%s (%s)" % (pkg_info['repr'], pkg_info['suite'])))
 
         if mapper.has_warnings():
             print("")
@@ -298,7 +295,7 @@ def get_npm2deb_instance(args):
 def _show_mapper_warnings():
     mapper = _Mapper.get_instance()
     if mapper.has_warnings():
-        print("Warnings occured:")
+        print("Warnings occurred:")
         mapper.show_warnings()
         print("")
 
diff --git a/npm2deb/templates.py b/npm2deb/templates.py
index 9bda4ee..239edb7 100644
--- a/npm2deb/templates.py
+++ b/npm2deb/templates.py
@@ -6,6 +6,19 @@ CHANGELOG = """%(debian_name)s (%(version)s-1) UNRELEASED; urgency=low
 
 """
 
+description_template = """ Write the short and long descriptions for the Debian package as
+ explained in the Developer's Reference, §6.2.1 – §6.2.3.
+ .
+ You can start with the short upstream package description,
+ “%(upstream_description)s”.
+ .
+ Be aware that most upstream package descriptions are not written to
+ conform with Debian package guidelines. You need to explain the role
+ of this package for a Debian audience.
+ .
+ Node.js is an event-based server-side JavaScript engine.
+"""
+
 CONTROL = """Source: %(Source)s
 Section: web
 Priority: optional
@@ -26,10 +39,7 @@ Depends:
  ${misc:Depends}
  , %(Depends)s
 Description: %(Description)s
- %(Description_Long)s
- .
- Node.js is an event-based server-side JavaScript engine.
-"""
+""" + description_template
 
 RULES = """#!/usr/bin/make -f
 # -*- makefile -*-
@@ -80,10 +90,18 @@ X-Debbugs-CC: debian-devel at lists.debian.org
   Programming Lang: JavaScript
   Description     : %(description)s
 
- FIX_ME bug long description
+ FIX_ME: This ITP report is not ready for submission, until you are
+ confident this package description is ready for Debian.
  .
- Node.js is an event-based server-side JavaScript engine.
-
+""" + description_template + """
+FIX_ME: Explain why this package is suitable for adding to Debian. Is
+it a dependency of some other package? What benefit does it provide
+compared to other similar packages already in Debian?
+
+FIX_ME: Explain how you intend to consistently maintain this package
+in Debian. If you are not yet a Debian member, does this package need
+a sponsor? Do you have co-maintainers? Are you a member of the Debian
+JavaScript maintainers team?
 """
 
 LICENSES = {}
diff --git a/npm2deb/utils.py b/npm2deb/utils.py
index 6937f13..ba4711a 100644
--- a/npm2deb/utils.py
+++ b/npm2deb/utils.py
@@ -1,5 +1,8 @@
 from subprocess import getstatusoutput as _getstatusoutput
+from subprocess import Popen as _Popen
+from subprocess import PIPE as _PIPE
 import codecs as _codecs
+import locale as _locale
 import os as _os
 
 from npm2deb import templates as _templates
@@ -7,7 +10,6 @@ from npm2deb import templates as _templates
 
 DEBUG_LEVEL = 0
 
-
 def debug(level, msg):
     if level <= DEBUG_LEVEL:
         print(" debug [%s] - %s" % (level, msg))
@@ -110,3 +112,74 @@ def create_dir(dir):
 
 def debianize_name(name):
     return name.replace('_', '-').lower()
+
+def get_npmjs_homepage(name):
+    return 'https://npmjs.com/package/' + name
+
+# taken from https://github.com/pallets/click/blob/master/click/_unicodefun.py
+def verify_python3_env():
+    """Ensures that the environment is good for unicode on Python 3."""
+    try:
+        fs_enc = _codecs.lookup(_locale.getpreferredencoding()).name
+    except Exception:
+        fs_enc = 'ascii'
+    if fs_enc != 'ascii':
+        return
+
+    extra = ''
+    if _os.name == 'posix':
+        rv = _Popen(['locale', '-a'], stdout=_PIPE,
+                    stderr=_PIPE).communicate()[0]
+        good_locales = set()
+        has_c_utf8 = False
+
+        # Make sure we're operating on text here.
+        if isinstance(rv, bytes):
+            rv = rv.decode('ascii', 'replace')
+
+        for line in rv.splitlines():
+            locale = line.strip()
+            if locale.lower().endswith(('.utf-8', '.utf8')):
+                good_locales.add(locale)
+                if locale.lower() in ('c.utf8', 'c.utf-8'):
+                    has_c_utf8 = True
+
+        extra += '\n\n'
+        if not good_locales:
+            extra += (
+                'Additional information: on this system no suitable UTF-8\n'
+                'locales were discovered.  This most likely requires resolving\n'
+                'by reconfiguring the locale system.'
+            )
+        elif has_c_utf8:
+            extra += (
+                'This system supports the C.UTF-8 locale which is recommended.\n'
+                'You might be able to resolve your issue by exporting the\n'
+                'following environment variables:\n\n'
+                '    export LC_ALL=C.UTF-8\n'
+                '    export LANG=C.UTF-8'
+            )
+        else:
+            extra += (
+                'This system lists a couple of UTF-8 supporting locales that\n'
+                'you can pick from.  The following suitable locales were\n'
+                'discovered: %s'
+            ) % ', '.join(sorted(good_locales))
+
+        bad_locale = None
+        for locale in _os.environ.get('LC_ALL'), _os.environ.get('LANG'):
+            if locale and locale.lower().endswith(('.utf-8', '.utf8')):
+                bad_locale = locale
+            if locale is not None:
+                break
+        if bad_locale is not None:
+            extra += (
+                '\n\nnpm2deb discovered that you exported a UTF-8 locale\n'
+                'but the locale system could not pick up from it because\n'
+                'it does not exist.  The exported locale is "%s" but it\n'
+                'is not supported'
+            ) % bad_locale
+
+    raise RuntimeError('npm2deb will abort further execution because Python 3 '
+                       'was configured to use ASCII as encoding for the '
+                       'environment.' + extra)

-- 
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