def move_to_dest_dir(self): try: shutil.move(self.move_source, self.move_dest) if self.verbose: logger.info('extracted archive to {}.'.format(self.move_dest)) except Exception as e: logger.error(e) msg = 'Moving the extracted data to \'{}\' failed.' raise PathError(msg.format(self.move_dest.decode('utf-8')))
def _download_file(self, link, name): downloader = Downloader(link) try: downloader.retrieve() except tek.errors.NotEnoughDiskSpace as e: logger.error(e) else: state = 'complete' if downloader.success else 'failed' logger.info('') logger.info('Download {}: {}'.format(state, name))
def _exec(self, cmdline, verbose): if verbose: logger.info('executing {}'.format(' '.join(cmdline))) if self.pipe: stdout = stderr = subprocess.PIPE else: stdout, stderr = sys.stdout, sys.stderr proc = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr) self.exitval = proc.wait() if self.pipe: self.output = proc.stdout.readlines()
def search(self, **kw): try: for i in itertools.count(): try: data = self._request(i, **kw).content for url in self._extract_urls(data): yield url except requests.Timeout: logger.warn('Timeout in search!') except (requests.RequestException, NoMoreResults) as e: logger.info('Search aborted: {}'.format(e))
def retrieve(self): forever = self._retry < 0 tries = self._retry retry = lambda: forever or tries >= 0 while retry(): tries -= 1 try: self._prepare() return self._transfer() except (RequestException, socket.timeout) as e: action = 'Retrying in 5 seconds.' if retry() else 'Aborting.' logger.warning('Connection error: {}!'.format(e)) logger.info(action) if retry(): time.sleep(5)
def _wait_for_files(self): if not self._files and self._uris: logger.info('Files not synced yet. Waiting for 5 seconds.') time.sleep(5) return bool(self._files)
def add_command(self, cmd): """ run iptables process with given args """ assert (isinstance(cmd, Command)) logger.info(cmd.string) self.commands.append(cmd)
def __exit__(self, exc_type, exc_val, exc_tb): self._end = self._current if self._log and self.enabled: logger.info('{}: {}s'.format(self._label, self.time))
def print_all(self): logger.info(self._config.info)