it now at least does a basic view page successfully, with name, size, hash
This commit is contained in:
39
photos.py
39
photos.py
@@ -6,16 +6,30 @@ from sqlalchemy import Sequence
|
|||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from status import st, Status
|
from status import st, Status
|
||||||
import os
|
import os
|
||||||
from os import path
|
|
||||||
import glob
|
import glob
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pymediainfo import MediaInfo
|
from pymediainfo import MediaInfo
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Local Class imports
|
||||||
|
################################################################################
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Class describing Author in the database, and via sqlalchemy, connected to the DB as well
|
# Utility Functions for Files
|
||||||
|
################################################################################
|
||||||
|
def md5(fname):
|
||||||
|
print("Trying to MD5 - {}".format(fname))
|
||||||
|
hash_md5 = hashlib.md5()
|
||||||
|
with open(fname, "rb") as f:
|
||||||
|
for chunk in iter(lambda: f.read(4096), b""):
|
||||||
|
hash_md5.update(chunk)
|
||||||
|
return hash_md5.hexdigest()
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Class describing Photos in the database, and via sqlalchemy, connected to the DB as well
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# photos might not be the best name... more than just photos live in this class currently
|
# photos might not be the best name... more than just photos live in this class currently
|
||||||
@@ -23,9 +37,9 @@ class Photos(db.Model):
|
|||||||
id = db.Column(db.Integer, db.Sequence('photos_id_seq'), primary_key=True )
|
id = db.Column(db.Integer, db.Sequence('photos_id_seq'), primary_key=True )
|
||||||
name = db.Column(db.String, unique=True, nullable=False )
|
name = db.Column(db.String, unique=True, nullable=False )
|
||||||
type = db.Column(db.String, unique=False, nullable=False)
|
type = db.Column(db.String, unique=False, nullable=False)
|
||||||
# size = db.Column(db.Integer, unique=False, nullable=False)
|
size_MB = db.Column(db.Integer, unique=False, nullable=False)
|
||||||
# hash might not be unique, this could be the source of dupe problems
|
# hash might not be unique, this could be the source of dupe problems
|
||||||
#hash = db.Column(db.Integer, unique=True, nullable=False)
|
hash = db.Column(db.Integer, unique=True, nullable=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<id: {}, name: {}>".format(self.id, self.name )
|
return "<id: {}, name: {}>".format(self.id, self.name )
|
||||||
@@ -38,11 +52,12 @@ def photos():
|
|||||||
sets = Settings.query.filter(Settings.name=="import_path").all()
|
sets = Settings.query.filter(Settings.name=="import_path").all()
|
||||||
paths= sets[0].value.split("#")
|
paths= sets[0].value.split("#")
|
||||||
file_list=[]
|
file_list=[]
|
||||||
|
view_list=[]
|
||||||
view_path=""
|
view_path=""
|
||||||
for p in paths:
|
for p in paths:
|
||||||
if p.startswith('c:'):
|
if p.startswith('c:'):
|
||||||
p = p.replace('/', '\\')
|
p = p.replace('/', '\\')
|
||||||
if( path.exists( p ) ):
|
if( os.path.exists( p ) ):
|
||||||
view_path = p
|
view_path = p
|
||||||
file_list.append(glob.glob(view_path + '**', recursive=True))
|
file_list.append(glob.glob(view_path + '**', recursive=True))
|
||||||
for file in file_list[0]:
|
for file in file_list[0]:
|
||||||
@@ -55,12 +70,16 @@ def photos():
|
|||||||
else:
|
else:
|
||||||
ftype = 'File'
|
ftype = 'File'
|
||||||
|
|
||||||
# fhash=... (file)
|
|
||||||
# fsize = ... (file)
|
|
||||||
file_list.append( Photos( name=file, type=ftype ))
|
|
||||||
|
|
||||||
return render_template("photos.html", page_title='View Photos', view_path=view_path, alert=st.GetAlert(), message=st.GetMessage() )
|
if ftype != "Directory":
|
||||||
return render_template("photos.html", page_title='View Photos', view_path=view_path, file_list=file_list, alert=st.GetAlert(), message=st.GetMessage() )
|
fhash=md5(file)
|
||||||
|
else:
|
||||||
|
fhash=None
|
||||||
|
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||||
|
view_list.append( Photos( name=file, type=ftype, size_MB=fsize, hash=fhash ))
|
||||||
|
|
||||||
|
print(file_list)
|
||||||
|
return render_template("photos.html", page_title='View Photos', view_path=view_path, file_list=view_list, alert=st.GetAlert(), message=st.GetMessage() )
|
||||||
|
|
||||||
|
|
||||||
def isImage(file):
|
def isImage(file):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<h3 class="offset-lg-2">{{page_title}} -- {{view_path}}</h3>
|
<h3 class="offset-lg-2">{{page_title}} -- {{view_path}}</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<table class="table table table-sm col-xl-12">
|
<table class="table table table-sm col-xl-12">
|
||||||
<thead><tr class="thead-light"><th>Name</th><th>Size</th><th>Hash</th></tr></thead><tbody>
|
<thead><tr class="thead-light"><th>Name</th><th>Size (MB)</th><th>Hash</th></tr></thead><tbody>
|
||||||
{% for obj in file_list %}
|
{% for obj in file_list %}
|
||||||
<tr><td>
|
<tr><td>
|
||||||
{% if obj.type=="Directory" %}
|
{% if obj.type=="Directory" %}
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<i class="fas fa-question-circle"></i>
|
<i class="fas fa-question-circle"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{obj.name}}</td></td><td>{{obj.size}}</td><td>{{obj.hash}}</tr>
|
{{obj.name}}
|
||||||
|
</td></td><td>{{obj.size_MB}}</td><td>{{obj.hash}}</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
</div class="row">
|
</div class="row">
|
||||||
|
|||||||
Reference in New Issue
Block a user