Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.

port packaging-helper.py to python3, partially addresses #936612 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Uploaders: Bernd Zeimetz <bzed@debian.org>
Build-Depends: autotools-dev, quilt, libgimp2.0-dev, intltool,
python, automake, autoconf, autotools-dev, dh-autoreconf,
libxml-parser-perl, liblqr-1-0-dev, automake (>= 1.6), autoconf (>= 2.54), liblcms2-dev, libtiff-dev, debhelper (>= 8.0.0), libglib2.0-dev,
python-debian
python3, python3-debian
Standards-Version: 3.9.5
Vcs-Git: https://github.com/bzed/gimp-plugin-registry.git
Vcs-Browser: https://github.com/bzed/gimp-plugin-registry
Expand Down
2 changes: 1 addition & 1 deletion debian/control.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Uploaders: #AUTO_UPDATE_Uploaders#
Build-Depends: autotools-dev, quilt, libgimp2.0-dev, intltool,
python, automake, autoconf, autotools-dev, dh-autoreconf,
#AUTO_UPDATE_Build-Depends#, debhelper (>= 8.0.0), libglib2.0-dev,
python-debian
python3, python3-debian
Standards-Version: 3.9.5
Vcs-Git: https://github.com/bzed/gimp-plugin-registry.git
Vcs-Browser: https://github.com/bzed/gimp-plugin-registry
Expand Down
64 changes: 32 additions & 32 deletions debian/packaging-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __get_control_data__():
# returns (plug, parsed control field data)
# We look at the first paragraph only!
for plugin in __plugins__:
data=(plugin, [x for x in deb822.Packages.iter_paragraphs(file(__basedir__ + os.path.sep+ plugin + os.path.sep + 'control'))][0])
for key in data[1].iterkeys():
data=(plugin, [x for x in deb822.Packages.iter_paragraphs(open(__basedir__ + os.path.sep+ plugin + os.path.sep + 'control'))][0])
for key in data[1].keys():
if key not in ALLOWED_FIELDS:
raise Exception("Unknown control field in plugin %s: %s" %(data[0],key))
yield data
Expand All @@ -44,7 +44,7 @@ def generate_debian_readme_plugins():
plugins_depends[plugin]={}
# look trough keys we might want to merge
for key in ['Suggests', 'Recommends']:
if _control.has_key(key):
if key in _control:
plugins_depends[plugin][key]=deb822.PkgRelation.parse_relations(_control[key])

