From db7fb0c3f9946a360cabc14fbb1eeb848582e035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 21 Feb 2016 17:39:35 +0100 Subject: [PATCH] [enh] Get completely rid of os.system calls in _fetch_app_from_git --- src/yunohost/app.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 4d2ec600..3f5feb8c 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1151,8 +1151,11 @@ def _fetch_app_from_git(app): Dict manifest """ + app_tmp_archive = '{0}.zip'.format(app_tmp_folder) if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder) + if os.path.exists(app_tmp_archive): + os.remove(app_tmp_archive) msignals.display(m18n.n('downloading')) @@ -1170,15 +1173,16 @@ def _fetch_app_from_git(app): tarball_url = "{url}/archive/{tree}.zip".format( url=url, tree=branch ) - if os.system('wget "%s" -O "%s.zip" > /dev/null 2>&1' % ( - tarball_url, app_tmp_folder)) == 0: - manifest = _extract_app_from_file( - app_tmp_folder +'.zip', remove=True) - del manifest['remote'] - else: - logger.debug('unable to download %s', tarball_url) + try: + subprocess.check_call([ + 'wget', '-qO', app_tmp_archive, tarball_url]) + except subprocess.CalledProcessError: + logger.exception('unable to download %s', tarball_url) raise MoulinetteError(errno.EIO, m18n.n('app_sources_fetch_failed')) + else: + manifest = _extract_app_from_file( + app_tmp_archive, remove=True) else: tree_index = url.rfind('/tree/') if tree_index > 0: @@ -1227,13 +1231,16 @@ def _fetch_app_from_git(app): tarball_url = "{url}/archive/{tree}.zip".format( url=url, tree=app_info['git']['revision'] ) - if os.system('wget "%s" -O "%s.zip" > /dev/null 2>&1' % ( - tarball_url, app_tmp_folder)) == 0: - manifest = _extract_app_from_file( - app_tmp_folder +'.zip', remove=True) - else: + try: + subprocess.check_call([ + 'wget', '-qO', app_tmp_archive, tarball_url]) + except subprocess.CalledProcessError: + logger.exception('unable to download %s', tarball_url) raise MoulinetteError(errno.EIO, m18n.n('app_sources_fetch_failed')) + else: + manifest = _extract_app_from_file( + app_tmp_archive, remove=True) else: try: subprocess.check_call([