Verified Commit e28f8944 authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Rework get_objects_from_file to use pathlib



Signed-off-by: Andrej Shadura's avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent a49f4c29
......@@ -11,7 +11,7 @@ from debian.deb822 import Changes, Dsc
from tempfile import TemporaryDirectory
from pathlib import Path
def _get_objects_from_file(filename):
def get_objects_from_file(filename):
"""
Return a tuple containing (None or a Changes object), a Dsc object,
and the filename of the .dsc file.
......@@ -21,36 +21,30 @@ def _get_objects_from_file(filename):
dscfile = None
try:
f = open(filename)
with open(filename) as f:
if filename.endswith('.changes'):
changes = Changes(f)
if 'source' not in changes['architecture'].split():
raise Exception(filename + ' does not contain source code')
for rec in changes['files']:
if rec['name'].endswith('.dsc'):
dscfile = Path(filename).with_name(rec['name'])
with open(dscfile) as fdsc:
dsc = Dsc(fdsc)
return changes, dsc, dscfile
else:
raise Exception(filename + ' does not list a .dsc file')
elif filename.endswith('.dsc'):
dsc = Dsc(f)
dscfile = filename
return changes, dsc, dscfile
else:
raise Exception(filename + ' is not a .dsc or .changes file')
except IOError:
raise Exception(filename + " couldn't be read")
if filename.endswith('.changes'):
changes = Changes(f)
f.close()
if 'source' not in changes['architecture'].split():
raise Exception(filename + ' does not contain source code')
for rec in changes['files']:
if rec['name'].endswith('.dsc'):
dscfile = os.path.join(os.path.dirname(filename), rec['name'])
f = open(dscfile)
dsc = Dsc(f)
f.close()
break
else:
raise Exception(filename + ' does not list a .dsc file')
elif filename.endswith('.dsc'):
dsc = Dsc(f)
dscfile = filename
else:
raise Exception(filename + ' is not a .dsc or .changes file')
f.close()
return changes, dsc, dscfile
class DPut(object):
def __init__(self, project_name=None, package_name=None, working_dir=None):
self.project_name = project_name
......@@ -114,7 +108,7 @@ def do_dput(self, subcmd, opts, proj_name, dsc_or_changes_file):
with TemporaryDirectory('_oscdput') as working_dir:
# get debian .change object before moving current path to the
# working_dir
changes, dsc, dsc_file = _get_objects_from_file(dsc_or_changes_file)
changes, dsc, dsc_file = get_objects_from_file(dsc_or_changes_file)
package_name = dsc.get("Source")
dput = DPut(proj_name, package_name, working_dir)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment