def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_UPGRADE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add ignore button. (ignoreLabel, ignoreEventBox) = setDefaultClickableDynamicLabel( __("Notify again"), "appIgnore", ) ignoreEventBox.connect("button-press-event", lambda w, e: self.removeIgnorePkgCallback([utils.getPkgName(pkg)])) ignoreLabelPaddingX = 30 ignoreAlign = gtk.Alignment() ignoreAlign.set(0.0, 0.5, 0.0, 0.0) ignoreAlign.set_padding(0, 0, ignoreLabelPaddingX, ignoreLabelPaddingX) ignoreAlign.add(ignoreEventBox) self.appAdditionBox.pack_start(ignoreAlign, False, False)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application installed size. size = utils.getPkgInstalledSize(pkg) appSize = gtk.Label() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_UNINSTALL, self.entryDetailCallback, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.confirmUninstall: appUninstallLabel = gtk.Label() appUninstallLabel.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, "你确定要卸载吗?")) actionButtonBox.pack_start(appUninstallLabel, False, False) appUninstallBox = gtk.HBox() appUninstallAlign = gtk.Alignment() appUninstallAlign.set(0.5, 0.5, 1.0, 1.0) appUninstallAlign.set_padding(ACTION_BUTTON_PADDING_Y, ACTION_BUTTON_PADDING_Y, 0, 0) appUninstallAlign.add(appUninstallBox) actionButtonBox.pack_start(appUninstallAlign, False, False) (appConfirmButton, appConfirmAlign) = newActionButton( "uninstall_confirm", 0.0, 0.5, "cell", False, "卸载", BUTTON_FONT_SIZE_SMALL ) appConfirmButton.connect("button-release-event", lambda widget, event: self.switchToUninstalling()) (appCancelButton, appCancelAlign) = newActionButton( "uninstall_confirm", 1.0, 0.5, "cell", False, "取消", BUTTON_FONT_SIZE_SMALL ) appCancelButton.connect("button-release-event", lambda widget, event: self.switchToNormal(False)) appUninstallBox.pack_start(appConfirmAlign) appUninstallBox.pack_start(appCancelAlign) else: (appUninstallBox, appUninstallAlign) = newActionButton( "uninstall", 0.5, 0.5, "cell", False, "卸载", BUTTON_FONT_SIZE_SMALL ) appUninstallBox.connect("button-release-event", lambda widget, event: self.switchToNormal(True)) actionButtonBox.pack_start(appUninstallAlign)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView(self.appInfo, PAGE_UPGRADE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSizeLabel = DynamicSimpleLabel( self.appAdditionBox, utils.formatFileSize(size), appTheme.getDynamicColor("appSize"), LABEL_FONT_SIZE, ) appSize = appSizeLabel.getLabel() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add ignore button. (ignoreLabel, ignoreEventBox) = setDefaultClickableDynamicLabel( __("Don't Notify"), "appIgnore", ) self.appAdditionBox.pack_start(ignoreEventBox, False, False) ignoreEventBox.connect( "button-press-event", lambda w, e: self.addIgnorePkgCallback(utils.getPkgName(pkg))) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) (appButton, appButtonAlign) = newActionButton("update", 0.5, 0.5, "cell", False, __("Action Update"), BUTTON_FONT_SIZE_SMALL, "buttonFont") appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_DOWNLOAD_MANAGE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.LIKE_PADDING_X) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.appInfo.status == APP_STATE_NORMAL: (appButton, appButtonAlign) = newActionButton( "install", 0.5, 0.5, "cell", False, __("Action Install"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) elif self.appInfo.status == APP_STATE_UPGRADE: (appButton, appButtonAlign) = newActionButton( "update", 0.5, 0.5, "cell", False, __("Action Update"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) else: appInstalledDynamicLabel = DynamicSimpleLabel( actionButtonBox, __("Action Installed"), appTheme.getDynamicColor("installed"), LABEL_FONT_SIZE, ) appInstalledLabel = appInstalledDynamicLabel.getLabel() buttonImage = appTheme.getDynamicPixbuf("cell/update_hover.png").getPixbuf() appInstalledLabel.set_size_request(buttonImage.get_width(), buttonImage.get_height()) actionButtonBox.pack_start(appInstalledLabel)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_DOWNLOAD_MANAGE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.LIKE_PADDING_X) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.appInfo.status == APP_STATE_NORMAL: (appButton, appButtonAlign) = newActionButton( "install", 0.5, 0.5, "cell", False, __("Action Install"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) elif self.appInfo.status == APP_STATE_UPGRADE: (appButton, appButtonAlign) = newActionButton( "update", 0.5, 0.5, "cell", False, __("Action Update"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) else: appInstalledDynamicLabel = DynamicSimpleLabel( actionButtonBox, __("Action Installed"), appTheme.getDynamicColor("installed"), LABEL_FONT_SIZE, ) appInstalledLabel = appInstalledDynamicLabel.getLabel() buttonImage = appTheme.getDynamicPixbuf("cell/update_hover.png").getPixbuf() appInstalledLabel.set_size_request(buttonImage.get_width(), buttonImage.get_height()) actionButtonBox.pack_start(appInstalledLabel)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_UPGRADE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSizeLabel = DynamicSimpleLabel( self.appAdditionBox, utils.formatFileSize(size), appTheme.getDynamicColor("appSize"), LABEL_FONT_SIZE, ) appSize = appSizeLabel.getLabel() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add ignore button. (ignoreLabel, ignoreEventBox) = setDefaultClickableDynamicLabel( __("Don't Notify"), "appIgnore", ) self.appAdditionBox.pack_start(ignoreEventBox, False, False) ignoreEventBox.connect("button-press-event", lambda w, e: self.addIgnorePkgCallback(utils.getPkgName(pkg))) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) (appButton, appButtonAlign) = newActionButton( "update", 0.5, 0.5, "cell", False, __("Action Update"), BUTTON_FONT_SIZE_SMALL, "buttonFont") appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.LIKE_PADDING_X) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_REPO, self.entryDetailCallback, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.appInfo.status == APP_STATE_NORMAL: (appButton, appButtonAlign) = newActionButton( "install", 0.5, 0.5, "cell", False, "安装", BUTTON_FONT_SIZE_SMALL ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) elif self.appInfo.status == APP_STATE_UPGRADE: (appButton, appButtonAlign) = newActionButton( "update", 0.5, 0.5, "cell", False, "升级", BUTTON_FONT_SIZE_SMALL ) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign) else: appInstalledLabel = gtk.Label() appInstalledLabel.set_markup("<span foreground='#1A3E88' size='%s'>%s</span>" % (LABEL_FONT_SIZE, "已安装")) buttonImage = gtk.gdk.pixbuf_new_from_file("./icons/cell/update_hover.png") appInstalledLabel.set_size_request(buttonImage.get_width(), buttonImage.get_height()) actionButtonBox.pack_start(appInstalledLabel)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView(self.appInfo, PAGE_UPGRADE, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add ignore button. (ignoreLabel, ignoreEventBox) = setDefaultClickableDynamicLabel( __("Notify again"), "appIgnore", ) ignoreEventBox.connect( "button-press-event", lambda w, e: self.removeIgnorePkgCallback([utils.getPkgName(pkg)])) ignoreLabelPaddingX = 30 ignoreAlign = gtk.Alignment() ignoreAlign.set(0.0, 0.5, 0.0, 0.0) ignoreAlign.set_padding(0, 0, ignoreLabelPaddingX, ignoreLabelPaddingX) ignoreAlign.add(ignoreEventBox) self.appAdditionBox.pack_start(ignoreAlign, False, False)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView(self.appInfo, PAGE_UNINSTALL, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application installed size. size = utils.getPkgInstalledSize(pkg) appSizeLabel = DynamicSimpleLabel( self.appAdditionBox, utils.formatFileSize(size), appTheme.getDynamicColor("appSize"), LABEL_FONT_SIZE, ) appSize = appSizeLabel.getLabel() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.confirmUninstall: appUninstallLabel = gtk.Label() appUninstallLabel.set_markup( "<span foreground='%s' size='%s'>%s</span>" % (appTheme.getDynamicColor("uninstallConfirm").getColor(), LABEL_FONT_SIZE, __("Are you sure uninstall?"))) actionButtonBox.pack_start(appUninstallLabel, False, False) appUninstallBox = gtk.HBox() appUninstallAlign = gtk.Alignment() appUninstallAlign.set(0.5, 0.5, 1.0, 1.0) appUninstallAlign.set_padding(ACTION_BUTTON_PADDING_Y, ACTION_BUTTON_PADDING_Y, 0, 0) appUninstallAlign.add(appUninstallBox) actionButtonBox.pack_start(appUninstallAlign, False, False) if getDefaultLanguage() == "default": buttonName = "uninstall_confirm" else: buttonName = "uninstall_confirm_cn" (appConfirmButton, appConfirmAlign) = newActionButton( buttonName, 0.0, 0.5, "cell", False, __("Action Uninstall"), BUTTON_FONT_SIZE_SMALL, "buttonFont") appConfirmButton.connect( "button-release-event", lambda widget, event: self.switchToUninstalling()) (appCancelButton, appCancelAlign) = newActionButton( buttonName, 1.0, 0.5, "cell", False, __("Action Cancel"), BUTTON_FONT_SIZE_SMALL, "buttonFont") appCancelButton.connect( "button-release-event", lambda widget, event: self.switchToNormal(False)) appUninstallBox.pack_start(appConfirmAlign) appUninstallBox.pack_start(appCancelAlign) else: (appUninstallBox, appUninstallAlign) = newActionButton( "uninstall", 0.5, 0.5, "cell", False, __("Action Uninstall"), BUTTON_FONT_SIZE_SMALL, "buttonFont") appUninstallBox.connect( "button-release-event", lambda widget, event: self.switchToNormal(True)) actionButtonBox.pack_start(appUninstallAlign)
def _download(self, pkgs): # Update status. self.updateCallback(self.pkgName, 0, __("Start Download")) # Make metalink. self.server.aria2.addMetalink(xmlrpclib.Binary(self.make_metalink(pkgs))) # Download loop. downloadCompleted = False while not downloadCompleted: # Sleep thread. time.sleep(self.updateInterval) # Stop download if reach retry times. if self.retryTicker > DOWNLOAD_TIMEOUT: self.messageCallback((__("% s: Download timeout, please check your network link.") % (self.pkgName))) self.updateCallback(self.pkgName, self.progress, __("Download Timeout")) return DOWNLOAD_STATUS_TIMEOUT elif self.retryTicker > 0: print "Retry (%s/%s)" % (self.retryTicker, DOWNLOAD_TIMEOUT) # Stop download if received signal. if not self.signalChannel.empty(): signal = self.signalChannel.get_nowait() if signal == "STOP": return DOWNLOAD_STATUS_STOP elif signal == "PAUSE": self.updateCallback(self.pkgName, self.progress, __("Download Pause"), APP_STATE_DOWNLOAD_PAUSE) return DOWNLOAD_STATUS_PAUSE # Otherwise wait download complete. else: # Get status list. statusList = self.server.aria2.tellActive() completedStatus = [] for status in statusList: gid = status['gid'] self.downloadStatus[gid] = int(status['completedLength']) completedStatus.append(status['status'] == 'complete') # Get current download length. currentLength = sum(self.downloadStatus.values()) # Get download speed. if self.cacheLength == 0: downloadSpeed = 0 else: downloadSpeed = currentLength - self.cacheLength / self.updateInterval # Store cache length. self.cacheLength = currentLength # Increases retry ticker if download speed is zero. if downloadSpeed == 0: self.retryTicker += 1 # Init retry ticker if download speed is not zero. else: self.retryTicker = 0 # Get progress. if self.totalLength == 0: self.progress = 0 else: self.progress = int(currentLength * 100 / self.totalLength) # Update status. self.updateCallback(self.pkgName, self.progress, utils.formatFileSize(downloadSpeed) + "/s") # Whether all download complete. downloadCompleted = all(completedStatus) link_success = True # Link archives/pkgName/*.deb to archives/ for pkg in pkgs: filename = get_filename(pkg.candidate) dst = os.path.join(self.archiveDir, filename) src = os.path.join(self.partialDir, filename) ctrl_file = ''.join([src, '.aria2']) # If control file exists, we assume download is not # complete. if os.path.exists(ctrl_file): continue try: # Making hard link because aria2c needs file in # partial directory to know download is complete # in the next invocation. os.rename(src, dst) except OSError, e: if e.errno != errno.ENOENT: print "Failed to move archive file", e link_success = False
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application version. currentVersion = pkg.installed.version if len(pkg.versions) == 0: upgradeVersion = "错误的版本, 请报告错误!" else: upgradeVersion = pkg.versions[0].version versionBox = gtk.VBox() versionAlign = gtk.Alignment() versionAlign.set(0.0, 0.5, 0.0, 0.0) versionAlign.add(versionBox) self.appAdditionBox.pack_start(versionAlign, True, True, self.APP_RIGHT_PADDING_X) currentVersionBox = gtk.HBox() versionBox.pack_start(currentVersionBox, False, False) currentVersionName = gtk.Label() currentVersionName.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, "当前版本: ")) currentVersionBox.pack_start(currentVersionName, False, False) currentVersionNum = gtk.Label() currentVersionNum.set_ellipsize(pango.ELLIPSIZE_MIDDLE) currentVersionNum.set_markup("<span foreground='#333333' size='%s'>%s</span>" % (LABEL_FONT_SIZE, currentVersion)) currentVersionNum.set_size_request(self.VERSION_LABEL_WIDTH, -1) currentVersionNum.set_alignment(0.0, 0.5) currentVersionBox.pack_start(currentVersionNum, False, False) upgradeVersionBox = gtk.HBox() versionBox.pack_start(upgradeVersionBox, False, False) upgradeVersionName = gtk.Label() upgradeVersionName.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, "升级版本: ")) upgradeVersionBox.pack_start(upgradeVersionName, False, False) upgradeVersionNum = gtk.Label() upgradeVersionNum.set_ellipsize(pango.ELLIPSIZE_MIDDLE) upgradeVersionNum.set_markup("<span foreground='#00BB00' size='%s'>%s</span>" % (LABEL_FONT_SIZE, upgradeVersion)) upgradeVersionNum.set_size_request(self.VERSION_LABEL_WIDTH, -1) upgradeVersionNum.set_alignment(0.0, 0.5) upgradeVersionBox.pack_start(upgradeVersionNum, False, False) # Add application size. size = utils.getPkgSize(pkg) appSize = gtk.Label() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_markup("<span size='%s'>%s</span>" % (LABEL_FONT_SIZE, utils.formatFileSize(size))) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_UPGRADE, self.entryDetailCallback, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) (appButton, appButtonAlign) = newActionButton( "update", 0.5, 0.5, "cell", False, "升级", BUTTON_FONT_SIZE_SMALL) appButton.connect("button-release-event", lambda widget, event: self.switchToDownloading()) actionButtonBox.pack_start(appButtonAlign)
def initNormalStatus(self): '''Init normal status.''' pkg = self.appInfo.pkg # Clean right box first. utils.containerRemoveAll(self.appAdditionBox) # Add application vote information. self.appVoteView = VoteView( self.appInfo, PAGE_UNINSTALL, self.sendVoteCallback) self.appAdditionBox.pack_start(self.appVoteView.eventbox, False, False) # Add application installed size. size = utils.getPkgInstalledSize(pkg) appSizeLabel = DynamicSimpleLabel( self.appAdditionBox, utils.formatFileSize(size), appTheme.getDynamicColor("appSize"), LABEL_FONT_SIZE, ) appSize = appSizeLabel.getLabel() appSize.set_size_request(self.SIZE_LABEL_WIDTH, -1) appSize.set_alignment(1.0, 0.5) self.appAdditionBox.pack_start(appSize, False, False, self.APP_RIGHT_PADDING_X) # Add action button. (actionButtonBox, actionButtonAlign) = createActionButton() self.appAdditionBox.pack_start(actionButtonAlign, False, False) if self.confirmUninstall: appUninstallLabel = gtk.Label() appUninstallLabel.set_markup( "<span foreground='%s' size='%s'>%s</span>" % ( appTheme.getDynamicColor("uninstallConfirm").getColor(), LABEL_FONT_SIZE, __("Are you sure uninstall?"))) actionButtonBox.pack_start(appUninstallLabel, False, False) appUninstallBox = gtk.HBox() appUninstallAlign = gtk.Alignment() appUninstallAlign.set(0.5, 0.5, 1.0, 1.0) appUninstallAlign.set_padding(ACTION_BUTTON_PADDING_Y, ACTION_BUTTON_PADDING_Y, 0, 0) appUninstallAlign.add(appUninstallBox) actionButtonBox.pack_start(appUninstallAlign, False, False) if getDefaultLanguage() == "default": buttonName = "uninstall_confirm" else: buttonName = "uninstall_confirm_cn" (appConfirmButton, appConfirmAlign) = newActionButton( buttonName, 0.0, 0.5, "cell", False, __("Action Uninstall"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appConfirmButton.connect("button-release-event", lambda widget, event: self.switchToUninstalling()) (appCancelButton, appCancelAlign) = newActionButton( buttonName, 1.0, 0.5, "cell", False, __("Action Cancel"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appCancelButton.connect("button-release-event", lambda widget, event: self.switchToNormal(False)) appUninstallBox.pack_start(appConfirmAlign) appUninstallBox.pack_start(appCancelAlign) else: (appUninstallBox, appUninstallAlign) = newActionButton( "uninstall", 0.5, 0.5, "cell", False, __("Action Uninstall"), BUTTON_FONT_SIZE_SMALL, "buttonFont" ) appUninstallBox.connect("button-release-event", lambda widget, event: self.switchToNormal(True)) actionButtonBox.pack_start(appUninstallAlign)
def _download(self, pkgs): # Update status. self.updateCallback(self.pkgName, 0, __("Start Download")) # Make metalink. self.server.aria2.addMetalink( xmlrpclib.Binary(self.make_metalink(pkgs))) # Download loop. downloadCompleted = False while not downloadCompleted: # Sleep thread. time.sleep(self.updateInterval) # Stop download if reach retry times. if self.retryTicker > DOWNLOAD_TIMEOUT: self.messageCallback((__( "% s: Download timeout, please check your network link.") % (self.pkgName))) self.updateCallback(self.pkgName, self.progress, __("Download Timeout")) return DOWNLOAD_STATUS_TIMEOUT elif self.retryTicker > 0: print "Retry (%s/%s)" % (self.retryTicker, DOWNLOAD_TIMEOUT) # Stop download if received signal. if not self.signalChannel.empty(): signal = self.signalChannel.get_nowait() if signal == "STOP": return DOWNLOAD_STATUS_STOP elif signal == "PAUSE": self.updateCallback(self.pkgName, self.progress, __("Download Pause"), APP_STATE_DOWNLOAD_PAUSE) return DOWNLOAD_STATUS_PAUSE # Otherwise wait download complete. else: # Get status list. statusList = self.server.aria2.tellActive() completedStatus = [] for status in statusList: gid = status['gid'] self.downloadStatus[gid] = int(status['completedLength']) completedStatus.append(status['status'] == 'complete') # Get current download length. currentLength = sum(self.downloadStatus.values()) # Get download speed. if self.cacheLength == 0: downloadSpeed = 0 else: downloadSpeed = currentLength - self.cacheLength / self.updateInterval # Store cache length. self.cacheLength = currentLength # Increases retry ticker if download speed is zero. if downloadSpeed == 0: self.retryTicker += 1 # Init retry ticker if download speed is not zero. else: self.retryTicker = 0 # Get progress. if self.totalLength == 0: self.progress = 0 else: self.progress = int(currentLength * 100 / self.totalLength) # Update status. self.updateCallback(self.pkgName, self.progress, utils.formatFileSize(downloadSpeed) + "/s") # Whether all download complete. downloadCompleted = all(completedStatus) link_success = True # Link archives/pkgName/*.deb to archives/ for pkg in pkgs: filename = get_filename(pkg.candidate) dst = os.path.join(self.archiveDir, filename) src = os.path.join(self.partialDir, filename) ctrl_file = ''.join([src, '.aria2']) # If control file exists, we assume download is not # complete. if os.path.exists(ctrl_file): continue try: # Making hard link because aria2c needs file in # partial directory to know download is complete # in the next invocation. os.rename(src, dst) except OSError, e: if e.errno != errno.ENOENT: print "Failed to move archive file", e link_success = False