Commit f8e34ed0 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Calcul de la taille par station.

parent 0f50cbcc
......@@ -32,7 +32,7 @@ def dict_dumper(dict):
def scan_volume(path):
"""
Scanne un volume indiqué par son chemin (path).
La fonction lance une commande "du -d2 path" et analyse chaque ligne renvoyée.
La fonction lance une commande "du -d3 path" et analyse chaque ligne renvoyée.
Elle renvoie une liste de dictionnaires :
[ {year: 2011, network: 'G', size: '100', files: '14'}, ...]
"""
......@@ -41,7 +41,7 @@ def scan_volume(path):
logger.debug("Volume %s"%(volume))
# TODO mettre le niveau de profondeur (2) en option
starttime = datetime.datetime.now()
lines = subprocess.check_output(["du", "--exclude", ".snapshot", "-d2", volume]).decode("utf-8").splitlines()
lines = subprocess.check_output(["du", "--exclude", ".snapshot", "-d3", volume]).decode("utf-8").splitlines()
logger.debug("Volume scanned in %s"%(datetime.datetime.now() - starttime))
for l in lines:
logger.debug(l)
......@@ -49,10 +49,10 @@ def scan_volume(path):
# On ne garde que le chemin qui nous intéresse
path = path.replace(volume,'').split('/')
# Ne pas considérer le seul chemin de niveau 1
if len(path) == 2:
if len(path) == 3:
logger.debug(f"path : {path}")
logger.debug(f"size : {size}")
data.append({'year': path[0], 'network': path[1], 'size': size})
data.append({'year': path[0], 'network': path[1], 'station': path[2], 'size': size})
return data
......
import pytest
from random import getrandbits
from random import getrandbits, choices
import string
import subprocess
from resifdatareporter import resifdatareporter
import yaml
from pprint import pprint
with open('config.yml.example', 'r') as ymlfile:
......@@ -24,17 +26,22 @@ def sds(tmpdir_factory):
d = tmpdir_factory.mktemp("%s/%d"%(t,y), numbered=False)
for i in ['G', 'FR', 'MT']:
d = tmpdir_factory.mktemp("%s/%d/%s"%(t, y, i), numbered=False)
station = ''.join(choices(string.ascii_uppercase + string.digits, k=4))
d = tmpdir_factory.mktemp("%s/%d/%s/%s"%(t, y, i,station), numbered=False)
size = getrandbits(12)
subprocess.call(['dd', 'if=/dev/zero', "of=%s/%s/%d/%s/file0"%(tmpdir_factory.getbasetemp(),t, y, i),"count=%d"%(size)])
subprocess.call(['dd', 'if=/dev/zero', "of=%s/%s/%d/%s/%s/file0"%(tmpdir_factory.getbasetemp(),t, y, i, station),"count=%d"%(size)])
pprint("Creating file %s/%s/%d/%s/%s/file0"%(tmpdir_factory.getbasetemp(),t, y, i, station))
return tmpdir_factory.getbasetemp()
def test_scan_volume(sds):
print(sds)
rd = resifdatareporter.scan_volume(sds+"/bud")
print(rd)
pprint(rd)
assert len(rd) > 0
for i in rd:
pprint(i)
assert int(i['size']) > 0
# on pourrait faire des asserts plus compliqués mais bon ...
def test_scan_volumes_well_formed_parameter(sds):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment