1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-02 13:29:49 +00:00

package_deb: Clean up pointless exception handling

The exception handling in this function seemed mildly crazy. Python will
given perfectly good or in several cases better information if we let its
standard traceback/exception handling happen. Remove the pointless code
along with the duplicated key checking which was broken in the inner loop
by usage of the wrong variable.

(From OE-Core rev: f755b07b528e828618141eda402399d791efba4a)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2017-01-21 14:08:07 +00:00
parent 53a3c58774
commit fdb52ade90
+25 -46
View File
@@ -53,6 +53,7 @@ python do_package_deb () {
import textwrap import textwrap
import subprocess import subprocess
import collections import collections
import codecs
oldcwd = os.getcwd() oldcwd = os.getcwd()
@@ -121,12 +122,8 @@ python do_package_deb () {
controldir = os.path.join(root, 'DEBIAN') controldir = os.path.join(root, 'DEBIAN')
bb.utils.mkdirhier(controldir) bb.utils.mkdirhier(controldir)
os.chmod(controldir, 0o755) os.chmod(controldir, 0o755)
try:
import codecs ctrlfile = codecs.open(os.path.join(controldir, 'control'), 'w', 'utf-8')
ctrlfile = codecs.open(os.path.join(controldir, 'control'), 'w', 'utf-8')
except OSError:
bb.utils.unlockfile(lf)
bb.fatal("unable to open control file for writing")
fields = [] fields = []
pe = d.getVar('PKGE') pe = d.getVar('PKGE')
@@ -153,7 +150,7 @@ python do_package_deb () {
for i in l: for i in l:
data = d.getVar(i) data = d.getVar(i)
if data is None: if data is None:
raise KeyError(f) raise KeyError(i)
if i == 'DPKG_ARCH' and d.getVar('PACKAGE_ARCH') == 'all': if i == 'DPKG_ARCH' and d.getVar('PACKAGE_ARCH') == 'all':
data = 'all' data = 'all'
elif i == 'PACKAGE_ARCH' or i == 'DPKG_ARCH': elif i == 'PACKAGE_ARCH' or i == 'DPKG_ARCH':
@@ -168,36 +165,26 @@ python do_package_deb () {
if d.getVar('PACKAGE_ARCH') == "all": if d.getVar('PACKAGE_ARCH') == "all":
ctrlfile.write("Multi-Arch: foreign\n") ctrlfile.write("Multi-Arch: foreign\n")
# check for required fields # check for required fields
try: for (c, fs) in fields:
for (c, fs) in fields: # Special behavior for description...
for f in fs: if 'DESCRIPTION' in fs:
if localdata.getVar(f, False) is None: summary = localdata.getVar('SUMMARY') or localdata.getVar('DESCRIPTION') or "."
raise KeyError(f) ctrlfile.write('Description: %s\n' % summary)
# Special behavior for description... description = localdata.getVar('DESCRIPTION') or "."
if 'DESCRIPTION' in fs: description = textwrap.dedent(description).strip()
summary = localdata.getVar('SUMMARY') or localdata.getVar('DESCRIPTION') or "." if '\\n' in description:
ctrlfile.write('Description: %s\n' % summary) # Manually indent
description = localdata.getVar('DESCRIPTION') or "." for t in description.split('\\n'):
description = textwrap.dedent(description).strip() # We don't limit the width when manually indent, but we do
if '\\n' in description: # need the textwrap.fill() to set the initial_indent and
# Manually indent # subsequent_indent, so set a large width
for t in description.split('\\n'): ctrlfile.write('%s\n' % textwrap.fill(t, width=100000, initial_indent=' ', subsequent_indent=' '))
# We don't limit the width when manually indent, but we do else:
# need the textwrap.fill() to set the initial_indent and # Auto indent
# subsequent_indent, so set a large width ctrlfile.write('%s\n' % textwrap.fill(description.strip(), width=74, initial_indent=' ', subsequent_indent=' '))
ctrlfile.write('%s\n' % textwrap.fill(t, width=100000, initial_indent=' ', subsequent_indent=' '))
else:
# Auto indent
ctrlfile.write('%s\n' % textwrap.fill(description.strip(), width=74, initial_indent=' ', subsequent_indent=' '))
else: else:
ctrlfile.write(c % tuple(pullData(fs, localdata))) ctrlfile.write(c % tuple(pullData(fs, localdata)))
except KeyError:
import sys
(type, value, traceback) = sys.exc_info()
bb.utils.unlockfile(lf)
ctrlfile.close()
bb.fatal("Missing field for deb generation: %s" % value)
# more fields # more fields
@@ -273,11 +260,7 @@ python do_package_deb () {
if not scriptvar: if not scriptvar:
continue continue
scriptvar = scriptvar.strip() scriptvar = scriptvar.strip()
try: scriptfile = open(os.path.join(controldir, script), 'w')
scriptfile = open(os.path.join(controldir, script), 'w')
except OSError:
bb.utils.unlockfile(lf)
bb.fatal("unable to open %s script file for writing" % script)
if scriptvar.startswith("#!"): if scriptvar.startswith("#!"):
pos = scriptvar.find("\n") + 1 pos = scriptvar.find("\n") + 1
@@ -297,11 +280,7 @@ python do_package_deb () {
conffiles_str = ' '.join(get_conffiles(pkg, d)) conffiles_str = ' '.join(get_conffiles(pkg, d))
if conffiles_str: if conffiles_str:
try: conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
except OSError:
bb.utils.unlockfile(lf)
bb.fatal("unable to open conffiles for writing")
for f in conffiles_str.split(): for f in conffiles_str.split():
if os.path.exists(oe.path.join(root, f)): if os.path.exists(oe.path.join(root, f)):
conffiles.write('%s\n' % f) conffiles.write('%s\n' % f)