Skip to content
Snippets Groups Projects
Commit a91431dc authored by Louis-Francis Ratté-Boulianne's avatar Louis-Francis Ratté-Boulianne Committed by Sjoerd Simons
Browse files

Add support for bundles in info command


Signed-off-by: default avatarLouis-Francis Ratté-Boulianne <lfrb@collabora.com>

Differential Revision: https://phabricator.apertis.org/D5231
parent 8a3289bd
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ ade-info \- Print information about an entity
.SH SYNOPSIS
.sp
.nf
\fIade info\fR --bundle <bundle>
\fIade info\fR --device [<user>[:<pass>]@]<hostname>[:<port>]
\fIade info\fR --project
\fIade info\fR --sdk
......@@ -25,6 +26,12 @@ Retrieve information about a sysroot or another ADE object\&.
.SH OPTIONS
.sp
.PP
\fI\-\-bundle\fR
.RS 4
Return ID and version of given bundle\&.
.sp
.RE
.PP
\fI\-\-device\fR
.RS 4
Return image version of given device (e.g. user@apertis)\&.
......
......@@ -31,6 +31,7 @@ import urllib
import xdg.BaseDirectory
from contextlib import contextmanager, closing
from gi.repository import GLib, Gio
from urllib.error import URLError
from urllib.parse import urlparse
from urllib.request import urlopen, urlretrieve
......@@ -744,8 +745,10 @@ class Bundle:
bundle = Bundle(path, project.bundle_id, project.version)
with tempfile.TemporaryDirectory() as tmpdir:
builddir = os.path.join(tmpdir, 'build')
bundledir = os.path.join(tmpdir, 'bundle')
repodir = os.path.join(tmpdir, 'repo')
os.makedirs(builddir)
os.makedirs(bundledir)
with open(os.path.join(bundledir, 'metadata'), 'w') as f:
......@@ -753,8 +756,9 @@ class Bundle:
f.write("name={0}\n".format(bundle.id))
f.write("X-Apertis-BundleVersion={0}".format(bundle.version))
os.makedirs(os.path.join(bundledir, 'export'))
os.makedirs(os.path.join(bundledir, 'files'))
project.install(os.path.join(bundledir, 'files'))
project.install(builddir)
shutil.copytree(os.path.join(builddir, 'Application', bundle.id),
os.path.join(bundledir, 'files'))
cmd = ['flatpak', 'build-export', repodir, bundledir]
ret = subprocess.run(cmd)
......@@ -768,6 +772,25 @@ class Bundle:
return bundle
def from_file(path):
bundle_file = Gio.File.new_for_path(path)
m = GLib.MappedFile.new(path, False)
b = m.get_bytes()
m.unref()
varianttype = GLib.VariantType.new('(a{sv}tayay(a{sv}aya(say)sstayay)aya(uayttay)a(yaytt))')
bundle = GLib.Variant.new_from_bytes(varianttype, b, False)
bundle.ref_sink()
metadata = bundle.get_child_value(0).lookup_value('metadata', None).get_string()
parser = configparser.ConfigParser()
parser.read_string(metadata)
return Bundle(path,
parser['Application']['name'],
parser['Application']['X-Apertis-BundleVersion'])
class Ade:
......@@ -787,6 +810,7 @@ class Ade:
self.sysroot = None
self.device = None
self.project = False
self.bundle = None
self.bundle_id = None
......@@ -877,6 +901,11 @@ class Ade:
self.target = Project()
except InvalidProjectError as e:
self.die("Invalid project: {0}".format(e))
elif self.bundle:
try:
self.target = Bundle.from_file(self.bundle)
except InvalidBundleError as e:
self.die("Invalid bundle: {0}".format(e))
else:
self.die("No target (simulator, sysroot or device) specified")
......@@ -1094,6 +1123,12 @@ class Ade:
print("ProjectName:{0}".format(self.target.name))
print("BundleId:{0}".format(self.target.bundle_id))
print("AppVersion:{0}".format(self.target.version))
elif isinstance(target, Bundle):
self.info("* BundleId: {0}".format(self.target.id))
self.info("* Version: {0}".format(self.target.version))
if self.format == 'parseable':
print("BundleId:{0}".format(self.target.id))
print("AppVersion:{0}".format(self.target.version))
def do_configure(self):
target = self.get_target()
......@@ -1171,6 +1206,7 @@ if __name__ == '__main__':
group.add_argument('--sysroot', help="Use sysroot as target (e.g. apertis-16.12-armhf)")
group.add_argument('--device', help="Use device as target (e.g. user:pass@apertis)")
group.add_argument('--project', help="Use current directory project as target", action='store_true')
group.add_argument('--bundle', help="Use bundle file as target")
# Sysroot parser
sysroot_parser = subparsers.add_parser('sysroot', help='Sysroot related commands')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment