Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. class Entry:
  2. def __init__(self):
  3. self.dupes = []
  4.  
  5. def add(self, l):
  6. self.dupes.append(l.split(" "))
  7.  
  8. def _parse(self, s):
  9. s = s.split(' ')[0] # remove the ' MB' suffix
  10. s = s.replace(',', '.') # change , into . for float(...) parsing
  11. try:
  12. return float(s)
  13. except:
  14. return 0.0
  15.  
  16.  
  17. def size(self):
  18. s = self.dupes[0][2] # 3rd field of the first 'line'
  19. return self._parse(s)
  20.  
  21. def name(self):
  22. return self.dupes[0][0]
  23.  
  24. def count(self):
  25. return len(self.dupes)
  26.  
  27. def __repr__(self):
  28. n = self.name()
  29. c = self.count()
  30. s = self.size()
  31. return '%s : %d * %d MB' % (n, c, s)
  32.  
  33. class Entry2(Entry):
  34. def add(self, l):
  35. fs = l.split(" ")
  36. self.n = fs[0]
  37. self.s = self._parse(fs[2])
  38. path = fs[1]
  39. date = fs[3]
  40. self.dupes.append((path, date))
  41.  
  42. def name(self):
  43. return self.n
  44.  
  45. def size(self):
  46. return self.s
  47.  
  48. def remap(lines, kind=Entry2):
  49. e = None
  50. for l in lines:
  51. if l.startswith('--------------'):
  52. yield e
  53. e = kind()
  54. continue
  55. else:
  56. e.add(l)
  57.  
  58. def main(f):
  59. with open(f, "r") as i:
  60. ls = i.readlines()
  61. yield from remap(ls)
  62.  
  63. F = "c:/Users/noob/Desktop/duplicate_marion.txt"
  64. es = main(F)
  65. total = sum(e.size() for e in es if e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement