(self, pyfile)
| 25 | ("jeix", "jeix@hasnomail.com")] |
| 26 | |
| 27 | def decrypt(self, pyfile): |
| 28 | try: |
| 29 | encoding = codecs.lookup(self.config.get('encoding')).name |
| 30 | |
| 31 | except Exception: |
| 32 | encoding = "utf-8" |
| 33 | |
| 34 | fs_filename = fs_encode(pyfile.url) |
| 35 | txt = codecs.open(fs_filename, 'r', encoding) |
| 36 | curPack = "Parsed links from %s" % pyfile.name |
| 37 | packages = {curPack: [], } |
| 38 | |
| 39 | for link in txt.readlines(): |
| 40 | link = link.strip() |
| 41 | |
| 42 | if not link: |
| 43 | continue |
| 44 | |
| 45 | if link.startswith(";"): |
| 46 | continue |
| 47 | |
| 48 | if link.startswith("[") and link.endswith("]"): |
| 49 | #: New package |
| 50 | curPack = link[1:-1] |
| 51 | packages[curPack] = [] |
| 52 | continue |
| 53 | |
| 54 | packages[curPack].append(link) |
| 55 | |
| 56 | txt.close() |
| 57 | |
| 58 | #: Empty packages fix |
| 59 | for key, value in packages.items(): |
| 60 | if not value: |
| 61 | packages.pop(key, None) |
| 62 | |
| 63 | if self.config.get('flush'): |
| 64 | try: |
| 65 | txt = open(fs_filename, 'wb') |
| 66 | txt.close() |
| 67 | |
| 68 | except IOError: |
| 69 | self.log_warning(_("Failed to flush list")) |
| 70 | |
| 71 | for name, links in packages.items(): |
| 72 | self.packages.append((name, links, name)) |
no test coverage detected