def errorHandler(self, text, err=None): ''' @summary: ハンドラがエラー発生時の処理を行います ''' self.last_text = text logger.error(err)
def __getAndSaveQuotes(self): ''' get and save data ''' while not self.stockQueue.empty(): item = self.stockQueue.get_nowait() stock = item[0] start = item[1] end = item[2] try: quotes = self.__getSaveOneStockQuotes(stock, start, end) except KeyboardInterrupt as excp: logger.error("Interrupted while processing %s: %s" % (stock.symbol, excp)) self.failed.append(stock) raise excp except BaseException as excp: logger.error("Error while processing %s: %s" % (stock.symbol, excp)) #logger.debug(traceback.format_exc()) self.failed.append(stock) else: logger.info("Success processed %s" % stock.symbol) self.sqlDAM.writeQuotes(stock.symbol, quotes) stock.price = quotes[-1].close stock.lastUpdate = datetime.datetime.now() self.sqlDAM.writeStock(stock) self.counter += 1 if 0 == self.counter % (self.poolsize if self.poolsize < 10 else 10): self.sqlDAM.commit() logger.info("Processed %d, remain %d." % (self.counter, self.stockQueue.qsize())) self.succeeded.append(stock) finally: self.stockQueue.task_done()
def _run(self, text, path): ''' @summary: テキストに対してハンドラ処理を行い、 結果をクリップボートにセットします @param text: クリップボートの中身 @param path: ハンドラモジュールのパス ''' result = None try: self.setClipBefore(text) mod = self.loadModule(path) self.last_handler.set_handler(mod.handler, path) try: result = self._parseClipText(mod.handler(text)) except Exception, err: self.errorHandler(text, err) except AttributeError: logger.error("Perhaps don't have your selected handler 'handler' method ?") if result is not None: try: self.last_text = result self.clipboard_set(result) self.setClipAfter(result) except Exception, err: logger.error(err)
def schedule(self, path, recursive=False): path = abspath(path) try: # インデックス追加処理 self.scan_path(path, recursive) self.watch_path[path] = Observer.schedule(self, self.event_handler, path, recursive) except NotFoundPathError, err: logger.error(err) raise
def downloadStocks(self, symbols, append=True, threads=5): stocks = [] for symbol in symbols: s = self.sqlDAM.readStock(symbol) if s is not None: stocks.append(s) else: logger.error("stock %s not found in database") return self.__downloadStocks(stocks, append=append, threads=threads)
def run(self): ''' @summary: ハンドラ処理の実行メソッドです ''' try: text = self.clipboard_get() mod_path = self.getPluginPath() if self.last_text != text or self.last_handler.path != mod_path: self._run(text, mod_path) except TclError, err: logger.error(err)
def main(): init() # Parse params if len(sys.argv) != 4: prompt.show(sys.argv[0]) exit(1) website = url.urlFormater(sys.argv[1]) threadNumber = int(sys.argv[2]) timeout = float(sys.argv[3]) if timeout == 0: logger.error("[-] Your timeout can not be equal with 0!") prompt.show(sys.argv[0]) exit(1) listFile = open('list.txt', 'r') dispatcher.start(website, threadNumber, listFile, timeout) output.asTable() output.asCSV("result.csv")
def setUpToolBar(self, frame): ''' @summary: ツールバーを作成します ''' toolbar = Tk.Frame(frame) for image, command in ( ("images/gif/Refresh.gif", self.refreshList), # handlerリストの更新 ("images/gif/Red Mark.gif", self.selectHandler), # ハンドラの選択 ("images/gif/Add.gif", self.loadPlugin), # プラグインのインポート ("images/gif/Folder.gif", self.changePluginPath) # プラグインディレクトリの変更を行います ): image = join(dirname(dirname(__file__)), image) try: image = Tk.PhotoImage(file=image) self.toolbar_images.append(image) button = Tk.Button(toolbar, image=image, command=command) button.grid(row=0, column=len(self.toolbar_images) -1) except Tk.TclError, err: logger.error(err)
def analyze_file(self, path): ''' @summary: ファイル解析 スレッドに委託するならこのメソッドをワーカーにする ''' try: index = ChildIndex() # mimeがGC時のバグがある模様 mtype = self.mime.from_file(path) if mtype in EXCLUDE_MIME: index.add(path, os.path.basename(path)) logger.debug("IGNORE: %s" % path) # 各パターンごとに判定して、テキスト読取 elif pattern['pdf'].search(mtype): # PDFからテキストを抽出してインデックス追加の第二引数に指定 index.add(path, os.path.basename(path)) logger.debug("PDF '%s'" % path) else: index.add(path) logger.debug("ADD Index '%s'" % path) except Exception, err: logger.error(err)