From: <sal...@li...> - 2011-11-17 09:40:58
|
Revision: 2791 http://salix.svn.sourceforge.net/salix/?rev=2791&view=rev Author: gapan Date: 2011-11-17 09:40:48 +0000 (Thu, 17 Nov 2011) Log Message: ----------- Get detailed list of packages to be installed Modified Paths: -------------- salix-codecs-installer/branches/python/src/salix-codecs-installer Modified: salix-codecs-installer/branches/python/src/salix-codecs-installer =================================================================== --- salix-codecs-installer/branches/python/src/salix-codecs-installer 2011-11-16 23:09:11 UTC (rev 2790) +++ salix-codecs-installer/branches/python/src/salix-codecs-installer 2011-11-17 09:40:48 UTC (rev 2791) @@ -4,6 +4,7 @@ import os import sys import commands +import subprocess import gzip import urllib2 import urlgrabber @@ -76,13 +77,10 @@ unmangled = repo.replace('#', '/').partition(working_dir+'.')[2] return unmangled - def download_file(self, working_dir, url, mangled=False): + def download_repofile(self, working_dir, url): new = self.__get_head(url) local = self.__local_head(working_dir, url) - if mangled == True: - murl = self.__mangled_url(url) - else: - murl = url + murl = self.__mangled_url(url) if new == local: # file is already there self.progressbar_repo.set_fraction(1) @@ -138,7 +136,7 @@ pkgname = '' for line in pkgtxt_file: if line.startswith('PACKAGE NAME'): - pkgname = line.partition('PACKAGE NAME:')[2].lstrip(' ').rpartition('\n')[0] + pkgname = line.partition('PACKAGE NAME:')[2].strip() has_mirror_line = False is_extra = False f.write(line) @@ -213,6 +211,7 @@ f.close(i) self.write_package_data_file(pkgtxt_file, mirror, priority+1, checksums_list) self.progressbar_repo_total.set_fraction(1) + self.label_repo_desc.set_text(_('Reading package lists...')) while gtk.events_pending(): gtk.main_iteration() @@ -248,7 +247,7 @@ self.messagedialog_sources_error.show() raise KeyboardInterrupt self.label_repo_desc.set_text(_('Retrieving package data...')) - self.download_file(working_dir, url, mangled=True) + self.download_repofile(working_dir, url) fullpath = working_dir+'/'+self.__mangled_url(url) repo_files.append(fullpath) repo_files.append(repo_priority) @@ -265,7 +264,7 @@ patches = True if patches == True: self.label_repo_desc.set_text(_('Retrieving patch list...')) - self.download_file(working_dir, url, mangled=True) + self.download_repofile(working_dir, url) fullpath = working_dir+'/'+self.__mangled_url(url) repo_files.append(fullpath) self.progressbar_repo.set_fraction(1) @@ -283,7 +282,7 @@ self.messagedialog_sources_error.show() raise KeyboardInterrupt self.label_repo_desc.set_text(_('Retrieving checksum list...')) - self.download_file(working_dir, url, mangled=True) + self.download_repofile(working_dir, url) fullpath = working_dir+'/'+self.__mangled_url(url) repo_files.append(fullpath) step += 1 @@ -299,7 +298,7 @@ checksumsig = True if checksumsig == True: self.label_repo_desc.set_text(_('Retrieving checksum signature...')) - self.download_file(working_dir, url, mangled=True) + self.download_repofile(working_dir, url) self.progressbar_repo.set_fraction(1) step += 1 self.progressbar_repo_total.set_fraction(step/steps) @@ -315,7 +314,7 @@ if self.url_exists(repo_url+'ChangeLog.txt'): url = repo_url+'ChangeLog.txt' self.label_repo_desc.set_text(_('Retrieving ChangeLog.txt...')) - self.download_file(working_dir, url, mangled=True) + self.download_repofile(working_dir, url) self.progressbar_repo.set_fraction(1) step += 1 self.progressbar_repo_total.set_fraction(step/steps) @@ -326,12 +325,87 @@ pass return allrepos + def pkg_deps_and_sugs(self, pkgname): + cmd = ['LANG=C /usr/sbin/slapt-get --show '+pkgname+'|grep "^Package Required:\|^Package Suggests:"'] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + output = process.communicate()[0] + pkgs = [] + for line in output.split('\n'): + if line.startswith('Package'): + for i in line.rpartition('Package Required:')[2].rpartition('Package Suggests:')[2].lstrip(' ').rstrip(' ').replace(' ', ',').replace('|', ' ').split(','): + if i is not '': + pkgs.append(i) + return pkgs + + def pkglist(self): + #pkgs = ['gstreamer', 'gst-plugins-base', 'gst-plugins-good', 'gst-plugins-bad', 'gst-plugins-ugly', 'gst-python', 'gst-ffmpeg'] + pkgs = ['openbox-menu', 'recordmydesktop'] + deps = [] + for pkg in pkgs: + for i in self.pkg_deps_and_sugs(pkg): + deps.append(i) + for i in pkgs: + deps.append(i) + return set(deps) + + def pkg_uris(self, pkglist): + pkgstr = ' '.join(pkglist) + cmd = ['/usr/sbin/slapt-get --print-uris -s -i '+pkgstr+'|grep "^http:\|^ftp:\|^file:"'] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + output = process.communicate()[0].split() + return output + + def pkg_detailed_list(self, uris): + working_dir = self.working_dir + f = open(working_dir+'/package_data') + package_data = f.readlines() + f.close() + uri_list = [] + for i in uris: + pkgname = i.rpartition('/')[2] + uri_list.append([pkgname, i]) + pkgfilename = '' + pkgname = '' + pkgver = '' + pkgname_match = False + location = '' + location_found = False + md5sum = '' + md5sum_found = False + detailed_list = [] + for line in package_data: + if line.startswith('PACKAGE NAME'): + pkgfilename = line.partition('PACKAGE NAME:')[2].strip() + for i in uri_list: + if pkgfilename == i[0]: + pkgname = pkgfilename.rpartition('-')[0].rpartition('-')[0].rpartition('-')[0] + pkgver = pkgfilename.partition(pkgname)[2].lstrip('-').rpartition('.')[0] + uri = i[1] + pkgname_match = True + location_found = False + elif line.startswith('PACKAGE LOCATION'): + location = line.partition('PACKAGE LOCATION:')[2].strip() + location_found = True + elif line.startswith('PACKAGE MD5SUM'): + md5sum = line.partition('PACKAGE MD5SUM:')[2].strip() + md5sum_found = True + if (pkgname_match is True) and (location_found is True) and (md5sum_found is True): + detailed_list.append([pkgname, pkgver, pkgfilename, uri, location, md5sum]) + pkgname_match = False + location_found = False + md5sum_found = False + return detailed_list + def on_button_infowindow_yes_clicked(self, widget): self.infowindow.hide() - self.dialog_update.show() - self.dialog_update.set_title(_('Updating local package cache')) - repos = self.download_repo_info() - self.create_package_data(repos) + #self.dialog_update.show() + #self.dialog_update.set_title(_('Updating local package cache')) + #repos = self.download_repo_info() + #self.create_package_data(repos) + pkglist = self.pkglist() + uris = self.pkg_uris(pkglist) + pkg_detailed_list=self.pkg_detailed_list(uris) + print pkg_detailed_list gtk.main_quit() def on_button_infowindow_no_clicked(self, widget): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |