Skip to content

Commit

Permalink
Improve automation
Browse files Browse the repository at this point in the history
* automating uscan and uupdate

* fixing path name

* automating dpkg-build package too

* trying to make code more readable

* remove extra line got added to 'debian/changelog' during package-build

* fix: running build-package when watch file is wrong

* Removing auto generated files

* fixing fakeupstream watch file issue

* specifying version in uscan

* prevent test_uscan from downloading file

* specifying upstream file version in uupdate
  • Loading branch information
psuhailp authored and shanavas786 committed Nov 10, 2016
1 parent f9c4fc6 commit 0b0b4e3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
83 changes: 78 additions & 5 deletions npm2deb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from shutil import rmtree as _rmtree
from urllib.request import urlopen as _urlopen
from subprocess import getstatusoutput as _getstatusoutput
from subprocess import call as _call
import os as _os
import re as _re
import tarfile
Expand Down Expand Up @@ -37,6 +38,7 @@ def __init__(self, module_name=None, args={}):
self.debian_standards = STANDARDS_VERSION
self.debian_debhelper = DEBHELPER
self.noclean = False
self.upstream_watch = False
if args:
if 'upstream_license' in args and args['upstream_license']:
self.upstream_license = args['upstream_license']
Expand Down Expand Up @@ -86,6 +88,77 @@ def start(self):
utils.change_dir('..')
self.create_itp_bug()

def initiate_build(self ,saved_path):
"""
Try building deb package after creating required files using start().
'uscan', 'uupdate' and 'dpkg-buildpackage' are run if debian/watch is OK.
"""
uscan_info = self.test_uscan()
if uscan_info[0] == 0:
self.run_uscan()
self.run_uupdate()

new_dir = '%s-%s' % (self.debian_name, self.upstream_version)
utils.change_dir('../%s' % new_dir)
self.run_buildpackage()
self.edit_changelog()

debian_path = "%s/%s/debian" % (self.name, new_dir)
print ('\nRemember, your new source directory is %s/%s' % (self.name, new_dir))

else:
debian_path = "%s/%s/debian" % (self.name, self.debian_name)

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

utils.change_dir(saved_path)
_call('/bin/grep --color=auto FIX_ME -r %s/*' % debian_path, shell=True)

if uscan_info[0] != 0:
print ("\nUse uscan to get orig source files. Fix debian/watch and then run\
\n$ uscan --download-current-version\n")

if self.upstream_watch:
print ("""
*** Warning ***\nUsing fakeupstream to download npm dist tarballs, because upstream
git repo is missing tags. Its better to ask upstream to tag their releases
instead of using npm dist tarballs as dist tarballs may contain pre built files
and may not include tests.\n""")

def edit_changelog(self):
"""
To remove extra line '* New upstream release'
from debian/changelog
"""
_call("sed -i '/* New upstream release/d' debian/changelog", shell=True)

def run_buildpackage(self):
print ("\nBuilding the binary package")
_call('dpkg-source -b .', shell=True)
_call('dpkg-buildpackage', shell=True)
# removing auto generated temporary files
_call('debian/rules clean', shell=True)

def run_uupdate(self):
print ('\nCreating debian source package...')
_call('uupdate -b -f --upstream-version %s' % self.upstream_version, shell=True)

def run_uscan(self):
print ('\nDownloading source tarball file using debian/watch file...')
_call('uscan --download-version %s' % self.upstream_version, shell=True)

def test_uscan(self):
info = _getstatusoutput('uscan --watchfile "debian/watch" '
'--package "{}" '
'--upstream-version 0 '
'--download-version {} '
'--no-download'
.format(self.debian_name, self.upstream_version))
return info


def create_itp_bug(self):
utils.debug(1, "creating wnpp bug template")
utils.create_file('%s_itp.mail' % self.debian_name, self.get_ITP())
Expand Down Expand Up @@ -119,14 +192,13 @@ def create_watch(self):

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:
uscan_info = self.test_uscan()

if uscan_info[0] != 0:
raise ValueError

except ValueError:
self.upstream_watch = True
content = utils.get_watch('fakeupstream') % args
utils.create_debian_file('watch', content)

Expand Down Expand Up @@ -350,6 +422,7 @@ def read_package_info(self):
self._get_json_version()
self._get_json_license()


def download(self):
utils.debug(1, "downloading %s tarball from npm registry" % self.name)
info = _getstatusoutput('npm pack "%s"' % self.name)
Expand Down
13 changes: 3 additions & 10 deletions npm2deb/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,13 @@ def create(args):
_utils.create_dir(npm2deb.name)
_utils.change_dir(npm2deb.name)
npm2deb.start()
_utils.change_dir(saved_path)
_utils.change_dir(npm2deb.debian_name)
npm2deb.initiate_build(saved_path)

except OSError as os_error:
print(str(os_error))
exit(1)

debian_path = "%s/%s/debian" % (npm2deb.name, npm2deb.debian_name)

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)
print ("\nUse uscan to get orig source files. Fix debian/watch and then run\
\n$ uscan --download-current-version\n")

_show_mapper_warnings()


Expand Down

0 comments on commit 0b0b4e3

Please sign in to comment.