mirror of
https://github.com/vale981/dirkules
synced 2025-03-05 09:21:38 -05:00
partitionen können zur db mit Link auf Drive hinzugefügt werden
This commit is contained in:
parent
5b551f6155
commit
2efebbbf6e
9 changed files with 42 additions and 9 deletions
|
@ -87,7 +87,7 @@ def part_for_disk(device):
|
|||
parts = []
|
||||
partdict = list()
|
||||
keys = ['name', 'label', 'fs', 'size', 'uuid', 'mount']
|
||||
|
||||
device = "/dev/" + device
|
||||
lsblk = subprocess.Popen(
|
||||
["lsblk " + device + " -l -b -o NAME,LABEL,FSTYPE,SIZE,UUID,MOUNTPOINT"],
|
||||
stdout=subprocess.PIPE,
|
||||
|
@ -122,9 +122,11 @@ def part_for_disk(device):
|
|||
for part in parts:
|
||||
values = list()
|
||||
for start, end in zip(element_length, element_length[1:]):
|
||||
values.append(part[start:(end-1)].strip())
|
||||
values.append(part[start:(end - 1)].strip())
|
||||
partdict.append(dict(zip(keys, values)))
|
||||
print(partdict)
|
||||
|
||||
return partdict
|
||||
|
||||
|
||||
def getPartitions(device):
|
||||
partDict = [] # ist eine Liste, enthält für jede part ein dict
|
20
dirkules/manager/driveManager.py
Normal file
20
dirkules/manager/driveManager.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from dirkules import db
|
||||
from dirkules.models import Drive, Partitions
|
||||
from dirkules.hardware import drive as hardware_drives
|
||||
from sqlalchemy.sql.expression import exists
|
||||
|
||||
|
||||
def get_partitions(drive_id, force=False):
|
||||
drive = db.session.query(Drive).get(drive_id)
|
||||
partdict = hardware_drives.part_for_disk(drive.name)
|
||||
for part in partdict:
|
||||
part_obj = Partitions(drive.id, part.get("name"), part.get("label"), part.get("fs"), int(part.get("size")),
|
||||
part.get("uuid"), part.get("mount"), drive)
|
||||
existence = db.session.query(exists().where(Partitions.uuid == part_obj.uuid)).scalar()
|
||||
if existence:
|
||||
print(part.get("name") + " in db")
|
||||
else:
|
||||
print(part.get("name") + " NICHT in db")
|
||||
db.session.add(part_obj)
|
||||
db.session.commit()
|
||||
print(drive.partitions)
|
|
@ -17,7 +17,7 @@ class Drive(db.Model):
|
|||
hotplug = db.Column(db.Boolean)
|
||||
state = db.Column(db.String)
|
||||
smart = db.Column(db.Boolean)
|
||||
partitions = db.relationship('Partitions', order_by="Partitions.id", backref="drives", lazy="select")
|
||||
partitions = db.relationship('Partitions', order_by="Partitions.id", backref="drive", lazy="select")
|
||||
|
||||
def __init__(self, name, model, serial, size, rota, rm, hotplug, state, smart):
|
||||
self.name = name
|
||||
|
@ -37,11 +37,21 @@ class Partitions(db.Model):
|
|||
drive_id = db.Column(db.Integer, db.ForeignKey('drives.id'), nullable=False)
|
||||
name = db.Column(db.String)
|
||||
fs = db.Column(db.String)
|
||||
size = db.Column(db.String)
|
||||
size = db.Column(db.Integer)
|
||||
uuid = db.Column(db.String)
|
||||
mountpoint = db.Column(db.String)
|
||||
label = db.Column(db.String)
|
||||
|
||||
def __init__(self, drive_id, name, label, fs, size, uuid, mpoint, drive):
|
||||
self.drive_id = drive_id
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.fs = fs
|
||||
self.size = size
|
||||
self.uuid = uuid
|
||||
self.mountpoint = mpoint
|
||||
self.drive = drive
|
||||
|
||||
|
||||
class Time(db.Model):
|
||||
__tablename__ = 'time'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from dirkules import scheduler
|
||||
import datetime
|
||||
import dirkules.driveManagement.driveController as drico
|
||||
import dirkules.hardware.drive as drico
|
||||
|
||||
@scheduler.task('interval', id='refresh_disks', seconds=3600, next_run_time=datetime.datetime.now())
|
||||
def refresh_disks():
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
from flask import Flask, render_template, redirect, request, url_for, flash
|
||||
from dirkules import app, db
|
||||
import dirkules.driveManagement.driveController as drico
|
||||
import dirkules.hardware.drive as drico
|
||||
import dirkules.serviceManagement.serviceManager as servMan
|
||||
from dirkules.models import Drive, Cleaning, SambaShare
|
||||
import dirkules.viewManager.viewManager as viewManager
|
||||
import dirkules.manager.viewManager as viewManager
|
||||
from dirkules.validation.validators import CleaningForm, samba_cleaning_form, SambaAddForm
|
||||
from sqlalchemy import asc, collate
|
||||
from dirkules.config import staticDir
|
||||
from dirkules.manager.driveManager import get_partitions
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
|
@ -72,7 +73,7 @@ def add_cleaning():
|
|||
|
||||
@app.route('/samba', methods=['GET'])
|
||||
def samba():
|
||||
drico.part_for_disk("/dev/sda")
|
||||
get_partitions(1)
|
||||
shares = []
|
||||
for share in SambaShare.query.order_by(asc(collate(SambaShare.name, 'NOCASE'))).all():
|
||||
shares.append(viewManager.db_object_as_dict(share))
|
||||
|
|
Loading…
Add table
Reference in a new issue