diff options
| author | jvoisin | 2011-08-16 18:11:24 +0200 |
|---|---|---|
| committer | jvoisin | 2011-08-16 18:11:24 +0200 |
| commit | 4bd3e47da02fde08acfada1795cc55170abdb00a (patch) | |
| tree | f8c7aa5fd5e1b07a28b350c5ded8125ef2467c51 /lib/misc.py | |
| parent | baf8e080125614326ba9c96ca8f2404fd12b050e (diff) | |
setup.py now works !
Diffstat (limited to 'lib/misc.py')
| -rw-r--r-- | lib/misc.py | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/lib/misc.py b/lib/misc.py deleted file mode 100644 index fdf53b2..0000000 --- a/lib/misc.py +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | ''' | ||
| 2 | Care about misc formats | ||
| 3 | ''' | ||
| 4 | |||
| 5 | import parser | ||
| 6 | |||
| 7 | from bencode import bencode | ||
| 8 | #import bencode | ||
| 9 | |||
| 10 | |||
| 11 | class TorrentStripper(parser.GenericParser): | ||
| 12 | ''' | ||
| 13 | Represent a torrent file with the help | ||
| 14 | of the bencode lib from Petru Paler | ||
| 15 | ''' | ||
| 16 | def __init__(self, filename, parser, mime, backup, add2archive): | ||
| 17 | super(TorrentStripper, self).__init__(filename, parser, mime, | ||
| 18 | backup, add2archive) | ||
| 19 | self.fields = ['comment', 'creation date', 'created by'] | ||
| 20 | |||
| 21 | def is_clean(self): | ||
| 22 | ''' | ||
| 23 | Check if the file is clean from harmful metadatas | ||
| 24 | ''' | ||
| 25 | with open(self.filename, 'r') as f: | ||
| 26 | decoded = bencode.bdecode(f.read()) | ||
| 27 | for key in self.fields: | ||
| 28 | try: | ||
| 29 | if decoded[key] != '': | ||
| 30 | return False | ||
| 31 | except: | ||
| 32 | pass | ||
| 33 | return True | ||
| 34 | |||
| 35 | def get_meta(self): | ||
| 36 | ''' | ||
| 37 | Return a dict with all the meta of the file | ||
| 38 | ''' | ||
| 39 | metadata = {} | ||
| 40 | with open(self.filename, 'r') as f: | ||
| 41 | decoded = bencode.bdecode(f.read()) | ||
| 42 | for key in self.fields: | ||
| 43 | try: | ||
| 44 | if decoded[key] != '': | ||
| 45 | metadata[key] = decoded[key] | ||
| 46 | except: | ||
| 47 | pass | ||
| 48 | return metadata | ||
| 49 | |||
| 50 | def remove_all(self): | ||
| 51 | ''' | ||
| 52 | Remove all the files that are compromizing | ||
| 53 | ''' | ||
| 54 | with open(self.filename, 'r') as f: | ||
| 55 | decoded = bencode.bdecode(f.read()) | ||
| 56 | for key in self.fields: | ||
| 57 | try: | ||
| 58 | decoded[key] = '' | ||
| 59 | except: | ||
| 60 | pass | ||
| 61 | with open(self.output, 'w') as f: # encode the decoded torrent | ||
| 62 | f.write(bencode.bencode(decoded)) # and write it in self.output | ||
| 63 | self.do_backup() | ||
