handle windows short names, #58
parent
4cbcd1de17
commit
8633dde3f8
|
|
@ -76,7 +76,7 @@ class ImageBrowserTab():
|
|||
|
||||
def __init__(self, name: str):
|
||||
self.name: str = os.path.basename(name) if os.path.isdir(name) else name
|
||||
self.path: str = os.path.abspath(path_maps.get(name, name))
|
||||
self.path: str = os.path.realpath(path_maps.get(name, name))
|
||||
self.base_tag: str = f"image_browser_tab_{self.get_unique_base_tag(self.remove_invalid_html_tag_chars(self.name).lower())}"
|
||||
|
||||
def remove_invalid_html_tag_chars(self, tag: str) -> str:
|
||||
|
|
@ -112,6 +112,8 @@ if hasattr(opts, "image_browser_logger_debug"):
|
|||
if opts.image_browser_logger_debug:
|
||||
logger_mode = logging.DEBUG
|
||||
logger.setLevel(logger_mode)
|
||||
if (logger.hasHandlers()):
|
||||
logger.handlers.clear()
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setLevel(logger_mode)
|
||||
logger.addHandler(console_handler)
|
||||
|
|
@ -152,7 +154,7 @@ def img_path_subdirs_get(img_path):
|
|||
return gr.update(choices=subdirs)
|
||||
|
||||
def img_path_add_remove(img_dir, path_recorder, add_remove, img_path_depth):
|
||||
img_dir = os.path.abspath(img_dir)
|
||||
img_dir = os.path.realpath(img_dir)
|
||||
if add_remove == "add" or (add_remove == "remove" and img_dir in path_recorder):
|
||||
if add_remove == "add":
|
||||
path_recorder[img_dir] = {
|
||||
|
|
@ -197,7 +199,7 @@ def pure_path(path):
|
|||
depth = int(match.group(1))
|
||||
else:
|
||||
depth = 0
|
||||
path = os.path.abspath(path)
|
||||
path = os.path.realpath(path)
|
||||
return path, depth
|
||||
|
||||
def browser2path(img_path_browser):
|
||||
|
|
@ -452,8 +454,8 @@ def exif_update_dirs(maint_update_dirs_from, maint_update_dirs_to, maint_wait):
|
|||
elif maint_update_dirs_to == "":
|
||||
maint_last_msg = "To is empty"
|
||||
else:
|
||||
maint_update_dirs_from = os.path.abspath(maint_update_dirs_from)
|
||||
maint_update_dirs_to = os.path.abspath(maint_update_dirs_to)
|
||||
maint_update_dirs_from = os.path.realpath(maint_update_dirs_from)
|
||||
maint_update_dirs_to = os.path.realpath(maint_update_dirs_to)
|
||||
rows = 0
|
||||
conn, cursor = wib_db.transaction_begin()
|
||||
wib_db.update_path_recorder_mult(cursor, maint_update_dirs_from, maint_update_dirs_to)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os
|
|||
import sqlite3
|
||||
from modules import scripts
|
||||
|
||||
version = 2
|
||||
version = 3
|
||||
|
||||
path_recorder_file = os.path.join(scripts.basedir(), "path_recorder.txt")
|
||||
aes_cache_file = os.path.join(scripts.basedir(), "aes_scores.json")
|
||||
|
|
@ -95,7 +95,7 @@ def migrate_path_recorder(cursor):
|
|||
# json-version
|
||||
path_recorder = json.load(f)
|
||||
for path, values in path_recorder.items():
|
||||
path = os.path.abspath(path)
|
||||
path = os.path.realpath(path)
|
||||
depth = values["depth"]
|
||||
path_display = f"{path} [{depth}]"
|
||||
cursor.execute('''
|
||||
|
|
@ -107,7 +107,7 @@ def migrate_path_recorder(cursor):
|
|||
# old txt-version
|
||||
path = f.readline().rstrip("\n")
|
||||
while len(path) > 0:
|
||||
path = os.path.abspath(path)
|
||||
path = os.path.realpath(path)
|
||||
cursor.execute('''
|
||||
INSERT INTO path_recorder (path, depth, path_display)
|
||||
VALUES (?, ?, ?)
|
||||
|
|
@ -192,7 +192,7 @@ def migrate_exif_data(cursor):
|
|||
exif_cache = json.load(file)
|
||||
|
||||
for file, info in exif_cache.items():
|
||||
file = os.path.abspath(file)
|
||||
file = os.path.realpath(file)
|
||||
update_exif_data(cursor, file, info)
|
||||
|
||||
return
|
||||
|
|
@ -203,7 +203,7 @@ def migrate_ranking(cursor):
|
|||
ranking = json.load(file)
|
||||
for file, info in ranking.items():
|
||||
if info != "None":
|
||||
file = os.path.abspath(file)
|
||||
file = os.path.realpath(file)
|
||||
name = os.path.basename(file)
|
||||
cursor.execute('''
|
||||
INSERT INTO ranking (file, name, ranking)
|
||||
|
|
@ -239,10 +239,10 @@ def migrate_path_recorder_dirs(cursor):
|
|||
FROM path_recorder
|
||||
''')
|
||||
for (path, path_display) in cursor.fetchall():
|
||||
abs_path = os.path.abspath(path)
|
||||
if path != abs_path:
|
||||
real_path = os.path.realpath(path)
|
||||
if path != real_path:
|
||||
update_from = path
|
||||
update_to = abs_path
|
||||
update_to = real_path
|
||||
cursor.execute('''
|
||||
UPDATE path_recorder
|
||||
SET path = ?,
|
||||
|
|
@ -259,10 +259,10 @@ def migrate_exif_data_dirs(cursor):
|
|||
''')
|
||||
for (filepath,) in cursor.fetchall():
|
||||
(path, file) = os.path.split(filepath)
|
||||
abs_path = os.path.abspath(path)
|
||||
if path != abs_path:
|
||||
real_path = os.path.realpath(path)
|
||||
if path != real_path:
|
||||
update_from = filepath
|
||||
update_to = os.path.join(abs_path, file)
|
||||
update_to = os.path.join(real_path, file)
|
||||
try:
|
||||
cursor.execute('''
|
||||
UPDATE exif_data
|
||||
|
|
@ -282,15 +282,16 @@ def migrate_exif_data_dirs(cursor):
|
|||
|
||||
return
|
||||
|
||||
def migrate_ranking_dirs(cursor):
|
||||
cursor.execute('''
|
||||
ALTER TABLE ranking
|
||||
ADD COLUMN name TEXT
|
||||
''')
|
||||
def migrate_ranking_dirs(cursor, db_version):
|
||||
if db_version == "1":
|
||||
cursor.execute('''
|
||||
ALTER TABLE ranking
|
||||
ADD COLUMN name TEXT
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE INDEX IF NOT EXISTS ranking_name ON ranking (name)
|
||||
''')
|
||||
cursor.execute('''
|
||||
CREATE INDEX IF NOT EXISTS ranking_name ON ranking (name)
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
SELECT file, ranking
|
||||
|
|
@ -304,10 +305,10 @@ def migrate_ranking_dirs(cursor):
|
|||
''', (filepath,))
|
||||
else:
|
||||
(path, file) = os.path.split(filepath)
|
||||
abs_path = os.path.abspath(path)
|
||||
real_path = os.path.realpath(path)
|
||||
name = file
|
||||
update_from = filepath
|
||||
update_to = os.path.join(abs_path, file)
|
||||
update_to = os.path.join(real_path, file)
|
||||
cursor.execute('''
|
||||
UPDATE ranking
|
||||
SET file = ?,
|
||||
|
|
@ -319,6 +320,7 @@ def migrate_ranking_dirs(cursor):
|
|||
|
||||
def check():
|
||||
if not os.path.exists(db_file):
|
||||
print("Image Browser: Creating database")
|
||||
conn, cursor = transaction_begin()
|
||||
create_db(cursor)
|
||||
update_db_data(cursor, "version", version)
|
||||
|
|
@ -326,15 +328,19 @@ def check():
|
|||
migrate_exif_data(cursor)
|
||||
migrate_ranking(cursor)
|
||||
transaction_end(conn, cursor)
|
||||
print("Image Browser: Database created")
|
||||
db_version = get_version()
|
||||
if db_version[0] == "1":
|
||||
# version 1 database had mixed path notations, this will change them all to abspath
|
||||
if db_version[0] <= "2":
|
||||
# version 1 database had mixed path notations, changed them all to abspath
|
||||
# version 2 database still had mixed path notations, because of windows short name, changed them all to realpath
|
||||
print(f"Image Browser: Upgrading database from version {db_version[0]} to version {version}")
|
||||
conn, cursor = transaction_begin()
|
||||
update_db_data(cursor, "version", version)
|
||||
migrate_path_recorder_dirs(cursor)
|
||||
migrate_exif_data_dirs(cursor)
|
||||
migrate_ranking_dirs(cursor)
|
||||
migrate_ranking_dirs(cursor, db_version[0])
|
||||
transaction_end(conn, cursor)
|
||||
print(f"Image Browser: Database upgraded from version {db_version[0]} to version {version}")
|
||||
|
||||
return version
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue