def pop(self, *args): """Pop an item. Should probably not be started while queue is running. Returns True if there queue was started, False if there were no items to be transferred. """ iter = self.store.get_waiting_iter() if iter: # set status to 'transfering' self.store.set_value(iter, QueueStore.I_STATUS, 1) # remember item and iter locally self._item = self.store.get_value(iter, QueueStore.I_REMOTE) self._iter = iter # get local path local = self.store.get_value(iter, QueueStore.I_LOCAL) direction = self.store.get_value(iter, QueueStore.I_DIRECTION) if direction == QueueStore.DR_DOWN: # create dir if it doesn't exist if os.path.sep in local and not os.path.isdir(os.path.dirname(local)): os.makedirs(os.path.dirname(local)) # now transfer it app.debug("Downloading %s to %s" % (self._item.filename, local), "queue") self.set_statusbar("Downloading") self.ftp.download(self._item, local, rest=True) elif direction == QueueStore.DR_UP: app.debug("Uplading %s to %s" % (local, self._item.filename)) self.set_statusbar("Uploading") self.ftp.upload(local, self._item) return True else: return False
def update_size(self, add=None): """Sets self.total_size. If add is set, just add it to total_size.""" if add: self.total_size += add else: c = 0 for it in self.iters(): c += self.get_value(it, self.I_SIZE) self.total_size = c app.debug( "Total queue size: %s" % units(self.total_size), "queue" ) return self.total_size
def select_site(self, cb): site = cb.get_active_text() app.debug("Site selected: " + site, "connectdialog") cfgstr = 'site:'+site host = self.config.get(cfgstr, 'hostname') if self.config.has_option(cfgstr, 'port'): port = self.config.getint(cfgstr, 'port') if port != 21: host += ":%s"%str(port) user = self.config.get(cfgstr, 'username') self.entry_host.set_text(host) self.entry_user.set_text(user) if self.config.has_option(cfgstr, 'password'): p = self.config.get(cfgstr, 'password') self.entry_password.set_text(p) else: self.entry_password.set_text('') # de-activate checkbutton_use_ssl if False if self.config.has_option(cfgstr, 'use_ssl'): self.checkbutton_use_ssl.set_active( self.config.getboolean(cfgstr, 'use_ssl')) # activate checbutton_force_ssl if set if self.config.has_option(cfgstr, 'force_ssl'): self.checkbutton_force_ssl.set_active( self.config.getboolean(cfgstr, 'force_ssl')) # set passive if self.config.has_option(cfgstr, 'passive'): self.checkbutton_passive.set_active( self.config.getboolean(cfgstr, 'passive'))
def append_item(self, fr, to, status=0): """Appends one item to the queue.""" if isinstance(fr, ftp.RemoteFile) and isinstance(to, str): # a download self.store.append(fr, to, direction=0, status=status) app.debug("Adding download item: %s to %s" % (fr, to), "queue") elif isinstance(to, ftp.File) and isinstance(fr, str): # upload self.store.append(to, fr, direction=1, status=status) app.debug("Adding upload from %s to %s" % (fr, to), "queue") else: raise ValueError, "Unknown from/to types. fr: %s to: %s" % \ (type(fr), type(to)) self.save() if self.menuitem_run.get_active() and not self.ftp.busy(): app.debug("Popping item since queue is not running.", "queue") self.pop()
#!/usr/bin/env python import app if __name__ == '__main__': app.debug()
def read(self): read = SafeConfigParser.read(self, [os.path.join(app.data_dir, "default.config"), app.config_file]) app.debug("Read: %s"%' '.join(read), "config")
def write(self): fd = open(app.config_file, 'w') SafeConfigParser.write(self, fd) app.debug("Configuration written", "config") del fd
def ftp_unhandled_exception(self, job, exception): app.debug("Unhandled exception in FTP thread: Job: %s Exception: %s" % \ (job, exception), "queue")
def ftp_cwd_error(self, msg): app.debug("Could not CWD to directory!", "queue")
def ftp_sending(self, data): app.debug(data, "queue-ftp")
def ftp_received(self, data): app.debug(data, "queue-ftp")
from app import debug debug()