[Pkg-javascript-commits] [tools.pkg-javascript.debian.org] 01/01: added rewrite watch file script - rough, but it works

Leo Iannacone l3on-guest at moszumanska.debian.org
Tue May 13 13:40:06 UTC 2014


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

l3on-guest pushed a commit to branch master
in repository tools.pkg-javascript.debian.org.

commit 4c8bd04c6815c7fd1ece240034f94c01a0bc3e87
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Tue May 13 15:40:01 2014 +0200

    added rewrite watch file script - rough, but it works
---
 rewrite-watch-files.py | 191 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 191 insertions(+)

diff --git a/rewrite-watch-files.py b/rewrite-watch-files.py
new file mode 100755
index 0000000..11a7729
--- /dev/null
+++ b/rewrite-watch-files.py
@@ -0,0 +1,191 @@
+#!/usr/bin/python
+"""
+Usage:
+    python rewrite-watch-fiels [package1, package2, package3]
+
+With no package(s) will get the list from Debian Maintainer Dashboard
+lookgin for 'uscan return an error'.
+
+For each package tries to write an new debian watch according with:
+    https://wiki.debian.org/qa.debian.org/HowToHelpWithFixingWatchFiles
+
+"""
+
+from urllib2 import urlopen
+from commands import getstatusoutput
+from npm2deb import Npm2Deb
+import os
+import sys
+
+DEBUG_LEVEL = 0
+DIR = 'watches'
+ERRORS_DIR = '%s/errors' % DIR
+URL = 'http://udd.debian.org/dmd/' + \
+      '?email1=pkg-javascript-devel%40lists.alioth.debian.org'
+
+
+WATCH_GITHUB = """version=3
+opts=\\
+dversionmangle=s/\?(debian|dfsg|ds|deb)\d*$//,\\
+filenamemangle=s/.*\/v?([\d\.-]+)\.tar\.gz/%(debian_name)s-$1.tar.gz/ \\
+ %(homepage)s/tags .*/archive/v?([\d\.]+).tar.gz
+"""
+
+WATCH_FAKEUPSTREAM = """version=3
+http://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=npmjs/%(module)s .*=%(module)s-(\d.*)\.(?:tgz|tar\.(?:gz|bz2|xz))
+"""
+
+
+def debug(level, msg):
+    if level <= DEBUG_LEVEL:
+        sys.stderr.write(" debug[%s] - %s\n" % (level, msg))
+
+
+def get_cmd_output(command):
+    debug(3, 'exec command: "%s"' % command)
+    info = getstatusoutput(command)
+    if info[0] != 0:
+        raise Exception(info[1])
+    return info[1]
+
+
+def test_watch_file(filename, package):
+    return get_cmd_output('uscan --watchfile "{}" --package "{}" '
+                          '--upstream-version 0 --no-download'
+                          .format(filename, package))
+
+
+def get_npm2deb(package):
+    npm2deb = None
+    # try getting homepage from npm2deb
+    try:
+        if not package.startswith('node-'):
+            raise
+        module = package.replace('node-', '')
+        debug(2, "package %s - trying module %s" %
+                 (package, module))
+        npm2deb = Npm2Deb(module)
+    except:
+        try:
+            module = package
+            debug(2, "package %s - trying module %s" %
+                     (package, module))
+            npm2deb = Npm2Deb(module)
+        except:
+            try:
+                if not module.find('.js') >= 0:
+                    raise
+                module = module.replace('.js', '')
+                debug(2, "package %s - trying module %s" %
+                         (package, module))
+                npm2deb = Npm2Deb(module)
+            except:
+                raise Exception("npm2deb error: no module found")
+    finally:
+        if not npm2deb or npm2deb.upstream_repo_url.find('FIX_ME') >= 0:
+            raise Exception("npm2deb error: upstream url")
+        return npm2deb
+
+
+def main(packages=[]):
+    if os.path.exists(DIR):
+        print('Directory "%s" already exists. Exit.' % DIR)
+        exit(1)
+
+    if os.path.exists(ERRORS_DIR):
+        print('Directory "%s" already exists. Exit.' % DIR)
+        exit(1)
+
+    os.makedirs(DIR)
+    os.makedirs(ERRORS_DIR)
+
+    if len(packages) == 0:
+        print("Reading page from %s" % URL)
+        data = urlopen(URL).read()
+        data = data.decode('utf-8').split('<table')[3].split('<tr')
+        for row in data:
+            if row.find('uscan returned an error') >= 0:
+                package = row.split('<td')[1].split('>')[2].split('<')[0]
+                packages.append(package)
+        print("Found %s watch errors" % len(packages))
+
+    watches = []
+    watches_errors = []
+    for package in packages:
+        homepage = None
+        module = None
+        npm2deb = None
+        try:
+            info = get_cmd_output('apt-cache madison "%s" '
+                                  '| grep Sources' % package)
+            version = info.split('|')[1].strip()
+            # trim epoch
+            if version.find(':') > 0:
+                version = version.split(':')[1]
+
+            debug(1, "investigating %s (%s)" % (package, version))
+            try:
+                info = get_cmd_output('apt-cache showsrc "%s" '
+                                      '| grep Homepage' % package)
+                homepage = info.split('Homepage:')[1].strip()
+                if homepage.find("github") < 0:
+                    raise
+            except:
+                npm2deb = get_npm2deb(package)
+                homepage = npm2deb.upstream_repo_url
+                module = npm2deb.name
+
+            debug(1, "package %s - found homepage %s" % (package, homepage))
+            args = {}
+            args['homepage'] = homepage
+            args['debian_name'] = package
+            args['module'] = module
+            watch_content = WATCH_GITHUB % args
+
+            filename = "%s/%s_%s.watch" % (DIR, package, version)
+            with open(filename, 'w') as fd:
+                debug(2, "writing github %s" % filename)
+                fd.write(watch_content)
+
+            # testing new watch
+            try:
+                test_watch_file(filename, package)
+            except:
+                try:
+                    if not npm2deb:
+                        npm2deb = get_npm2deb(package)
+                        if not npm2deb:
+                            raise
+                    # fakeupstream
+                    args['module'] = npm2deb.name
+                    watch_content = WATCH_FAKEUPSTREAM % args
+                    with open(filename, 'w') as fd:
+                        debug(2, "writing fakeroot %s" % filename)
+                        fd.write(watch_content)
+                    test_watch_file(filename, package)
+                except:
+                    tmp_filename = "%s/%s" % (ERRORS_DIR,
+                                              filename.split('/').pop())
+                    try:
+                        os.rename(filename, tmp_filename)
+                    except:
+                            raise Exception("watch test reports errors")
+                    raise Exception("watch test reports errors - "
+                                    "saving a copy %s" % tmp_filename)
+
+            watches.append(package)
+
+        except Exception as ex:
+            error = str(ex)
+            print("Error with %s - %s" % (package, error))
+            watches_errors.append(package)
+            continue
+
+    print("Fixed %s watch files. Error with %s packages" %
+          (len(watches), len(watches_errors)))
+
+if __name__ == '__main__':
+    if len(sys.argv) > 1:
+        main(sys.argv[1:])
+    else:
+        main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/tools.pkg-javascript.debian.org.git



More information about the Pkg-javascript-commits mailing list