Merge lp:~popey/ubuntu-filemanager-app/add-click-deps into lp:ubuntu-filemanager-app

Status: Merged
Approved by: Alan Pope 🍺🐧🐱 πŸ¦„
Approved revision: 469
Merged at revision: 481
Proposed branch: lp:~popey/ubuntu-filemanager-app/add-click-deps
Merge into: lp:ubuntu-filemanager-app
Diff against target: 538 lines (+518/-0)
3 files modified
CMakeLists.txt (+17/-0)
filemanager-libs.json (+50/-0)
get-click-deps (+451/-0)
To merge this branch: bzr merge lp:~popey/ubuntu-filemanager-app/add-click-deps
Reviewer Review Type Date Requested Status
Carlos Jose Mazieri Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+270287@code.launchpad.net

Commit message

Add basics to cmake file and necessary parts to pull in samba libs.

Description of the change

First pass at adding get-click-deps from Stefano Verzegnassi to pull samba libs in during build process. Not final.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
467. By Alan Pope 🍺🐧🐱 πŸ¦„

New get-click-deps from Stefano and updated deployment process

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Ok, built a click based on this merge, which builds successfully, and bundles in all the samba libs.
http://people.canonical.com/~alan/filemanager/com.ubuntu.filemanager_0.4.467_armhf.click

Tried goto -> smb://nas.local or some other local IP which serves up over SMB and it failed. Here's a log extract:- http://paste.ubuntu.com/12307671/

Pretty sure this worked when I manually put all the samba libs in an already installed file manager build from the past. Am I doing something wrong? (probably)

Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Feel like I'm having the same issue with loviewer dependencies (libraries not found by the application).

