From e9ec305a290f372124ec9d33f356b8e1023a811c Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 5 Mar 2019 14:04:31 +0100 Subject: [PATCH] new database format... --- dirkules/config.py | 4 +-- dirkules/driveManagement/driveController.py | 14 ++++++--- dirkules/models.py | 35 ++++++++++----------- dirkules/templates/base.html | 1 + dirkules/templates/partitions.html | 33 +++++++++++++++++++ dirkules/views.py | 8 +++++ 6 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 dirkules/templates/partitions.html diff --git a/dirkules/config.py b/dirkules/config.py index e152400..bcd6bb9 100644 --- a/dirkules/config.py +++ b/dirkules/config.py @@ -1,8 +1,6 @@ import os - baseDir = os.path.abspath(os.path.dirname(__file__)) -SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join( - baseDir, 'dirkules.db') +SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(baseDir, 'dirkules.db') SQLALCHEMY_TRACK_MODIFICATIONS = False diff --git a/dirkules/driveManagement/driveController.py b/dirkules/driveManagement/driveController.py index 3bf4a34..7885f29 100644 --- a/dirkules/driveManagement/driveController.py +++ b/dirkules/driveManagement/driveController.py @@ -2,6 +2,7 @@ import psutil import subprocess import os +from dirkules.models import Drive def getAllDrives(): @@ -33,16 +34,17 @@ def getAllDrives(): values.append(smartPassed(values[0])) values.append(getTotalSize(values[0])) driveDict.append(dict(zip(keys, values))) + db.session.add(Drive(values[0], values[1], values[2], values[3])) + db.session.commit() return driveDict def smartPassed(device): passed = False - smartctl = subprocess.Popen( - ["smartctl -H " + device], - stdout=subprocess.PIPE, - shell=True, - universal_newlines=True) + smartctl = subprocess.Popen(["smartctl -H " + device], + stdout=subprocess.PIPE, + shell=True, + universal_newlines=True) while True: line = smartctl.stdout.readline() if "PASSED" in line: @@ -54,6 +56,7 @@ def smartPassed(device): smartctl.stdout.close() return passed + def getTotalSize(device): # Hier könnte man auch die Partitionen mit abfragen drives = [] @@ -76,6 +79,7 @@ def getTotalSize(device): size = firstLine[2] + " " + firstLine[3][:-1] return size + #nicht verwenden def OLDgetAllDrives(): diff --git a/dirkules/models.py b/dirkules/models.py index 67ae0ec..81deb97 100644 --- a/dirkules/models.py +++ b/dirkules/models.py @@ -1,26 +1,25 @@ -import time from dirkules import db from sqlalchemy import Table, Column, Integer, ForeignKey from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declarative_base -Base = declarative_base() -class Drive(Base): - __tablename__ = 'drives' - id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String) - path = db.Column(db.String) - storage = db.Column(db.Integer) - observed = db.Column(db.Boolean) - statuse = db.relationship("Drive_status") - -class Drive_status(Base): - __tablename__ = 'drive_status' +class Drive(db.Model): + __tablename__ = 'drives' id = db.Column(db.Integer, primary_key=True) - drive_id = db.Column(db.Integer, db.ForeignKey('drive.id')) + device = db.Column(db.String) + name = db.Column(db.String) + size = db.Column(db.Integer) smart = db.Column(db.Boolean) - operating_hours = db.Column(db.Integer) - startups = db.Column(db.Integer) - startups = db.Column(db.Integer) - time = db.Column(db.Integer) + partitions = db.relationship("Partitions") + + +class Partitions(db.Model): + __tablename__ = 'partitions' + id = db.Column(db.Integer, primary_key=True) + drive_id = db.Column(db.Integer, db.ForeignKey('drives.id')) + name = db.Column(db.String) + fs = db.Column(db.String) + uuid = db.Column(db.String) + mountpoint = db.Column(db.String) + label = db.Column(db.String) diff --git a/dirkules/templates/base.html b/dirkules/templates/base.html index 31d853a..f5143a1 100644 --- a/dirkules/templates/base.html +++ b/dirkules/templates/base.html @@ -22,6 +22,7 @@
  • Startseite
  • NZBGet
  • Festplatten
  • +
  • Partitionen
  • diff --git a/dirkules/templates/partitions.html b/dirkules/templates/partitions.html new file mode 100644 index 0000000..399d9e7 --- /dev/null +++ b/dirkules/templates/partitions.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} +{% block title %}Dashboard{% endblock %} +{% block head %} + {{ super() }} +{% endblock %} +{% block body %} +
    + Partitionen +
    +
    + + + + + + + + + + + + {% for drive in drives %} + + + + + + + {% endfor %} + +
    LaufwerkNameSpeicherplatzSMART Status
    {{drive.device}}{{drive.name}}{{drive.size}}{{drive.smart}}
    +
    +{% endblock %} diff --git a/dirkules/views.py b/dirkules/views.py index 37cd906..4d3907b 100644 --- a/dirkules/views.py +++ b/dirkules/views.py @@ -2,16 +2,24 @@ from flask import Flask, render_template from dirkules import app import dirkules.driveManagement.driveController as drico + @app.route('/', methods=['GET']) def index(): return render_template('index.html') + @app.route('/drives', methods=['GET']) def drives(): drives = drico.getAllDrives() return render_template('drives.html', drives=drives) + @app.route('/about', methods=['GET']) def about(): version = "1.0" return render_template('about.html', version=version) + + +@app.route('/partitions', methods=['GET']) +def partitions(): + return render_template('partitions.html')