ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/iTunesDirSync.py
Revision: 744
Committed: Tue Apr 13 21:40:41 2021 UTC (4 years, 11 months ago) by nino.borges
Content type: text/x-python
File size: 3429 byte(s)
Log Message:
Updated all tools libs to be python 3 compatible. 

File Contents

# User Rev Content
1 ninoborges 8 """
2    
3     iTunesDirSync.py
4    
5     Created by:
6     Emanuel Borges
7     03.30.209
8    
9    
10     """
11    
12     import os, NinoGenTools
13    
14     class DirDictionary:
15     def __init__ (self, reportType = 'Simple'):
16     self.reportType = reportType
17     if reportType == 'Complex':
18     self.hasher = NinoGenTools.HashFileContents('md5')
19    
20     def CreateDictionary(self, topLevelDir):
21     self.matrix = {}
22     self.hashMatrix = {}
23     for contents in os.walk(topLevelDir):
24     (currentDir, dirNames, listOfFiles) = contents
25     for file in listOfFiles:
26     if self.reportType == 'Complex':
27     hashVal = self.hasher.HashFile(os.path.join(currentDir, file))
28     self.hashMatrix[os.path.join(currentDir, file)] = hashVal
29 nino.borges 744 if file in list(self.matrix.keys()):
30 ninoborges 8 self.matrix[file].append(os.path.join(currentDir, file))
31     else:
32     self.matrix[file] = [os.path.join(currentDir, file)]
33     def DuplicateReport(self):
34     dupCount = NinoGenTools.Counter()
35    
36 nino.borges 744 for i in list(self.matrix.keys()):
37 ninoborges 8 instanceCount = len(self.matrix[i])
38     ## Query these "Dups" against the hash table and remove them if they're not.
39    
40     if instanceCount > 1:
41     dupCount.inc()
42 nino.borges 744 print("-"*25)
43     print("You have %d versions of %s" %(instanceCount, i))
44 ninoborges 8 for dir in self.matrix[i]:
45 nino.borges 744 print(dir)
46     print("-"*25)
47     print()
48     print("*"*25)
49     print("You have a total of %d duplicates" %dupCount.count)
50 ninoborges 8
51    
52     class DirDictionaryComparisonTool:
53     def __init__(self):
54     """Tools for comparing two DirDictionary objects. Dont forget that they're objects
55     not just dicts"""
56     pass
57     def FindDifferences(self,localComputer, otherComputer):
58     """(localComputer DirDictionary, otherComputer DirDictionary)
59     Finds the differences between 2 DirDictionaries"""
60     localComputerMissingCount = NinoGenTools.Counter()
61     otherComputerMissingCount = NinoGenTools.Counter()
62     localMissingFileList =[]
63     otherMissingFileList =[]
64 nino.borges 744 for i in list(localComputer.matrix.keys()):
65     if i in list(otherComputer.matrix.keys()):
66 ninoborges 8 pass
67     else:
68     otherMissingFileList.append(i)
69 nino.borges 744 for x in list(otherComputer.matrix.keys()):
70     if x in list(localComputer.matrix.keys()):
71 ninoborges 8 pass
72     else:
73     localMissingFileList.append(x)
74    
75 nino.borges 744 print("*"*25)
76     print("You are missing %d files, that the other computer has."%len(localMissingFileList))
77     print()
78     input("Press any key to see a list:")
79     print("-"*25)
80 ninoborges 8 for fileName in localMissingFileList:
81     for absFilePath in otherComputer.matrix[fileName]:
82 nino.borges 744 print(absFilePath)
83     print("-"*25)
84     print("*"*25)
85     print("The other computer is missing %d files, that you have."%len(otherMissingFileList))
86     print()
87     input("Press any key to see a list:")
88     print("-"*25)
89 ninoborges 8 for fileName in otherMissingFileList:
90     for absFilePath in localComputer.matrix[fileName]:
91 nino.borges 744 print(absFilePath)
92     print("-"*25)
93 ninoborges 8