77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
|
|
#!/usr/bin/env python
|
||
|
|
|
||
|
|
import enum
|
||
|
|
import itertools
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
import re
|
||
|
|
import sys
|
||
|
|
from dataclasses import KW_ONLY, dataclass, field
|
||
|
|
from functools import partial, partialmethod
|
||
|
|
from operator import itemgetter
|
||
|
|
from tabnanny import verbose
|
||
|
|
from time import sleep
|
||
|
|
|
||
|
|
import defl
|
||
|
|
from defl import CLIError, DotDict, Null, Path, Undefined, cl, log
|
||
|
|
from defl._assert_ import Assert
|
||
|
|
from defl._typing_ import *
|
||
|
|
from defl.testing_ import Tester
|
||
|
|
from defl.lsblk_ import *
|
||
|
|
|
||
|
|
tester = Tester(name=__file__)
|
||
|
|
|
||
|
|
def rec(d, ind=0):
|
||
|
|
for i in d:
|
||
|
|
# print(' ' * ind, i.name, [i.name for i in i.children])
|
||
|
|
rec(i.children, ind + 1)
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def lsblk():
|
||
|
|
r = Lsblk.Run()
|
||
|
|
rec(r.toList())
|
||
|
|
# log.info(r)
|
||
|
|
# log.info('r', lambda jc: jc.r)
|
||
|
|
assert isinstance(r, LsblkCollection)
|
||
|
|
k = next(r.toList())
|
||
|
|
assert isinstance(k, Lsblk)
|
||
|
|
assert isinstance(k.children, list)
|
||
|
|
for i in r.toList(r):
|
||
|
|
i.path
|
||
|
|
|
||
|
|
a = r.filter(lambda x: x.diskTree.has(Path('/dev/sda')))
|
||
|
|
Assert(next(a).path) == '/dev/sda'
|
||
|
|
|
||
|
|
a = r.filter(lambda x: x.diskTree.has(Path('/dev/disk/by-partlabel/efi')))
|
||
|
|
Assert(next(a).path) == '/dev/sda1'
|
||
|
|
|
||
|
|
a = r.filter(lambda x: x.diskTree.has(Path('/dev/disk/by-diskseq/1-part1')))
|
||
|
|
Assert(next(a).path) == '/dev/sda1'
|
||
|
|
|
||
|
|
# for i in list(itertools.chain(*([x for x in y] for y in r))):
|
||
|
|
# print(i.path)
|
||
|
|
# da
|
||
|
|
|
||
|
|
# for k, v in defl.getObjAsDict(r[0]).items():
|
||
|
|
# print(k, type(v))
|
||
|
|
|
||
|
|
# @tester.add()
|
||
|
|
# def df():
|
||
|
|
# r = Lsblk.Run()
|
||
|
|
# d = r.df()
|
||
|
|
# li(d)
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def diskTree():
|
||
|
|
dt = DiskTree(root=Path(1), byId=[Path(2)])
|
||
|
|
Assert(dt.has(Path(1))) == 'root'
|
||
|
|
Assert(dt.has(Path(2))) == 'byId'
|
||
|
|
a = DiskTree.Run()
|
||
|
|
log.info('a', lambda x: x.a)
|
||
|
|
|
||
|
|
log.info(tester.run())
|
||
|
|
tester.exitWithStatus()
|
||
|
|
|
||
|
|
# for i in ch:
|
||
|
|
# print(defl.printTable([[y for y in x] for x in ch], squareFill=True))
|