mirror of
https://github.com/vale981/dirkules
synced 2025-03-04 17:01:40 -05:00
partitionen angefangen
This commit is contained in:
parent
413bdfe644
commit
01838f3820
5 changed files with 43 additions and 44 deletions
|
@ -10,4 +10,13 @@ db = SQLAlchemy(app)
|
|||
import dirkules.models
|
||||
db.create_all()
|
||||
|
||||
from dirkules.models import Time
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
try:
|
||||
Time.query.one()
|
||||
except NoResultFound:
|
||||
db.session.add(Time("Drives"))
|
||||
db.session.commit()
|
||||
|
||||
import dirkules.views
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import psutil
|
||||
import subprocess
|
||||
import os
|
||||
from dirkules.models import Drive
|
||||
|
@ -9,7 +8,7 @@ from dirkules import db
|
|||
def getAllDrives():
|
||||
#vorbereitung
|
||||
drives = []
|
||||
driveDict = []
|
||||
driveDict = [] # ist eine Liste, enthält für jede HDD ein dict
|
||||
keys = ['device', 'name', 'smart', 'size']
|
||||
|
||||
blkid = subprocess.Popen(["hwinfo --disk --short"],
|
||||
|
@ -28,6 +27,7 @@ def getAllDrives():
|
|||
break
|
||||
blkid.stdout.close()
|
||||
for line in drives:
|
||||
# Effizienter machen mit newLine = ' '.join(line.split())
|
||||
values = []
|
||||
line = line.replace(" ", "", 15)
|
||||
values.append(line[:8])
|
||||
|
@ -63,7 +63,6 @@ def smartPassed(device):
|
|||
|
||||
|
||||
def getTotalSize(device):
|
||||
# Hier könnte man auch die Partitionen mit abfragen
|
||||
drives = []
|
||||
fdisk = subprocess.Popen(["fdisk -l"],
|
||||
stdout=subprocess.PIPE,
|
||||
|
@ -85,19 +84,18 @@ def getTotalSize(device):
|
|||
return size
|
||||
|
||||
|
||||
#nicht verwenden
|
||||
def OLDgetAllDrives():
|
||||
|
||||
#vorbereitung
|
||||
def getPartitions(device):
|
||||
partDict = [] # ist eine Liste, enthält für jede part ein dict
|
||||
drives = []
|
||||
driveDict = []
|
||||
keys = ['device', 'mountpoint', 'fstype', 'label']
|
||||
# name = sda1 zum Beispiel
|
||||
keys = ['name', 'fs', 'size', 'uuid', 'mountpoint', 'label']
|
||||
|
||||
blkid = subprocess.Popen(["blkid"],
|
||||
fdisk = subprocess.Popen(["fdisk -l"],
|
||||
stdout=subprocess.PIPE,
|
||||
shell=True,
|
||||
universal_newlines=True)
|
||||
grepedDrives = subprocess.Popen(["grep", "/dev/sd"],
|
||||
stdin=blkid.stdout,
|
||||
grepedDrives = subprocess.Popen(["grep", device],
|
||||
stdin=fdisk.stdout,
|
||||
stdout=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
while True:
|
||||
|
@ -106,31 +104,22 @@ def OLDgetAllDrives():
|
|||
drives.append(line.rstrip())
|
||||
else:
|
||||
break
|
||||
blkid.stdout.close()
|
||||
fdisk.stdout.close()
|
||||
del drives[0]
|
||||
for line in drives:
|
||||
values = []
|
||||
#Informationen aufbereiten
|
||||
arrayline = line.split(' ')
|
||||
values.append(arrayline[0][:-1])
|
||||
if any("LABEL" in s for s in arrayline):
|
||||
if any("UUID_SUB" in s for s in arrayline):
|
||||
values.append("Was weiß ich...")
|
||||
values.append(arrayline[4][6:-1])
|
||||
values.append("Weiß ich auch noch nicht...")
|
||||
else:
|
||||
values.append("Was weiß ich...")
|
||||
values.append(arrayline[3][6:-1])
|
||||
values.append("Weiß ich auch noch nicht...")
|
||||
elif any(not "LABEL" in s
|
||||
for s in arrayline) and any("UUID_SUB" in s
|
||||
for s in arrayline):
|
||||
values.append("Was weiß ich...")
|
||||
values.append(arrayline[3][6:-1])
|
||||
values.append("(keiner)")
|
||||
line = line.replace("*", "")
|
||||
newLine = ' '.join(line.split())
|
||||
newLine = newLine.split(" ")
|
||||
if newLine[5] != 5: #Ungültige Partitionen herausfiltern
|
||||
# Für jede Partition muss nun blkid ausgeführt werden, um weitere Informationen zu erhalten
|
||||
values = []
|
||||
values.append(newLine[0])
|
||||
values.append("fs")
|
||||
values.append(newLine[4])
|
||||
values.append("uuid")
|
||||
values.append("mountpoint")
|
||||
values.append("label")
|
||||
partDict.append(dict(zip(keys, values)))
|
||||
else:
|
||||
values.append("Was weiß ich...")
|
||||
values.append(arrayline[2][6:-1])
|
||||
values.append("(keiner)")
|
||||
#Dict für Jinja anfügen
|
||||
driveDict.append(dict(zip(keys, values)))
|
||||
return driveDict
|
||||
pass
|
||||
return partDict
|
||||
|
|
|
@ -26,17 +26,17 @@ class Partitions(db.Model):
|
|||
drive_id = db.Column(db.Integer, db.ForeignKey('drives.id'))
|
||||
name = db.Column(db.String)
|
||||
fs = db.Column(db.String)
|
||||
size =db.Column(db.String)
|
||||
uuid = db.Column(db.String)
|
||||
mountpoint = db.Column(db.String)
|
||||
label = db.Column(db.String)
|
||||
|
||||
|
||||
class Times(db.Model):
|
||||
__tablename__ = 'times'
|
||||
class Time(db.Model):
|
||||
__tablename__ = 'time'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
desc = db.Column(db.String)
|
||||
time = db.Column(db.Integer, default=0, onupdate=1)
|
||||
|
||||
def __init__(self, desc, time):
|
||||
def __init__(self, desc):
|
||||
self.desc = desc
|
||||
self.time = time
|
||||
|
|
|
@ -12,7 +12,9 @@ def index():
|
|||
@app.route('/drives', methods=['GET'])
|
||||
def drives():
|
||||
drives = drico.getAllDrives()
|
||||
print(Drive.query.filter_by(device='/dev/sda').all())
|
||||
#print(Drive.query.filter_by(device='/dev/sda').all())
|
||||
test = drico.getPartitions("/dev/sdb")
|
||||
print(test)
|
||||
return render_template('drives.html', drives=drives)
|
||||
|
||||
|
||||
|
|
1
setup.py
1
setup.py
|
@ -8,6 +8,5 @@ setup(
|
|||
install_requires=[
|
||||
'flask',
|
||||
'Flask-SQLAlchemy',
|
||||
'psutil',
|
||||
],
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue