[elbe-devel] [PATCH 3/3] Upload Debian packages into project Debian repository
Philipp Arras
philipp.arras at linutronix.de
Mon May 8 18:18:17 CEST 2017
`elbe prjrepo upload <build_dir> <deb/dsc file>` loads the Debain package
into the project's repository and runs the necessary Debian functions
to integrate the package correctly.
You can upload both .deb and .dsc packages. When uploading sources, elbe
expects the requiered source tarballs (see `Files:`section in .dsc file) in
the same directory as the .dsc file.
Signed-off-by: Philipp Arras <philipp.arras at linutronix.de>
---
elbepack/daemons/soap/esoap.py | 7 ++++
elbepack/projectmanager.py | 13 +++++++
elbepack/soapclient.py | 85 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+)
diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
index 995f08b..2e45cf0 100644
--- a/elbepack/daemons/soap/esoap.py
+++ b/elbepack/daemons/soap/esoap.py
@@ -336,3 +336,10 @@ class ESoap (ServiceBase):
self.app.pm.open_project (uid, builddir)
with tarfile.open(os.path.join(builddir, filename), "w:gz") as tar:
tar.add(os.path.join(builddir, "repo"), arcname=os.path.basename(os.path.join(builddir, "repo")))
+
+ @rpc (String, String)
+ @authenticated_uid
+ @soap_faults
+ def include_package (self, uid, builddir, filename):
+ self.app.pm.open_project (uid, builddir)
+ self.app.pm.add_deb_package(uid, filename)
diff --git a/elbepack/projectmanager.py b/elbepack/projectmanager.py
index 6e6dcc1..90cab8c 100644
--- a/elbepack/projectmanager.py
+++ b/elbepack/projectmanager.py
@@ -482,6 +482,19 @@ class ProjectManager(object):
with open (os.path.join (ep.builddir, 'log.txt'), 'w', 0):
pass
+ def add_deb_package(self, userid, filename):
+ ep = self._get_current_project( userid )
+
+ t = filename[-3:] # filetype of uploaded file
+
+ if t == 'dsc':
+ ep.repo.includedsc(os.path.join( ep.builddir, filename))
+ elif t == 'deb':
+ ep.repo.includedeb(os.path.join( ep.builddir, filename))
+
+ ep.repo.finalize()
+
+
def current_project_has_changes (self, userid):
with self.lock:
builddir = self._get_current_project( userid ).builddir
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 437bf00..4f0f63d 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -30,6 +30,7 @@ import sys
import os
from datetime import datetime
+import deb822 # package for dealing with Debian related data
from elbepack.filesystem import Filesystem
from elbepack.elbexml import ElbeXML, ValidationMode
@@ -654,3 +655,87 @@ class DownloadAction(RepoAction):
RepoAction.register(DownloadAction)
+
+
+class UploadPackageAction(RepoAction):
+
+ tag = 'upload_pkg'
+
+ def __init__(self, node):
+ RepoAction.__init__(self, node)
+
+ def upload_file(self, client, f, builddir):
+ # Uploads file f into builddir in intivm
+ size = 1024 * 1024
+ part = 0
+ with file (f, "r") as fp:
+ while (True):
+ xml_base64 = binascii.b2a_base64(fp.read (size))
+ # finish upload
+ if len (xml_base64) == 1:
+ part = client.service.upload_file (builddir,
+ f,
+ xml_base64,
+ -1)
+ else:
+ part = client.service.upload_file (builddir,
+ f,
+ xml_base64,
+ part)
+ if part == -1:
+ print ("project busy, upload not allowed")
+ return -1
+ if part == -2:
+ print ("Upload of package finished.")
+ break
+
+ def execute(self, client, opt, args):
+ if len (args) != 2:
+ print ("usage: elbe prjrepo upload_pkg <project_dir> <deb/dsc file>", file=sys.stderr)
+ sys.exit(20)
+
+ builddir = args[0]
+ filename = args[1]
+
+ print("\n--------------------------")
+ print("Upload and Include Package")
+ print("--------------------------")
+ print("Check files...")
+
+ # Check filetype
+ if filename[-3:] not in ['dsc','deb']:
+ print ("Error: Only .dsc and .deb files allowed to upload.")
+ else:
+ filetype = filename[-4:]
+
+ files = [filename] # list of all files which will be uploaded
+
+ # Parse .dsc-File and append neccessary source files to files
+ if filetype == '.dsc':
+ for f in deb822.Dsc(file(filename))['Files']:
+ files.append(f['name'])
+
+ # Check whether all files are available
+ abort = False
+ for f in files:
+ if not os.path.isfile(f):
+ print("File %s not found." % f)
+ abort = True
+ # Abort if one or more source files are missing
+ if abort: sys.exit(20)
+
+ print ("Start uploading file(s)...")
+ for f in files:
+ print("Upload %s..." % f)
+ self.upload_file(client, f, builddir)
+
+ print ("Including Package in initvm...")
+ client.service.include_package(builddir, filename)
+
+
+ print("Cleaning initvm builddir...")
+ for f in files:
+ client.service.rm (builddir, f)
+
+
+RepoAction.register(UploadPackageAction)
--
2.1.4
More information about the elbe-devel
mailing list