May the links to the shared libraries, provided in the click package, be somehow broken? (probably when cp'ing files from temp folder to their destination)

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

> Ok, built a click based on this merge, which builds successfully, and bundles
> in all the samba libs.
> http://people.canonical.com/~alan/filemanager/com.ubuntu.filemanager_0.4.467_a
> rmhf.click
>
> Tried goto -> smb://nas.local or some other local IP which serves up over SMB
> and it failed. Here's a log extract:- http://paste.ubuntu.com/12307671/
>
> Pretty sure this worked when I manually put all the samba libs in an already
> installed file manager build from the past. Am I doing something wrong?
> (probably)

Try "unlock full access" first, it blocks remote browsing.
Next MPs will correct this as we discussed on File Manager meeting.

Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

@stefano, I think it must be finding the libs, because the app crashes (won't even start) if the libs aren't there, or are in the wrong directory usually.

@carlos, yes, I tried that, but it still wouldn't connect. Will try on a different device as this one has lots of other things installed which may compromise it.

Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Just tried this click on my "retail" bq e4.5 (so it's still read only - not had any debian packages installed - is as a customer would find it). Not able to browse to my NAS.

http://termbin.com/vdt4

Is there a "known good" config that this should connect to?

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Looking at the log you posted, it looks like there is an extra space
after "smb":
void DirModel::setPath(const QString&, const QString&, const QString&,
bool) DirModel_QML_137(0x12ff010) path or url may not exist or cannot
be read: "smb ://192.168.1.3/"

The correct url must be "smb://192.168.1.3".

BTW, I have had some hard time trying to type "smb" urls on the device.

On 9/8/15, Alan Pope ξƒΏ <email address hidden> wrote:
> Just tried this click on my "retail" bq e4.5 (so it's still read only - not
> had any debian packages installed - is as a customer would find it). Not
> able to browse to my NAS.
>
> http://termbin.com/vdt4
>
> Is there a "known good" config that this should connect to?
> --
> https://code.launchpad.net/~popey/ubuntu-filemanager-app/add-click-deps/+merge/270287
> Your team Ubuntu File Manager Developers is requested to review the proposed
> merge of lp:~popey/ubuntu-filemanager-app/add-click-deps into
> lp:ubuntu-filemanager-app.
>

Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Well spotted. We should disable the keyboard helpers (which try to autocorrect when you type in a location) and that will stop the space getting added, and also stop smb being 'corrected' to sob.

I tried again and this time the file manager crashes.

http://termbin.com/d8x0

The crash dump was uploaded, and processed. It's a secured page so I printed it as a PDF, I hope that's readable.

http://people.canonical.com/~alan/filemanager_crash.pdf

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

It is hard to say something about the crash, if you have the
'libsmbclient' installed in your phone you can try this click package
which contains 'Network' in Places to start navigating in Samba.
https://www.dropbox.com/s/f6gxiqbav3th8bx/com.ubuntu.filemanager_0.4.latest_armhf.click?dl=0

Have you tested on Desktop?

On 9/8/15, Alan Pope ξƒΏ <email address hidden> wrote:
> Well spotted. We should disable the keyboard helpers (which try to
> autocorrect when you type in a location) and that will stop the space
> getting added, and also stop smb being 'corrected' to sob.
>
> I tried again and this time the file manager crashes.
>
> http://termbin.com/d8x0
>
> The crash dump was uploaded, and processed. It's a secured page so I printed
> it as a PDF, I hope that's readable.
>
> http://people.canonical.com/~alan/filemanager_crash.pdf
> --
> https://code.launchpad.net/~popey/ubuntu-filemanager-app/add-click-deps/+merge/270287
> Your team Ubuntu File Manager Developers is requested to review the proposed
> merge of lp:~popey/ubuntu-filemanager-app/add-click-deps into
> lp:ubuntu-filemanager-app.
>

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

> It is hard to say something about the crash, if you have the
> 'libsmbclient' installed in your phone you can try this click package
> which contains 'Network' in Places to start navigating in Samba.
> https://www.dropbox.com/s/f6gxiqbav3th8bx/com.ubuntu.filemanager_0.4.latest_ar
> mhf.click?dl=0
>
> Have you tested on Desktop?
>
> On 9/8/15, Alan Pope ξƒΏ <email address hidden> wrote:
> > Well spotted. We should disable the keyboard helpers (which try to
> > autocorrect when you type in a location) and that will stop the space
> > getting added, and also stop smb being 'corrected' to sob.
> >
> > I tried again and this time the file manager crashes.
> >
> > http://termbin.com/d8x0
> >
> > The crash dump was uploaded, and processed. It's a secured page so I printed
> > it as a PDF, I hope that's readable.
> >
> > http://people.canonical.com/~alan/filemanager_crash.pdf
> > --
> > https://code.launchpad.net/~popey/ubuntu-filemanager-app/add-click-
> deps/+merge/270287
> > Your team Ubuntu File Manager Developers is requested to review the proposed
> > merge of lp:~popey/ubuntu-filemanager-app/add-click-deps into
> > lp:ubuntu-filemanager-app.
> >

@popey, I do confirm the crash on Samba browsing, it happens on the phone, works on Desktop and works on the phone using the plugin/model as console application.

I am sorry for that, I did not test it properly, I worked on this on weekend and cannot solve it, I need the debug to work in order to find out the problem, I am able to use the debug from qtCreator on device, but it does not work properly, it behaves as a non debug invocation, when the crash happens there is not information about it.

Also tried using "gdb" directly on the device without success, in this case I could generate a core file with no enough information either.

Also added some qDebug() lines but it did not give me the reason for the crash.

If you have any idea about the crash or about other way of debugging please share with me.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Hello,

I did a first test without removing my Samba libraries.

On desktop it downloaded the libraries but on armhf it did not.

See some output:
-- Setting BZR_SOURCE to lp:ubuntu-filemanager-app
Grabbing upstream libs to /home/carlos/ubuntu_work/build-add-click-deps-UbuntuSDK_for_armhf_GCC_ubuntu_sdk_15_04_vivid-Default/upstream-libs
Installing upstream libs from /home/carlos/ubuntu_work/build-add-click-deps-UbuntuSDK_for_armhf_GCC_ubuntu_sdk_15_04_vivid-Default/upstream-libs/usr/lib/arm-linux-gnueabihf/ to /lib/arm-linux-gnueabihf
Following files to install:-

-- Found PkgConfig: arm-linux-gnueabihf-pkg-config (found version "0.28")
-- samba include=/usr/include/samba-4.0
-- samba lib=/usr/lib/arm-linux-gnueabihf/libsmbclient.so=/usr/lib/arm-linux-gnueabihf/libsmbclient.so
-- Found samba: include=/usr/include/samba-4.0 library=/usr/lib/arm-linux-gnueabihf/libsmbclient.so

Questions:
   1. Did I do something wrong?
   2. Cmake still found my installed samba libraries, should not it be changed to find downloaded stuff including libsmbclient.h which I think is missed from download script?
   3. I am wondering how is the mechanism used to load local libraries in the click package, can anyone tell how it works?

review: Needs Information
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Ok, I just checked building this branch on a nexus 7. Here's what I did to prove it builds:-

# grab this branch
bzr branch lp:~popey/ubuntu-filemanager-app/add-click-deps
# install build dependencies and cmake and phablet tools (to get click-buddy)
sudo apt-get install cmake debhelper intltool qtbase5-dev qtdeclarative5-dev qt5-default pkg-kde-tools python3-all libtag1-dev libpam0g-dev libsmbclient-dev cmake phablet-tools
# Build it:-
click-buddy --dir add-click-deps/

This grabbed the binary-built stuff which gets used at runtime, it then compiles and built filemanager.

I guess maybe when you un-installed samba libs you removed the headers needed for building?

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Hello Alan,

My attempt was done using the SDK armhf 15-04.

I see that you did install 'libsmbclient-dev' (it installs all the samba libraries) which I thought it was going to be downloaded by the proposed solution.

I thought that solution would bring all the necessary resources to compile and deploy on device. Any new developer will try to create the click package using SDK.

Am I wrong?

Can you try it again after removing all the samba libraries?

If so, I would suggest a sequence of commands:
sudo apt-get remove libsmbclient-dev
sudo apt-get autoremove # I hope this will uninstall all other samba libraries
click-buddy --dir add-click-deps/

If you want, can you also try it using armhf SDK?

Thanks,
Carlos

468. By Alan Pope 🍺🐧🐱 πŸ¦„

Merge trunk

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
469. By Alan Pope 🍺🐧🐱 πŸ¦„

update get-click-deps to python3

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Thanks,

I am looking forward to getting the entire Samba stuff in the next release.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-09-30 23:39:47 +0000
+++ CMakeLists.txt 2015-10-14 11:21:34 +0000
@@ -65,6 +65,23 @@
65 add_custom_target(com_ubuntu_calendar_CLICKFiles ALL SOURCES ${CLICK_FILES})65 add_custom_target(com_ubuntu_calendar_CLICKFiles ALL SOURCES ${CLICK_FILES})
6666
67 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json filemanager.apparmor ${CONTENT_HUB_EXPORTER} DESTINATION ${CMAKE_INSTALL_PREFIX})67 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json filemanager.apparmor ${CONTENT_HUB_EXPORTER} DESTINATION ${CMAKE_INSTALL_PREFIX})
68
69 MESSAGE("Grabbing upstream libs to ${CMAKE_CURRENT_BINARY_DIR}/upstream-libs")
70 execute_process(
71 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/upstream-libs
72 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/get-click-deps -d ${CMAKE_CURRENT_SOURCE_DIR}/filemanager-libs.json ${CLICK_ARCH} ${CMAKE_CURRENT_BINARY_DIR}/upstream-libs
73 )
74 MESSAGE("Installing upstream libs from ${CMAKE_CURRENT_BINARY_DIR}/upstream-libs/usr/lib/${ARCH_TRIPLET}/ to ${DATA_DIR}lib/${ARCH_TRIPLET}")
75 file(GLOB_RECURSE UPSTREAM_LIBS "${CMAKE_CURRENT_BINARY_DIR}/upstream-libs/usr/lib/${ARCH_TRIPLET}/*")
76 foreach(ITEM ${UPSTREAM_LIBS})
77 IF( IS_DIRECTORY "${ITEM}" )
78 LIST( APPEND DIRS_TO_DEPLOY "${ITEM}" )
79 ELSE()
80 LIST( APPEND FILES_TO_DEPLOY "${ITEM}" )
81 ENDIF()
82 endforeach()
83 MESSAGE("Following files to install:- ${FILES_TO_DEPLOY}")
84 INSTALL( FILES ${FILES_TO_DEPLOY} DESTINATION ${DATA_DIR}lib/${ARCH_TRIPLET} )
68else(CLICK_MODE)85else(CLICK_MODE)
69 execute_process(86 execute_process(
70 COMMAND qmake -query QT_INSTALL_QML87 COMMAND qmake -query QT_INSTALL_QML
7188
=== added file 'filemanager-libs.json'
--- filemanager-libs.json 1970-01-01 00:00:00 +0000
+++ filemanager-libs.json 2015-10-14 11:21:34 +0000
@@ -0,0 +1,50 @@
1{
2 "armhf": [
3 {
4 "url": "http://ports.ubuntu.com/ubuntu-ports",
5 "dist": "vivid",
6 "component": "main",
7 "packages": [
8 "libsmbclient",
9 "samba-libs",
10 "libtalloc2",
11 "libtevent0",
12 "libwbclient0",
13 "libldb1",
14 "libntdb1"
15 ]
16 }
17 ],
18 "amd64": [
19 {
20 "url": "http://archive.ubuntu.com/ubuntu",
21 "dist": "vivid",
22 "component": "main",
23 "packages": [
24 "libsmbclient",
25 "samba-libs",
26 "libtalloc2",
27 "libtevent0",
28 "libwbclient0",
29 "libldb1",
30 "libntdb1"
31 ]
32 }
33 ],
34 "i386": [
35 {
36 "url": "http://archive.ubuntu.com/ubuntu",
37 "dist": "vivid",
38 "component": "main",
39 "packages": [
40 "libsmbclient",
41 "samba-libs",
42 "libtalloc2",
43 "libtevent0",
44 "libwbclient0",
45 "libldb1",
46 "libntdb1"
47 ]
48 }
49 ]
50}
051
=== added file 'get-click-deps'
--- get-click-deps 1970-01-01 00:00:00 +0000
+++ get-click-deps 2015-10-14 11:21:34 +0000
@@ -0,0 +1,451 @@
1#!/usr/bin/python3
2
3# Copyright (C) 2015 Stefano Verzegnassi <verzegnassi.stefano@gmail.com>
4# Copyright (C) 2015 Didier Roche <didrocks@ubuntu.com>
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18#
19# Source code at:
20# https://code.launchpad.net/~verzegnassi-stefano/+junk/get-click-deps
21#
22# A script to automate the fetching all the external dependencies of a
23# Click packaged application from internet, and copying them in a given
24# folder, so that the click packaging tool can easily build them in the
25# package.
26#
27# usage: get-click-deps [-h] [-f] [-d] [-e] [-c SCRIPT_PATH]
28# manifest_path {amd64,i386,armhf} target_path
29#
30# A tool for adding external libraries to a Ubuntu SDK application or scope.
31#
32# positional arguments:
33# manifest_path path of json file containing the list of packages to
34# be downloaded.
35# {amd64,i386,armhf} CPU architecture ("amd64", "i386" or "armhf")
36# target_path path to the target (a click package or a folder)
37# where this tool will include the downloaded binaries.
38# If the folder does not exist, it will be created.
39#
40# optional arguments:
41# -h, --help show this help message and exit
42# -f, --force-download force a new download of the packages
43# -d, --delete-temp delete temp files at the end of the process
44# -e, --extract-only only create temp directory and extract the content of
45# downloaded packages
46# -c SCRIPT_PATH, --custom-script SCRIPT_PATH
47# run a custom script after the extraction of Debian
48# packages and before copying their content to the
49# target destination. The tool will execute the script
50# with the path to the packages dump as argument. If
51# the '-e' flag has been specified, the script will be
52# anyway executed. This option is useful when you need
53# to automatically modify the content of temp folder
54# (e.g. when you need to fix some path before including
55# the files in a click package).
56#
57#
58# USAGE EXAMPLE:
59# get-click-deps packages.json armhf <path/to/package.click>
60#
61# package.json is the package manifest, and contains all the references to the
62# .deb packages to be included into the Ubuntu SDK project.
63# If you're familiar to the Debian/Ubuntu world, you'll see that it's pretty
64# similar to therepository management of these distros:
65# see https://wiki.debian.org/SourcesList for further informations.
66#
67# An example of packages.json file is:
68# {
69# "armhf": [
70# {
71# "url": "http://ports.ubuntu.com/ubuntu-ports/",
72# "dist": "vivid",
73# "component": "main",
74# "packages": [
75# "libgl1-mesa-glx",
76# "libxslt1.1",
77# "libxcb-glx0",
78# "libxcb-dri3-0",
79# "libxcb-present0",
80# "libxshmfence1",
81# "libxxf86vm1"
82# ]
83# },
84#
85# {
86# "url": "http://ppa.launchpad.net/canonical-community/ppa/ubuntu",
87# "dist": "vivid",
88# "component": "main",
89# "packages": [
90# "libreoffice-vanilla"
91# ]
92# }
93# ],
94#
95# "amd64": [
96# "url": "http://ppa.launchpad.net/canonical-community/ppa/ubuntu",
97# "dist": "vivid",
98# "component": "main",
99# "packages": [
100# "libreoffice-vanilla"
101# ]
102# }
103# ]
104# }
105#
106# Instead of a click package, you can specify the build folder used by Ubuntu
107# SDK for compiling the sources of your project. This way the binaries
108# downloaded by this tool will be automatically included in the .click package
109# the next time you ask Ubuntu SDK to create a new package.
110#
111
112# TODO: Complete error handling
113# TODO: Make target_path optional if the '-e' flag has been specified.
114
115import sys
116import os
117import stat
118import time
119import argparse
120import json
121import gzip
122import subprocess
123import urllib.request, urllib.error, urllib.parse
124
125def get_timestamp():
126 return time.time()
127
128
129def check_internet_connection():
130 try:
131 urllib.request.urlopen('http://www.google.com', timeout=20)
132 return True
133 except urllib2.error.URLError as err:
134 pass
135 return False
136
137
138def get_arch_triplet(arch):
139 return subprocess.check_output([
140 'dpkg-architecture',
141 '-A',
142 arch,
143 '-qDEB_TARGET_MULTIARCH'])
144
145
146def download_file(url, dest, verbose=True):
147 if verbose:
148 print ("\nDownloading:\n{}".format(url))
149 # TODO: Switch to subprocess
150 os.system('cd %s && { curl -# -O %s ; cd - ; }' % (dest, url))
151
152
153def download_file_and_rename(url, dest, new_filename, verbose=True):
154 if verbose:
155 print ("\nDownloading:\n{}".format(url))
156 new_path = os.path.join(dest, new_filename)
157 subprocess.call(['curl', url, '-#', '-o', new_path])
158
159 return new_path
160
161
162def get_package_download_url(package_name, packages_list, base_url):
163 pkgs_list = packages_list.decode('utf-8').split('\n')
164 index = pkgs_list.index('Package: %s' % package_name)
165
166 for i in range(index, len(pkgs_list)):
167 if pkgs_list[i].find('Filename:') > -1:
168 return "%s/%s" % (base_url, pkgs_list[i].replace('Filename: ', ''))
169
170
171def get_URLs_for_arch(manifest_path, arch, destpath):
172 urls = []
173
174 f = open(manifest_path)
175 content = json.load(f)
176 f.close()
177
178 # Download repository index for each repository in the JSON package
179 # manifest.
180 try:
181 repo_index = 0
182 for repo in content[arch]:
183 repo_index_url = '%s/dists/%s/%s/binary-%s/Packages.gz' % (
184 repo['url'],
185 repo['dist'],
186 repo['component'],
187 arch)
188
189 print ("\nDownloading repository index at:\n".format(repo_index_url))
190
191 repo_index_zip = download_file_and_rename(
192 repo_index_url,
193 destpath,
194 'repo-index-%s-%s.gz' % (arch, repo_index),
195 False)
196
197 with gzip.open(repo_index_zip, 'r') as f:
198 repo_index_content = f.read()
199 f.close()
200
201 # Get the download URL of each package of the repository.
202 packages = repo['packages']
203 for package in packages:
204 urls.append(get_package_download_url(
205 package,
206 repo_index_content,
207 repo['url']))
208
209 repo_index += 1
210 except KeyError:
211 # Arch not found in the manifest. Exit with no error, since there's no
212 # need to run the script for this arch.
213 print ("\n\nRequested arch has been not specified in the manifest. \
214 Exiting...")
215 sys.exit(0)
216 print ("\nObtained packages informations")
217 return urls
218
219
220def check_if_temp_folder_already_exists(path):
221 return os.path.isdir(path)
222
223
224def copy_directory_content(sourcepath, destpath):
225 subprocess.call(['cp', '-r', '%s/.' % sourcepath, destpath])
226
227
228def delete_folder(path, recursive=False):
229 if recursive:
230 flag = '-rf'
231 else:
232 flag = '-f'
233 subprocess.call(['rm', flag, path])
234
235
236def extract_deb_package(deb_path, destpath):
237 subprocess.call(['dpkg-deb', '-x', deb_path, destpath])
238
239
240def extract_click_package(click_path, destpath):
241 extract_deb_package(click_path, destpath)
242
243 manifest = subprocess.check_output(['click', 'info', click_path])
244
245 # The manifest we get has an 'installed-size' key with the value of the
246 # previous package. Anyway this value will be replaced when we'll run
247 # 'click build <pkg>', so there's no reason for removing it here.
248 f = open(os.path.join(destpath, 'manifest.json'), 'w')
249 f.write(manifest)
250 f.close()
251
252 return destpath
253
254
255def build_click_package(source_dirpath):
256 output = subprocess.check_output(['click', 'build', source_dirpath])
257
258 for line in output.split(os.linesep):
259 if line.find('Successfully built package in ') > -1:
260 # FIXME: Very ugly.
261 path = line.replace('Successfully built package in \'', '')
262 path = path.replace('\'.', '')
263 return path
264
265
266def copy_file(sourcepath, destpath, overwrite=False):
267 flag = ''
268
269 if not overwrite:
270 flag = '-n'
271
272 subprocess.call(['cp', flag, sourcepath, destpath])
273
274
275# Argument parser
276parser = argparse.ArgumentParser(
277 description="A tool for adding external libraries to a Ubuntu SDK \
278 application or scope.")
279
280parser.add_argument(
281 '-f',
282 '--force-download',
283 dest='force_download',
284 action='store_true',
285 help='force a new download of the packages')
286
287parser.add_argument(
288 '-d',
289 '--delete-temp',
290 dest='delete_temp',
291 action='store_true',
292 help='delete temp files at the end of the process')
293
294parser.add_argument(
295 '-e',
296 '--extract-only',
297 dest='extract_only',
298 action='store_true',
299 help='only create temp directory and extract the content of downloaded \
300 packages')
301
302parser.add_argument(
303 '-c',
304 '--custom-script',
305 dest='script_path',
306 type=str,
307 help='run a custom script after the extraction of Debian packages and \
308 before copying their content to the target destination. The tool will \
309 execute the script with the path to the packages dump as argument. If \
310 the \'-e\' flag has been specified, the script will be anyway \
311 executed. This option is useful when you need to automatically modify \
312 the content of temp folder (e.g. when you need to fix some path \
313 before including the files in a click package).')
314
315parser.add_argument(
316 'manifest_path',
317 type=str,
318 help='path of json file containing the list of packages to be downloaded.')
319
320parser.add_argument(
321 'arch',
322 type=str,
323 choices=['amd64', 'i386', 'armhf'],
324 help='CPU architecture ("amd64", "i386" or "armhf")')
325
326parser.add_argument(
327 'target_path',
328 type=str,
329 help='path to the target (a click package or a folder) where this \
330 tool will include the downloaded binaries. If the folder does not \
331 exist, it will be created.')
332
333args = parser.parse_args()
334
335# Variables
336manifest_path = args.manifest_path
337target_path = args.target_path
338manifest_stat = os.stat(manifest_path)
339temp_folder = os.path.join(
340 '/tmp/',
341 'tmp-click-deps-%s-%s-%s-%s' % (
342 manifest_stat.st_dev,
343 manifest_stat.st_ino,
344 manifest_stat.st_size,
345 manifest_stat.st_mtime))
346temp_arch_folder = os.path.join(temp_folder, args.arch)
347is_click_target = os.path.isfile(args.target_path)
348
349# Check command line arguments
350if not os.path.isfile(manifest_path):
351 sys.exit("\n\nERROR: Package manifest is not a valid file. Exit...")
352
353if not os.path.isfile(target_path) and target_path.endswith('.click'):
354 sys.exit("\n\nERROR: The specified target .click does not exists.")
355elif not os.path.isdir(target_path):
356 print ("\n\nCreating dest folder\n{}".format(target_path))
357 os.mkdir(target_path)
358
359# Check if the script exist, if specified any.
360if args.script_path and not os.path.exists(args.script_path):
361 sys.exit("\n\nERROR: The specified script does not exists.")
362
363# If -f argument has been specified, remove all the existing data before
364# running this script.
365if args.force_download:
366 if os.path.isdir(temp_folder):
367 print ("\nRemoving temp data of the previous run, as requested")
368 delete_folder(temp_folder, True)
369
370# Check if we already have run this script for the same target.
371if not check_if_temp_folder_already_exists(temp_arch_folder):
372 # Check internet connection
373 if not check_internet_connection():
374 sys.exit("\n\nERROR: An internet connection is required in order to \
375 download packages from repositories.")
376
377 # Create temp folder in /tmp
378 print ("\nCreating temp folder in {}".format(temp_folder))
379 os.mkdir(temp_folder)
380 os.mkdir(temp_arch_folder)
381
382 # Parse the JSON package list and get the download URL of the packages.
383 debs_url_list = get_URLs_for_arch(
384 manifest_path,
385 args.arch,
386 temp_folder)
387
388 # Download packages from web
389 for url in debs_url_list:
390 download_file(url, temp_folder)
391
392 # Extract DEBs packages
393 print ("\nExtracting .deb packages to {}".format(temp_arch_folder))
394 deb_pkgs_list = []
395 for file in os.listdir(temp_folder):
396 if file.endswith('.deb'):
397 deb_pkgs_list.append(file)
398
399 for deb_pkg in deb_pkgs_list:
400 extract_deb_package(
401 os.path.join(temp_folder, deb_pkg),
402 temp_arch_folder)
403
404 # If a script has been specified, run it.
405 if args.script_path:
406 print ("\nRunning the script at: {}\n".format(args.script_path))
407
408 # Ensure that we can run the script, otherwise we don't have the
409 # permission
410 subprocess.call(['chmod', '+x', args.script_path])
411 subprocess.call([
412 args.script_path,
413 temp_arch_folder,
414 get_arch_triplet(args.arch)])
415else:
416 print ("\nPackages are already downloaded. Use them...")
417
418# If -e or --extract-only flags have been specified, we have completed our work
419if args.extract_only:
420 print ("\n\nCompleted successfully.")
421 sys.exit(0)
422
423# Copy temp_arch folder content to its destination
424if is_click_target:
425 print ("\nExtracting target .click package")
426 temp_click_folder = extract_click_package(
427 args.target_path,
428 os.path.join('/tmp/', str(get_timestamp())))
429
430 print ("\nAdding extracted binaries to the package")
431 copy_directory_content(temp_arch_folder, temp_click_folder)
432
433 new_click_package_path = build_click_package(temp_click_folder)
434 print ("\nCreated new .click package at:\n{}".format(new_click_package_path))
435
436 print ("\nReplacing older .click package")
437 copy_file(new_click_package_path, args.target_path, True)
438
439 delete_folder(temp_click_folder, True)
440
441else:
442 print ("\nCopying extracted binaries to their destination")
443 copy_directory_content(temp_arch_folder, args.target_path)
444
445# Delete temp files
446if args.delete_temp:
447 print ("\)nRemoving temp files and directory, as requested")
448 delete_folder(temp_folder, True)
449
450# Exit
451print ("\n\nCompleted successfully.")

Subscribers

People subscribed via source and target branches