# check for generated substvars files
Expand All @@ -54,7 +54,7 @@ def generate_debian_readme_plugins():
substvars = fd.read()
try:
rel = deb822.PkgRelation.parse_relations(__shlibs_re__.findall(substvars)[0])
if plugins_depends[plugin].has_key('Recommends'):
if 'Recommends' in plugins_depends[plugin]:
plugins_depends[plugin]['Recommends'].extend(rel)
else:
plugins_depends[plugin]['Recommends']=rel
Expand All @@ -66,12 +66,12 @@ def generate_debian_readme_plugins():
for plugin in __plugins__:
if len(plugins_depends[plugin]) > 0:
rtext = '%s:' %(plugin,)
if plugins_depends[plugin].has_key('Recommends'):
if 'Recommends' in plugins_depends[plugin]:
rtext = '%s\n Required Packages: %s' %(
rtext,
deb822.PkgRelation.str(plugins_depends[plugin]['Recommends'])
)
if plugins_depends[plugin].has_key('Suggests'):
if 'Suggests' in plugins_depends[plugin]:
rtext = '%s\n Optional Packages: %s' %(
rtext,
deb822.PkgRelation.str(plugins_depends[plugin]['Suggests'])
Expand Down Expand Up @@ -104,18 +104,18 @@ def update_control():
# print "Don't use 'Depends' in %s/control - use 'Recommends' instead" %(plugin,)
# sys.exit(1)
for key in ['Build-Depends', 'Depends', 'Suggests', 'Recommends']:
if _control.has_key(key):
if key in _control:
for rel in deb822.PkgRelation.parse_relations(_control[key]):
if not rel in control_data[key]:
control_data[key].append(rel)
# extract description
description = ' * %s' %(plugin,)
if _control.has_key('Version'):
if 'Version' in _control:
description = '%s (%s)' %(description, _control['Version'])
try:
description = '%s: %s' %(description, _control['Description'].replace('\n','\n '))
except KeyError:
print 'Description for plugin %s missing!' %(plugin,)
print('Description for plugin %s missing!' %(plugin,))
sys.exit(1)

try:
Expand All @@ -135,11 +135,11 @@ def update_control():
with open(__basedir__ + os.path.sep + 'debian' + os.path.sep + 'control.in', 'r') as f:
control_in = f.read()

for k, v in control_data.iteritems():
for k, v in control_data.items():
if k == 'Description':
control_in = control_in.replace('#AUTO_UPDATE_Description#', u'\n'.join(v))
control_in = control_in.replace('#AUTO_UPDATE_Description#', '\n'.join(v))
elif k == 'Uploaders':
control_in = control_in.replace('#AUTO_UPDATE_Uploaders#', u', '.join(v))
control_in = control_in.replace('#AUTO_UPDATE_Uploaders#', ', '.join(v))
else:
control_in = control_in.replace('#AUTO_UPDATE_%s#' %(k, ), deb822.PkgRelation.str(v))

Expand All @@ -154,25 +154,25 @@ def update_copyright():
copyrights = []
for plugin, _control in __get_control_data__():
_p_copyright = '%s:\n\n' %(plugin,)
if _control.has_key('Homepage'):
if 'Homepage' in _control:
_p_copyright = '%sThe plugin was downloaded from: \n%s\n\n' %(_p_copyright, _control['Homepage'])

try:
with open(__basedir__ + os.path.sep + plugin + os.path.sep + 'copyright', 'r') as f:
_p_copyright = '%s %s' %(_p_copyright, f.read().decode('utf-8').replace('\n','\n '))
_p_copyright = '%s %s' %(_p_copyright, f.read().replace('\n','\n '))
except IOError:
print 'copyright file for plugin %s missing!' %(plugin,)
print('copyright file for plugin %s missing!' %(plugin,))
sys.exit(1)

copyrights.append(_p_copyright)

with open(__basedir__ + os.path.sep + 'debian' + os.path.sep + 'copyright.in', 'r') as f:
copyright_in = f.read().decode('utf-8')
copyright_in = f.read()

copyright_in = copyright_in.replace('#AUTO_UPDATE_Copyright#', u'\n\n------------------------------------------------------------------------------\n\n'.join(copyrights))
copyright_in = copyright_in.replace('#AUTO_UPDATE_Copyright#', '\n\n------------------------------------------------------------------------------\n\n'.join(copyrights))

with open(__basedir__ + os.path.sep + 'debian' + os.path.sep + 'copyright', 'w') as f:
f.write(copyright_in.encode('utf-8'))
f.write(copyright_in)


def watch():
Expand All @@ -182,39 +182,39 @@ def watch():

import hashlib

import urllib2
url_opener = urllib2.build_opener()
import urllib.request, urllib.error, urllib.parse
url_opener = urllib.request.build_opener()
url_opener.addheaders = [('User-agent', 'Debian nagios-plugins-contrib 1.0')]

watch_re = re.compile(r'([^ ]+) (.+)')
whitespace_re = re.compile(r'\s')
for plugin, _control in __get_control_data__():
if not _control.has_key('Watch'):
print 'WARNING: %s - missing watch information!' %(plugin,)
if 'Watch' not in _control:
print('WARNING: %s - missing watch information!' %(plugin,))
continue
try:
url, check = watch_re.findall(_control['Watch'])[0]
except IndexError:
print 'WARNING: %s - failed to parse Watch line!' %(plugin,)
print('WARNING: %s - failed to parse Watch line!' %(plugin,))
continue
try:
f=url_opener.open(url)
content = f.read()
f.close()
except IOError:
print 'WARNING: %s - failed to retrieve %s !' %(plugin,url)
print('WARNING: %s - failed to retrieve %s !' %(plugin,url))
continue
check=check.strip()
if check.startswith('SHA1:'):
check=check.replace('SHA1:','')
new_sha=hashlib.sha1(content).hexdigest()
if check != new_sha:
print 'UPDATE NECESSARY: %s - SHA1 checksum does not match! New checksum: %s' %(plugin,new_sha)
print('UPDATE NECESSARY: %s - SHA1 checksum does not match! New checksum: %s' %(plugin,new_sha))
else:
print 'OK: %s' %(plugin,)
print('OK: %s' %(plugin,))
else:
if not _control.has_key('Version'):
print 'WARNING: %s - missing current version information!' %(plugin,)
if 'Version' not in _control:
print('WARNING: %s - missing current version information!' %(plugin,))
continue
check_re=re.compile(check)
# check for simple matches
Expand All @@ -225,19 +225,19 @@ def watch():
if not v in found_versions:
found_versions.append(v)
if not found_versions:
print "WARNING: %s - regex does not match!" %(plugin)
print("WARNING: %s - regex does not match!" %(plugin))
continue

new_version = found_versions[0]
for v in found_versions:
if (apt_pkg.version_compare(v, found_versions[0]) > 0):
new_version = v
if (apt_pkg.version_compare(new_version, _control['Version'].strip()) > 0):
print 'UPDATE NECESSARY: %s - found new version %s' %(plugin, new_version)
print('UPDATE NECESSARY: %s - found new version %s' %(plugin, new_version))
elif (apt_pkg.version_compare(new_version, _control['Version'].strip()) < 0):
print 'WARNING: %s - could not find the current version (found: %s, control says: %s)!' %(plugin, new_version, _control['Version'])
print('WARNING: %s - could not find the current version (found: %s, control says: %s)!' %(plugin, new_version, _control['Version']))
else:
print 'OK: %s' %(plugin,)
print('OK: %s' %(plugin,))



Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DH_AUTO_CALL = if [ "$$auto_command" = "dh_auto_configure" ]; then \
echo failed to build $$plugin; exit 255 ; \
fi

PACKAGING_HELPER = /usr/bin/python $(CURDIR)/debian/packaging-helper.py
PACKAGING_HELPER = /usr/bin/python3 $(CURDIR)/debian/packaging-helper.py


clean: $(PLUGINS:%=clean-%) debian/copyright debian/control
Expand Down