files now processes multiple paths, and view shows images for any images in appropriate path
This commit is contained in:
20
files.py
20
files.py
@@ -23,10 +23,7 @@ from settings import Settings
|
||||
|
||||
class FileData():
|
||||
def __init__(self):
|
||||
self.view_path=''
|
||||
self.view_list=[]
|
||||
self.symlink=''
|
||||
self.file_list=[]
|
||||
|
||||
################################################################################
|
||||
# Utility Functions for Files
|
||||
@@ -106,17 +103,18 @@ class FileData():
|
||||
paths= import_path.split("#")
|
||||
|
||||
for path in paths:
|
||||
print( "GenerateFileData: Checking {}".format( path ) )
|
||||
path = self.FixPath(path)
|
||||
if os.path.exists( path ):
|
||||
self.view_path = path
|
||||
# to serve static content of the images, we create a symlink
|
||||
# from inside the static subdir of each import_path that exists
|
||||
self.symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
|
||||
if not os.path.exists(self.symlink):
|
||||
os.symlink(path, self.symlink)
|
||||
symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
|
||||
if not os.path.exists(symlink):
|
||||
os.symlink(path, symlink)
|
||||
|
||||
self.file_list.append(glob.glob(self.view_path + '**', recursive=True))
|
||||
for file in self.file_list[0]:
|
||||
file_list=[]
|
||||
file_list.append(glob.glob(path + '**', recursive=True))
|
||||
for file in file_list[0]:
|
||||
if file == path:
|
||||
continue
|
||||
stat = os.stat(file)
|
||||
@@ -141,7 +139,8 @@ class FileData():
|
||||
|
||||
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||
fname=file.replace(path, "")
|
||||
file_obj = Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, thumbnail=fthumbnail )
|
||||
path_prefix=symlink.replace(path,"")
|
||||
file_obj = Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, path_prefix=path_prefix, thumbnail=fthumbnail )
|
||||
db.session.add(file_obj)
|
||||
else:
|
||||
print( "{} - {} is OLDER than {}".format( file, stat.st_ctime, last_import_date ) )
|
||||
@@ -158,6 +157,7 @@ class Files(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('files_id_seq'), primary_key=True )
|
||||
name = db.Column(db.String, unique=True, nullable=False )
|
||||
type = db.Column(db.String, unique=False, nullable=False)
|
||||
path_prefix = db.Column(db.String, 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 = db.Column(db.Integer, unique=True, nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user