changeset d815964e2845 in /home/hg/repos/gajim-plugins
author: Yann Leboulanger asterix@lagaule.org branches: details:gajim-plugins?cmd=changeset;node=d815964e2845 description: get plugins via zip files instead of file by file
diffstat:
plugin_installer/manifest.ini | 2 +- plugin_installer/plugin_installer.py | 55 +++++++---------------------------- 2 files changed, 13 insertions(+), 44 deletions(-)
diffs (92 lines):
diff -r 2560a9ae79ca -r d815964e2845 plugin_installer/manifest.ini --- a/plugin_installer/manifest.ini Sat Feb 27 13:46:45 2016 +0100 +++ b/plugin_installer/manifest.ini Sun Mar 06 16:06:29 2016 +0100 @@ -1,7 +1,7 @@ [info] name: Plugin Installer short_name: plugin_installer -version: 0.11.22 +version: 0.11.30 description: Install and upgrade plugins from ftp authors: Denis Fomin fominde@gmail.com Yann Leboulanger asterix@lagaule.org diff -r 2560a9ae79ca -r d815964e2845 plugin_installer/plugin_installer.py --- a/plugin_installer/plugin_installer.py Sat Feb 27 13:46:45 2016 +0100 +++ b/plugin_installer/plugin_installer.py Sun Mar 06 16:06:29 2016 +0100 @@ -79,7 +79,7 @@ elif gajim.version.startswith('0.16.10'): self.server_folder = 'plugins_gtk3' else: - self.server_folder = 'plugins_0.16' + self.server_folder = 'plugins_0.16_zip'
@log_calls('PluginInstallerPlugin') def activate(self): @@ -588,29 +588,7 @@ self.pulse = gobject.timeout_add(150, self.progressbar_pulse) gobject.idle_add(self.progressbar.set_text, _('Creating a list of files')) for remote_dir in self.remote_dirs: - - def nlstr(dir_, subdir=None): - if subdir: - dir_ = dir_ + '/' + subdir - list_ = self.ftp.nlst(dir_) - for i in list_: - name = i.split('/')[-1] - if '.' not in name: - try: - if i == self.ftp.nlst(i)[0]: - files.append(i[1:]) - del dirs[i[1:]] - except Exception, e: - # empty dir or file - continue - dirs.append(i[1:]) - subdirs = name - nlstr(dir_, subdirs) - else: - files.append(i[1:]) - dirs, files = [], [] - nlstr('/%s/%s' % (self.plugin.server_folder, remote_dir)) - + filename = remote_dir + '.zip' base_dir, user_dir = gajim.PLUGINS_DIRS if not os.path.isdir(user_dir): os.mkdir(user_dir) @@ -619,26 +597,17 @@ os.mkdir(local_dir) local_dir = os.path.split(user_dir)[0]
- # creating dirs - for dir_ in dirs: - dir_ = dir_.replace(self.plugin.server_folder, 'plugins') - if os.path.exists(os.path.join(local_dir, dir_)): - continue - os.mkdir(os.path.join(local_dir, dir_)) + # downloading zip file + gobject.idle_add(self.progressbar.set_text, + _('Downloading "%s"') % filename) + self.buffer_ = io.BytesIO() + try: + self.ftp.retrbinary('RETR %s' % filename, self.handleDownload) + except ftplib.error_perm: + print 'ERROR: cannot read file "%s"' % filename + with zipfile.ZipFile(self.buffer_) as zip_file: + zip_file.extractall(os.path.join(local_dir, 'plugins'))
- # downloading files - for filename in files: - gobject.idle_add(self.progressbar.set_text, - _('Downloading "%s"') % filename) - full_filename = os.path.join(local_dir, filename.replace( - self.plugin.server_folder, 'plugins')) - try: - self.ftp.retrbinary('RETR /%s' % filename, - open(full_filename, 'wb').write) - #full_filename.close() - except ftplib.error_perm: - print 'ERROR: cannot read file "%s"' % filename - os.unlink(filename) self.ftp.quit() gobject.idle_add(self.window.emit, 'plugin_downloaded', self.remote_dirs)