diff options
author | florent <florent.pigout@gmail.com> | 2011-04-19 18:22:40 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-04-19 18:22:40 (GMT) |
commit | 89799eedcb5348339156beb35593781b6686edbb (patch) | |
tree | a8bf3f26fe5665fa7363dbe05cb239f55242fac4 | |
parent | 8052c667b5f91e1613e6d3b0e287393009315a87 (diff) |
catch more import errors
-rw-r--r-- | atoidejouer/tools/storage.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/atoidejouer/tools/storage.py b/atoidejouer/tools/storage.py index 63f5e36..b10770a 100644 --- a/atoidejouer/tools/storage.py +++ b/atoidejouer/tools/storage.py @@ -307,16 +307,23 @@ def import_project(activity_, file_path, msg_label): __check_dir('tmp', parent=None) # .. _tmp_root = os.path.join(activity.get_activity_root(), 'tmp') - # copy file to tmp - _tar_path = os.path.join(_tmp_root, '__tmp.tar.bz2') - shutil.copy(file_path, _tar_path) - # change dir for unzipping - os.chdir(_tmp_root) - # extract files in tmp dir - _tar = tarfile.open(file_path) - _p_name = _tar.getnames()[0] - _tar.extractall() - _tar.close() + try: + # copy file to tmp + _tar_path = os.path.join(_tmp_root, '__tmp.tar.bz2') + shutil.copy(file_path, _tar_path) + # change dir for unzipping + os.chdir(_tmp_root) + # extract files in tmp dir + _tar = tarfile.open(file_path) + _p_name = _tar.getnames()[0] + _tar.extractall() + _tar.close() + except Exception, e: + # prepare message + _msg = _('Project import failed!') + _msg = _('%s\n\n[Error] Can not read archive file!' % _msg) + # quit! + return __show_in_out_result_message(msg_label, _msg) # merge dirs _exist_list = list() if __merge_dir(_p_name, 'graphics', exist_list=_exist_list)\ @@ -338,7 +345,7 @@ def import_project(activity_, file_path, msg_label): pass else: # prepare message - _msg = _('%s\n\n[Warning] The following files already exist:\n'\ + _msg = _('%s\n\n[Warning] Following files already exist:\n'\ % _msg) for _f in _exist_list: _msg = '%s - %s\n' % (_msg, _f) @@ -355,7 +362,7 @@ def import_project(activity_, file_path, msg_label): pass else: # prepare message - _msg = _('%s\n\n[Warning] The following sequences already exist:\n' + _msg = _('%s\n\n[Warning] Following sequences already exist:\n' % _msg) for _s in _existing_dict['graphics']: _msg = '%s - graphics.%s\n' % (_msg, _s) |