mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
modernize typing
This commit is contained in:
+7
-7
@@ -5,7 +5,7 @@ from modules import ui_symbols, ui_components
|
||||
from installer import install, log
|
||||
|
||||
|
||||
class Page():
|
||||
class Page:
|
||||
def __init__(self, fn, full: bool = True):
|
||||
self.fn = fn
|
||||
self.title = ''
|
||||
@@ -21,7 +21,7 @@ class Page():
|
||||
try:
|
||||
self.title = ' ' + os.path.basename(self.fn).replace('.md', '').replace('-', ' ') + ' '
|
||||
self.mtime = time.localtime(os.path.getmtime(self.fn))
|
||||
with open(self.fn, 'r', encoding='utf-8') as f:
|
||||
with open(self.fn, encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
self.size = len(content)
|
||||
self.lines = [line.strip().lower() + ' ' for line in content.splitlines() if len(line)>1]
|
||||
@@ -80,7 +80,7 @@ class Page():
|
||||
log.error(f'Search docs: page="{self.fn}" does not exist')
|
||||
return f'page="{self.fn}" does not exist'
|
||||
try:
|
||||
with open(self.fn, 'r', encoding='utf-8') as f:
|
||||
with open(self.fn, encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
return content
|
||||
except Exception as e:
|
||||
@@ -91,7 +91,7 @@ class Page():
|
||||
return f'Page(title="{self.title.strip()}" fn="{self.fn}" mtime={self.mtime} h1={[h.strip() for h in self.h1]} h2={len(self.h2)} h3={len(self.h3)} lines={len(self.lines)} size={self.size})'
|
||||
|
||||
|
||||
class Pages():
|
||||
class Pages:
|
||||
def __init__(self):
|
||||
self.time = time.time()
|
||||
self.size = 0
|
||||
@@ -117,7 +117,7 @@ class Pages():
|
||||
text = text.lower()
|
||||
scores = [page.search(text) for page in self.pages]
|
||||
mtimes = [page.mtime for page in self.pages]
|
||||
found = sorted(zip(scores, mtimes, self.pages), key=lambda x: (x[0], x[1]), reverse=True)
|
||||
found = sorted(zip(scores, mtimes, self.pages, strict=False), key=lambda x: (x[0], x[1]), reverse=True)
|
||||
found = [item for item in found if item[0] > 0]
|
||||
return [(item[0], item[2]) for item in found][:topk]
|
||||
except Exception as e:
|
||||
@@ -177,7 +177,7 @@ def search_docs(search_term):
|
||||
|
||||
def get_github_page(page):
|
||||
try:
|
||||
with open(os.path.join('wiki', f'{page}.md'), 'r', encoding='utf-8') as f:
|
||||
with open(os.path.join('wiki', f'{page}.md'), encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
log.debug(f'Search wiki: page="{page}" size={len(content)}')
|
||||
except Exception as e:
|
||||
@@ -230,7 +230,7 @@ def search_github(search_term):
|
||||
|
||||
def create_ui_logs():
|
||||
def get_changelog():
|
||||
with open('CHANGELOG.md', 'r', encoding='utf-8') as f:
|
||||
with open('CHANGELOG.md', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
content = content.replace('# Change Log for SD.Next', ' ')
|
||||
return content
|
||||
|
||||
Reference in New Issue
Block a user