/ gsync.py
gsync.py
 1  import os
 2  
 3  from init import *
 4  import settings
 5  import functions
 6  import shutil
 7  
 8  args = init_args()
 9  
10  # Get source file list and write to file
11  file = open(settings.sourceOutput, 'a')
12  for sourceFiles in functions.listDirs(args.source):
13      hashedList = functions.buildHashedFileList(sourceFiles)
14      file.writelines(hashedList)
15  
16  file.close()
17  
18  # Get destination file list and write to file
19  file = open(settings.destinationOutput, 'a')
20  for sourceFiles in functions.listDirs(args.destination):
21      hashedList = functions.buildHashedFileList(sourceFiles)
22      file.writelines(hashedList)
23  
24  file.close()
25  
26  # Begin copy to destination when source hash does not exist
27  # anywhere under the destination tree and only of the appropriate
28  # file types chosen.
29  
30  fileMeetsSyncCriteria = functions.checkAndResolveType(args, settings.sourceOutput)
31  
32  if fileMeetsSyncCriteria:
33      with open(settings.sourceOutput, "r", buffering=100) as sourceFileList:
34          for sourceFile in sourceFileList:
35              sourceFileHash, sourceFilePath = sourceFile.split('\t')
36              fileSynced = functions.isFileSynced(sourceFileHash, settings.destinationOutput)
37  
38              if not fileSynced:
39                  destination = args.destination
40  
41                  if not destination.endswith('/'):
42                      destination = destination + '/'
43  
44                  sourceFilePath = sourceFilePath.strip('\n')
45                  shutil.copy2(sourceFilePath, destination)
46  
47  # if fileMeetsSyncCriteria:
48  #     fileSynced = functions.isFileSynced(settings.sourceOutput, settings.sourceOutput)
49  
50      # call the sync function, issue, only returning true/false above, need paths
51  
52  
53  # functions.sync()
54  
55  stop = True
56  
57  
58  # os.system("rm ")
59  print("Finished copy/sync")
60  print(__name__)