Ajouté un script lua pour afficher la taille des fichiers dans le dossier du host, cela permet déjà de faire une première comparaison beaucoup plus rapide qu'avec le checksum sur le NodeMCU

This commit is contained in:
Christian Zufferey
2019-11-24 17:02:19 +01:00
parent 9c0ce19393
commit 0b6f71ca95
4 changed files with 71 additions and 70 deletions

View File

@@ -1,65 +0,0 @@
-- fonction dir() pour calculer le checksum de tous les fichiers sur le NodeMCU !
-- fonction dirfile(fichier) pour calculer le checksum d'un seul fichiers sur le NodeMCU !
print("\n dir2.lua zf191124.1343 \n")
function dir2()
function calc_chksum_file(name_file)
print(name_file)
size_file = 1 chksum_file = 0
local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
if size_file%100 == 0 then uart.write(0,".") end
end
f:close() print("")
end
function filec(k)
calc_chksum_file(k)
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
function dirc()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
calc_chksum_file(k)
zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
dir()
print("\nusage:")
print(" dir()")
print(" dirc()")
print(" filec('dir2.lua')")
end
dir2()
--[[
dir()
dirc()
filec("dir2.lua")
for k,v in pairs(_G) do print(k,v) end
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
]]

View File

@@ -3,15 +3,13 @@
README.md : 2841, 347247457
_secrets_energy.lua_ : 574, 14047690
_zremote_cmd.txt : 4225, 742020960
a.lua : 492, 9072034
_zremote_cmd.txt : 4416, 811416628
b.lua : 4289, 696634446
boot.lua : 451, 8092291
boot2.lua : 1581, 89772835
c.lua : 1023, 45354296
cat.lua : 522, 9721978
dir2.lua : 2504, 246241567
dir2.lua.zf191124.1436 : 1931, 139164369
flash_led_xfois.lua : 1131, 43977377
head.lua : 567, 11507510
initz.lua : 2159, 175035891
@@ -21,7 +19,7 @@ secrets_wifi.lua : 635, 15410620
set_time.lua : 879, 31173858
telnet_srv2.lua : 2760, 289194718
thost : 40, 43773
tnode : 1083, 34517179
tnode : 881, 22330813
upload_s.sh : 1913, 159132384
upload_t.sh : 1618, 109879609
web_srv2.lua : 2960, 297644504
@@ -32,6 +30,7 @@ z_page1.html : 443, 7731060
z_page2.html : 1867, 123937742
z_page3.html : 1415, 67091731
z_page4.html : 1660, 90364904
zz_host_dir.lua : 2001, 159551326
zz_host_dir2.lua : 2020, 162623430

View File

@@ -1,6 +1,5 @@
b.lua : 4289, 696634446
boot.lua : 451, 8092291
boot2.lua : 1581, 89772835
c.lua : 1023, 45354296
cat.lua : 522, 9721978
@@ -20,3 +19,4 @@ z_page1.html : 443, 7731060
z_page2.html : 1867, 123937742
z_page3.html : 1415, 67091731
z_page4.html : 1660, 90364904
~.

View File

@@ -0,0 +1,67 @@
#!/usr/local/bin/lua5.1
-- script lua à faire tourner sur le host pour la taille de tous les fichiers
-- du dossier en cours, donc PAS sur le NodeMCU !
-- source: https://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua (30%)
-- usage dans la console:
-- ./zz_host_dir.lua
--[[
./zz_host_dir.lua > thost
]]
-- usage dans Atom editor
-- il faut installer ceci: https://atom.io/packages/compare-files
-- puis sélectionner les deux fichiers dans l'explorateur à gauche puis CTRL+CMD+C
print("\n zz_host_dir.lua zf191124.1646 \n")
function calc_chksum_file(name_file)
size_file = 0 chksum_file = 0
local f = io.open(name_file, "r")
-- local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
-- chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
-- if size_file%100 == 0 then uart.write(0,".") end
end
f:close()
-- print(name_file)
end
function dirfile(k)
calc_chksum_file(k)
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
local pfile = io.popen("ls -1r *.lua *.html")
for k in pfile:lines() do
-- local pfile = file.list()
-- for k,v in pairs(pfile) do
calc_chksum_file(k)
if (size_file ~= 1) and (chksum_file ~= 1) then
zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file
end
end
pfile:close()
table.sort(zdir)
for i=1, #zdir do
print(zdir[i])
end
size_file=nil chksum_file=nil k=nil
end
dir()
print("\n\nRappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C\n")
--[[
dir()
dirfile("dir2.lua")
for k,v in pairs(_G) do print(k,v) end
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
]]