mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-07-01 07:22:45 +00:00
fix bugs in size calculation
This commit is contained in:
parent
c71008f008
commit
b1ae8488ac
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# requires: coreutils
|
# requires: coreutils
|
||||||
[[ -f "$1" ]] || exit
|
[[ -f "$1" ]] || exit 0
|
||||||
sz=$(cat $1)
|
sz=$(cat $1)
|
||||||
sz=$((0$sz))
|
sz=$((0$sz))
|
||||||
echo "size-sum:" $(numfmt --to=iec $sz)
|
echo "size-sum:" $(numfmt --to=iec $sz)
|
||||||
|
20
yum-sync.py
20
yum-sync.py
@ -21,21 +21,23 @@ REPO_STAT = {}
|
|||||||
def calc_repo_size(path: Path):
|
def calc_repo_size(path: Path):
|
||||||
dbfiles = path.glob('repodata/*primary.sqlite*')
|
dbfiles = path.glob('repodata/*primary.sqlite*')
|
||||||
with tempfile.NamedTemporaryFile() as tmp:
|
with tempfile.NamedTemporaryFile() as tmp:
|
||||||
|
dec = None
|
||||||
|
dbfile = None
|
||||||
for db in dbfiles:
|
for db in dbfiles:
|
||||||
with db.open('rb') as f:
|
dbfile = db
|
||||||
suffix = db.suffix
|
suffix = db.suffix
|
||||||
if suffix == '.bz2':
|
if suffix == '.bz2':
|
||||||
tmp.write(bz2.decompress(f.read()))
|
dec = bz2.decompress
|
||||||
break
|
|
||||||
elif suffix == '.gz':
|
elif suffix == '.gz':
|
||||||
tmp.write(gzip.decompress(f.read()))
|
dec = gzip.decompress
|
||||||
break
|
elif suffix == '.sqlite':
|
||||||
elif suffix == '':
|
dec = lambda x: x
|
||||||
tmp.write(f.read())
|
if dec is None:
|
||||||
break
|
|
||||||
else:
|
|
||||||
print(f"Failed to read DB from {path}: {dbfiles}", flush=True)
|
print(f"Failed to read DB from {path}: {dbfiles}", flush=True)
|
||||||
return
|
return
|
||||||
|
with db.open('rb') as f:
|
||||||
|
tmp.write(dec(f.read()))
|
||||||
|
tmp.flush()
|
||||||
|
|
||||||
conn = sqlite3.connect(tmp.name)
|
conn = sqlite3.connect(tmp.name)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user