Unverified Commit b7522f9f authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Reformat the source code according to PEP-8



Signed-off-by: Andrej Shadura's avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent 31b4d60c
......@@ -11,6 +11,7 @@ from debian.deb822 import Changes, Dsc
from tempfile import TemporaryDirectory
from pathlib import Path
def get_objects_from_file(filename):
"""
Return a tuple containing (None or a Changes object), a Dsc object,
......@@ -45,6 +46,7 @@ def get_objects_from_file(filename):
except IOError:
raise Exception(filename + " couldn't be read")
class DPut(object):
def __init__(self, project_name=None, package_name=None, working_dir=None):
self.project_name = project_name
......@@ -84,10 +86,10 @@ class DPut(object):
path.mkdir()
os.chdir(path)
package = osc.core.Package.init_package(conf.config['apiurl'],
project=self.project_name,
package=self.package_name,
dir='.',
meta=True)
project=self.project_name,
package=self.package_name,
dir='.',
meta=True)
package.update()
return package
......@@ -101,113 +103,116 @@ class DPut(object):
"""
return osc.core.meta_get_filelist(conf.config['apiurl'], self.project_name, self.package_name)
@cmdln.option('--maintained-in-git', action='store_true',
help='add MAINTAINED_IN_GIT.txt')
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)
package_name = dsc.get("Source")
dput = DPut(proj_name, package_name, working_dir)
# Filenames in the .dsc are relative to the directory where it appears.
# We need to make it absolute before we chdir elsewhere.
dsc_or_changes_file = os.path.abspath(dsc_or_changes_file)
dsc_file = os.path.abspath(dsc_file)
dscdir = os.path.dirname(dsc_file)
# Get the list of packages
# TODO: Probably it can be done after checking out the project
# So we can save one http request
package_list = osc.core.meta_get_packagelist(conf.config['apiurl'], proj_name)
# Starting the project
project = osc.core.Project.init_project(conf.config['apiurl'],
dir=dput.working_dir / proj_name,
project=proj_name)
# check if the package exists on server, otherwise create one
if package_name not in package_list:
dput._create_package()
# it also changes the current_dir to the package dir
package = dput.get_package_object()
# defining file list, so we can decide which one to delete
remote_file_list = dput.get_remote_file_list(package)
local_file_list = [f["name"] for f in dsc.get("Files")] #local lambda list
# Remove old files, but only those that are part of the Debian package
superseded = set()
retained = set()
downloaded = set()
for f in remote_file_list:
if f.endswith('.dsc'):
u = osc.core.makeurl(conf.config['apiurl'],
['source', proj_name, package_name, f],
query={})
lines = []
remote_dsc = Dsc(osc.core.streamfile(u, bufsize='line'))
for entry in remote_dsc.get('Files'):
superseded.add(entry['name'])
superseded.add(f)
elif f.endswith('.changes'):
superseded.add(f)
else:
retained.add(f)
retained -= superseded
# The temporary checkout we're using doesn't seem to have the
# expected result for latest_rev()?
source_rev = osc.core.get_source_rev(conf.config['apiurl'],
proj_name, package_name)
if 'rev' in source_rev:
latest_revision = source_rev['rev']
for f in retained:
print('retaining non-source file: %r' % f)
# this will undo branch links since _link needs meta=0 when fetching
if not os.path.exists(f) and f != '_link':
print('fetching %r from server' % f)
package.updatefile(f, latest_revision)
downloaded.add(f)
# adding local_file_list to the package as links
for f in local_file_list:
filepath = os.path.join(dscdir, f)
os.symlink(filepath, f)
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)
package_name = dsc.get("Source")
dput = DPut(proj_name, package_name, working_dir)
# Filenames in the .dsc are relative to the directory where it appears.
# We need to make it absolute before we chdir elsewhere.
dsc_or_changes_file = os.path.abspath(dsc_or_changes_file)
dsc_file = os.path.abspath(dsc_file)
dscdir = os.path.dirname(dsc_file)
# Get the list of packages
# TODO: Probably it can be done after checking out the project
# So we can save one http request
package_list = osc.core.meta_get_packagelist(
conf.config['apiurl'], proj_name)
# Starting the project
project = osc.core.Project.init_project(conf.config['apiurl'],
dir=dput.working_dir / proj_name,
project=proj_name)
# check if the package exists on server, otherwise create one
if package_name not in package_list:
dput._create_package()
# it also changes the current_dir to the package dir
package = dput.get_package_object()
# defining file list, so we can decide which one to delete
remote_file_list = dput.get_remote_file_list(package)
local_file_list = [f["name"]
for f in dsc.get("Files")] # local lambda list
# Remove old files, but only those that are part of the Debian package
superseded = set()
retained = set()
downloaded = set()
for f in remote_file_list:
if f.endswith('.dsc'):
u = osc.core.makeurl(conf.config['apiurl'],
['source', proj_name, package_name, f],
query={})
lines = []
remote_dsc = Dsc(osc.core.streamfile(u, bufsize='line'))
for entry in remote_dsc.get('Files'):
superseded.add(entry['name'])
superseded.add(f)
elif f.endswith('.changes'):
superseded.add(f)
else:
retained.add(f)
retained -= superseded
# The temporary checkout we're using doesn't seem to have the
# expected result for latest_rev()?
source_rev = osc.core.get_source_rev(conf.config['apiurl'],
proj_name, package_name)
if 'rev' in source_rev:
latest_revision = source_rev['rev']
for f in retained:
print('retaining non-source file: %r' % f)
# this will undo branch links since _link needs meta=0 when fetching
if not os.path.exists(f) and f != '_link':
print('fetching %r from server' % f)
package.updatefile(f, latest_revision)
downloaded.add(f)
# adding local_file_list to the package as links
for f in local_file_list:
filepath = os.path.join(dscdir, f)
os.symlink(filepath, f)
package.addfile(f)
f = os.path.basename(dsc_file)
os.symlink(dsc_file, f)
package.addfile(f)
f = os.path.basename(dsc_file)
os.symlink(dsc_file, f)
package.addfile(f)
if opts.maintained_in_git and 'MAINTAINED_IN_GIT.txt' not in retained:
open('MAINTAINED_IN_GIT.txt', 'w+').close()
package.addfile('MAINTAINED_IN_GIT.txt')
if opts.maintained_in_git and 'MAINTAINED_IN_GIT.txt' not in retained:
open('MAINTAINED_IN_GIT.txt', 'w+').close()
package.addfile('MAINTAINED_IN_GIT.txt')
# a plain .dsc file has very little metadata, so "hello_2.10-1.dsc"
# is about the best commit message we can provide without unpacking
# the source package
msg = f
# a plain .dsc file has very little metadata, so "hello_2.10-1.dsc"
# is about the best commit message we can provide without unpacking
# the source package
msg = f
for f in downloaded:
package.addfile(f)
for f in downloaded:
package.addfile(f)
if changes is not None:
f = os.path.basename(dsc_or_changes_file)
os.symlink(dsc_or_changes_file, f)
package.addfile(f)
if changes is not None:
f = os.path.basename(dsc_or_changes_file)
os.symlink(dsc_or_changes_file, f)
package.addfile(f)
msg = changes.get('changes', msg)
msg = changes.get('changes', msg)
package.commit(msg=msg)
package.commit(msg=msg)
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