Created
November 10, 2015 11:18
-
-
Save xgiovio/9e3eed6032c91efa064e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'xgiovio' | |
localpath = "localpath" # I:\\Backup NAS\\All\Works\\life\\ | |
swift_container = "default" # default | |
prefix = "path/" # life/ | |
import swiftclient | |
import os, sys | |
localfiles = {} | |
remotefiles = {} | |
difffiles = {} | |
for root, dirs, files in os.walk(localpath, topdown=True): | |
for name in files: | |
localfiles[os.path.join(root.replace(localpath,""), name)]=int(os.stat(os.path.join(root, name)).st_size) | |
''' | |
for name in dirs: | |
print(os.path.join(root, name)) | |
''' | |
''' | |
print("___________") | |
for files, sizes in localfiles.items(): | |
print(files,sizes) | |
''' | |
print ("Files locali " + str(len(localfiles))) | |
print ("Scaricando lista remota ... ") | |
swift_conn = swiftclient.client.Connection(authurl='http://www.auth', user='t', key='t',) | |
headers,containers = swift_conn.get_account() | |
headers,objects = swift_conn.get_container(swift_container, prefix =prefix,full_listing=True ) | |
swift_conn.close() | |
byte0real = 0 | |
byte0manifest = 0 | |
for o in objects : | |
if o["content_type"] != "application/directory": | |
if int(o["bytes"]) == 0 : | |
print ("Requesting metadata for 0byte file " + o["name"] ) | |
oheaders = swift_conn.head_object(swift_container,o["name"]) | |
if "x-object-manifest" in oheaders.keys(): | |
print ("0byte file " + o["name"] + " e' un large file" ) | |
o["bytes"] = oheaders["content-length"] | |
byte0manifest = byte0manifest + 1 | |
else: | |
print ("0byte file " + o["name"] + " e' un file normale" ) | |
byte0real = byte0real + 1 | |
remotefiles[(o["name"].replace(prefix,"")).replace("/","\\")]=int(o["bytes"]) | |
''' | |
print("___________") | |
for files, sizes in remotefiles.items(): | |
print(files,sizes) | |
''' | |
print ("Files remoti " + str(len(remotefiles))) | |
skipped = 0 | |
for lname in localfiles.keys(): | |
if lname not in remotefiles.keys() or localfiles[lname] != remotefiles[lname]: | |
if "Thumbs.db" not in lname and ".DS_Store" not in lname : | |
difffiles[lname] = localfiles[lname] | |
else: | |
print("Skipped " + lname ) | |
skipped = skipped + 1 | |
print("___________Differenze___________") | |
print ("Files locali " + str(len(localfiles))) | |
print ("Skipped " + str(skipped)) | |
print ("Files locali - skipped " + str(len(localfiles) - skipped)) | |
print ("Files remoti " + str(len(remotefiles))) | |
print ("Files 0byte reali " + str(byte0real)) | |
print ("Files 0byte large " + str(byte0manifest)) | |
for files, sizes in difffiles.items(): | |
print(files,sizes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment