change of stderr/stdout strategy

This commit is contained in:
q
2017-02-25 21:22:51 +02:00
parent 1a2bfdf8bd
commit 496bd5c8ff

View File

@@ -161,29 +161,29 @@ def checkdb(options):
print_stderr("----\nDiffering files:") print_stderr("----\nDiffering files:")
pad=str(max([len(x[0]) for x in differing])) pad=str(max([len(x[0]) for x in differing]))
for f in differing: for f in differing:
print_stderr(("%-"+pad+"s (%s %7s => %s %7s)")%(f[0],humanize_date(f[3]),humanize_size(f[2]), print(("%-"+pad+"s (%s %7s => %s %7s)")%(f[0],humanize_date(f[3]),humanize_size(f[2]),
humanize_date(os.path.getmtime(f[0])), humanize_date(os.path.getmtime(f[0])),
humanize_size(os.path.getsize(f[0])))) humanize_size(os.path.getsize(f[0]))))
if len(missing)>0: if len(missing)>0:
print_stderr("----\nMissing files:") print("----\nMissing files:")
pad=str(max([len(x[0]) for x in missing])) pad=str(max([len(x[0]) for x in missing]))
for f in missing: for f in missing:
print_stderr(("%-"+pad+"s (%s %7s)")%(f[0],humanize_date(f[3]),humanize_size(f[2]))) print(("%-"+pad+"s (%s %7s)")%(f[0],humanize_date(f[3]),humanize_size(f[2])))
(added,changed)=has_changes_additions(db,options,False) (added,changed)=has_changes_additions(db,options,False)
if len(added)>0: if len(added)>0:
print_stderr("----\nAdded files:") print("----\nAdded files:")
pad=str(max([len(x[0]) for x in added])) pad=str(max([len(x[0]) for x in added]))
for f in added: for f in added:
print_stderr(("%-"+pad+"s (%s %7s)")%(f, print(("%-"+pad+"s (%s %7s)")%(f,
humanize_date(os.path.getmtime(f)), humanize_date(os.path.getmtime(f)),
humanize_size(os.path.getsize(f)))) humanize_size(os.path.getsize(f))))
print_stderr("----\nFile check summary:") print("----\nFile check summary:")
print_stderr("Database modified: %s"%(humanize_date(os.path.getmtime(options.sqlfile)),)) print("Database modified: %s"%(humanize_date(os.path.getmtime(options.sqlfile)),))
print_stderr("Checksum matches : %d"%(OK_count,)) print("Checksum matches : %d"%(OK_count,))
print_stderr("Checksum mismatch: %d"%(len(differing),)) print("Checksum mismatch: %d"%(len(differing),))
print_stderr("Files missing : %d"%(len(missing),)) print("Files missing : %d"%(len(missing),))
print_stderr("Files added : %d"%(len(added),)) print("Files added : %d"%(len(added),))
def clean_dirs(dirs): def clean_dirs(dirs):
@@ -328,11 +328,11 @@ def get_md5(filename,fullfile=False):
md5 = hashlib.md5() md5 = hashlib.md5()
with open(filename,'rb') as f: with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(block_size), b''): for chunk in iter(lambda: f.read(block_size), b''):
sys.stdout.write('\r %s (%02d%%)'%(ANIM[anim_i%anim_len],int(anim_i*percents_per_block))) sys.stderr.write('\r %s (%02d%%)'%(ANIM[anim_i%anim_len],int(anim_i*percents_per_block)))
sys.stdout.flush() sys.stderr.flush()
anim_i+=1 anim_i+=1
md5.update(chunk) md5.update(chunk)
sys.stdout.write('\r ') sys.stderr.write('\r ')
return md5.hexdigest() return md5.hexdigest()
return hashlib.md5(open(filename,'rb').read(DEFAULT_CHUNK)).hexdigest() return hashlib.md5(open(filename,'rb').read(DEFAULT_CHUNK)).hexdigest()