forked from AUTOMATIC1111/stable-diffusion-webui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial version of the extensions tab
fix broken Restart Gradio button
- Loading branch information
1 parent
9b384df
commit 910a097
Showing
9 changed files
with
333 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
function extensions_apply(_, _){ | ||
disable = [] | ||
update = [] | ||
gradioApp().querySelectorAll('#extensions input[type="checkbox"]').forEach(function(x){ | ||
if(x.name.startsWith("enable_") && ! x.checked) | ||
disable.push(x.name.substr(7)) | ||
|
||
if(x.name.startsWith("update_") && x.checked) | ||
update.push(x.name.substr(7)) | ||
}) | ||
|
||
restart_reload() | ||
|
||
return [JSON.stringify(disable), JSON.stringify(update)] | ||
} | ||
|
||
function extensions_check(){ | ||
gradioApp().querySelectorAll('#extensions .extension_status').forEach(function(x){ | ||
x.innerHTML = "Loading..." | ||
}) | ||
|
||
return [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import sys | ||
import traceback | ||
|
||
import git | ||
|
||
from modules import paths, shared | ||
|
||
|
||
extensions = [] | ||
extensions_dir = os.path.join(paths.script_path, "extensions") | ||
|
||
|
||
def active(): | ||
return [x for x in extensions if x.enabled] | ||
|
||
|
||
class Extension: | ||
def __init__(self, name, path, enabled=True): | ||
self.name = name | ||
self.path = path | ||
self.enabled = enabled | ||
self.status = '' | ||
self.can_update = False | ||
|
||
repo = None | ||
try: | ||
if os.path.exists(os.path.join(path, ".git")): | ||
repo = git.Repo(path) | ||
except Exception: | ||
print(f"Error reading github repository info from {path}:", file=sys.stderr) | ||
print(traceback.format_exc(), file=sys.stderr) | ||
|
||
if repo is None or repo.bare: | ||
self.remote = None | ||
else: | ||
self.remote = next(repo.remote().urls, None) | ||
self.status = 'unknown' | ||
|
||
def list_files(self, subdir, extension): | ||
from modules import scripts | ||
|
||
dirpath = os.path.join(self.path, subdir) | ||
if not os.path.isdir(dirpath): | ||
return [] | ||
|
||
res = [] | ||
for filename in sorted(os.listdir(dirpath)): | ||
res.append(scripts.ScriptFile(dirpath, filename, os.path.join(dirpath, filename))) | ||
|
||
res = [x for x in res if os.path.splitext(x.path)[1].lower() == extension and os.path.isfile(x.path)] | ||
|
||
return res | ||
|
||
def check_updates(self): | ||
repo = git.Repo(self.path) | ||
for fetch in repo.remote().fetch("--dry-run"): | ||
if fetch.flags != fetch.HEAD_UPTODATE: | ||
self.can_update = True | ||
self.status = "behind" | ||
return | ||
|
||
self.can_update = False | ||
self.status = "latest" | ||
|
||
def pull(self): | ||
repo = git.Repo(self.path) | ||
repo.remotes.origin.pull() | ||
|
||
|
||
def list_extensions(): | ||
extensions.clear() | ||
|
||
if not os.path.isdir(extensions_dir): | ||
return | ||
|
||
for dirname in sorted(os.listdir(extensions_dir)): | ||
path = os.path.join(extensions_dir, dirname) | ||
if not os.path.isdir(path): | ||
continue | ||
|
||
extension = Extension(name=dirname, path=path, enabled=dirname not in shared.opts.disabled_extensions) | ||
extensions.append(extension) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.