checks the content of the last downloaded file, re match is saved to `lastCheck` :param rules: dict with names and rules to match (compiled regexp or strings) :param api_size: expected file size :param max_size: if the file is larger then it wont be checked
(self, rules, api_size=0, max_size=50000, delete=True, read_size=0)
| 527 | return self.lastDownload |
| 528 | |
| 529 | def checkDownload(self, rules, api_size=0, max_size=50000, delete=True, read_size=0): |
| 530 | """ checks the content of the last downloaded file, re match is saved to `lastCheck` |
| 531 | |
| 532 | :param rules: dict with names and rules to match (compiled regexp or strings) |
| 533 | :param api_size: expected file size |
| 534 | :param max_size: if the file is larger then it wont be checked |
| 535 | :param delete: delete if matched |
| 536 | :param read_size: amount of bytes to read from files larger then max_size |
| 537 | :return: dictionary key of the first rule that matched |
| 538 | """ |
| 539 | lastDownload = fs_encode(self.lastDownload) |
| 540 | if not exists(lastDownload): return None |
| 541 | |
| 542 | size = stat(lastDownload) |
| 543 | size = size.st_size |
| 544 | |
| 545 | if api_size and api_size <= size: return None |
| 546 | elif size > max_size and not read_size: return None |
| 547 | self.log.debug("Download Check triggered") |
| 548 | f = open(lastDownload, "rb") |
| 549 | content = f.read(read_size if read_size else -1) |
| 550 | f.close() |
| 551 | #produces encoding errors, better log to other file in the future? |
| 552 | #self.log.debug("Content: %s" % content) |
| 553 | for name, rule in rules.iteritems(): |
| 554 | if type(rule) in (str, unicode): |
| 555 | if rule in content: |
| 556 | if delete: |
| 557 | remove(lastDownload) |
| 558 | return name |
| 559 | elif hasattr(rule, "search"): |
| 560 | m = rule.search(content) |
| 561 | if m: |
| 562 | if delete: |
| 563 | remove(lastDownload) |
| 564 | self.lastCheck = m |
| 565 | return name |
| 566 | |
| 567 | |
| 568 | def getPassword(self): |