Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
d9034b48
Commit
d9034b48
authored
Jan 04, 2024
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid unnecessary `isfile`/`exists` calls
parent
e4dcdcc9
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
41 additions
and
35 deletions
+41
-35
modules/cache.py
modules/cache.py
+8
-9
modules/extensions.py
modules/extensions.py
+6
-5
modules/extra_networks.py
modules/extra_networks.py
+4
-3
modules/infotext_utils.py
modules/infotext_utils.py
+3
-1
modules/launch_utils.py
modules/launch_utils.py
+4
-3
modules/postprocessing.py
modules/postprocessing.py
+4
-3
modules/shared_init.py
modules/shared_init.py
+3
-1
modules/ui_gradio_extensions.py
modules/ui_gradio_extensions.py
+3
-5
modules/ui_loadsave.py
modules/ui_loadsave.py
+3
-2
modules/util.py
modules/util.py
+3
-3
No files found.
modules/cache.py
View file @
d9034b48
...
...
@@ -62,12 +62,11 @@ def cache(subsection):
if
cache_data
is
None
:
with
cache_lock
:
if
cache_data
is
None
:
if
not
os
.
path
.
isfile
(
cache_filename
):
cache_data
=
{}
else
:
try
:
with
open
(
cache_filename
,
"r"
,
encoding
=
"utf8"
)
as
file
:
cache_data
=
json
.
load
(
file
)
except
FileNotFoundError
:
cache_data
=
{}
except
Exception
:
os
.
replace
(
cache_filename
,
os
.
path
.
join
(
script_path
,
"tmp"
,
"cache.json"
))
print
(
'[ERROR] issue occurred while trying to read cache.json, move current cache to tmp/cache.json and create new cache'
)
...
...
modules/extensions.py
View file @
d9034b48
...
...
@@ -32,7 +32,8 @@ class ExtensionMetadata:
self
.
config
=
configparser
.
ConfigParser
()
filepath
=
os
.
path
.
join
(
path
,
self
.
filename
)
if
os
.
path
.
isfile
(
filepath
):
# `self.config.read()` will quietly swallow OSErrors (which FileNotFoundError is),
# so no need to check whether the file exists beforehand.
try
:
self
.
config
.
read
(
filepath
)
except
Exception
:
...
...
modules/extra_networks.py
View file @
d9034b48
...
...
@@ -215,9 +215,10 @@ def get_user_metadata(filename):
metadata
=
{}
try
:
if
os
.
path
.
isfile
(
metadata_filename
):
with
open
(
metadata_filename
,
"r"
,
encoding
=
"utf8"
)
as
file
:
metadata
=
json
.
load
(
file
)
except
FileNotFoundError
:
pass
except
Exception
as
e
:
errors
.
display
(
e
,
f
"reading extra network user metadata from {metadata_filename}"
)
...
...
modules/infotext_utils.py
View file @
d9034b48
...
...
@@ -453,9 +453,11 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component,
def
paste_func
(
prompt
):
if
not
prompt
and
not
shared
.
cmd_opts
.
hide_ui_dir_config
:
filename
=
os
.
path
.
join
(
data_path
,
"params.txt"
)
if
os
.
path
.
exists
(
filename
)
:
try
:
with
open
(
filename
,
"r"
,
encoding
=
"utf8"
)
as
file
:
prompt
=
file
.
read
()
except
OSError
:
pass
params
=
parse_generation_parameters
(
prompt
)
script_callbacks
.
infotext_pasted_callback
(
prompt
,
params
)
...
...
modules/launch_utils.py
View file @
d9034b48
...
...
@@ -245,9 +245,10 @@ def list_extensions(settings_file):
settings
=
{}
try
:
if
os
.
path
.
isfile
(
settings_file
):
with
open
(
settings_file
,
"r"
,
encoding
=
"utf8"
)
as
file
:
settings
=
json
.
load
(
file
)
except
FileNotFoundError
:
pass
except
Exception
:
errors
.
report
(
"Could not load settings"
,
exc_info
=
True
)
...
...
modules/postprocessing.py
View file @
d9034b48
...
...
@@ -97,11 +97,12 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
if
pp
.
caption
:
caption_filename
=
os
.
path
.
splitext
(
fullfn
)[
0
]
+
".txt"
if
os
.
path
.
isfile
(
caption_filename
):
existing_caption
=
""
try
:
with
open
(
caption_filename
,
encoding
=
"utf8"
)
as
file
:
existing_caption
=
file
.
read
()
.
strip
()
e
lse
:
existing_caption
=
""
e
xcept
FileNotFoundError
:
pass
action
=
shared
.
opts
.
postprocessing_existing_caption_action
if
action
==
'Prepend'
and
existing_caption
:
...
...
modules/shared_init.py
View file @
d9034b48
...
...
@@ -18,8 +18,10 @@ def initialize():
shared
.
options_templates
=
shared_options
.
options_templates
shared
.
opts
=
options
.
Options
(
shared_options
.
options_templates
,
shared_options
.
restricted_opts
)
shared
.
restricted_opts
=
shared_options
.
restricted_opts
if
os
.
path
.
exists
(
shared
.
config_filename
)
:
try
:
shared
.
opts
.
load
(
shared
.
config_filename
)
except
FileNotFoundError
:
pass
from
modules
import
devices
devices
.
device
,
devices
.
device_interrogate
,
devices
.
device_gfpgan
,
devices
.
device_esrgan
,
devices
.
device_codeformer
=
\
...
...
modules/ui_gradio_extensions.py
View file @
d9034b48
...
...
@@ -35,13 +35,11 @@ def css_html():
return
f
'<link rel="stylesheet" property="stylesheet" href="{webpath(fn)}">'
for
cssfile
in
scripts
.
list_files_with_name
(
"style.css"
):
if
not
os
.
path
.
isfile
(
cssfile
):
continue
head
+=
stylesheet
(
cssfile
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
data_path
,
"user.css"
)):
head
+=
stylesheet
(
os
.
path
.
join
(
data_path
,
"user.css"
))
user_css
=
os
.
path
.
join
(
data_path
,
"user.css"
)
if
os
.
path
.
exists
(
user_css
):
head
+=
stylesheet
(
user_css
)
return
head
...
...
modules/ui_loadsave.py
View file @
d9034b48
...
...
@@ -26,8 +26,9 @@ class UiLoadsave:
self
.
ui_defaults_review
=
None
try
:
if
os
.
path
.
exists
(
self
.
filename
):
self
.
ui_settings
=
self
.
read_from_file
()
except
FileNotFoundError
:
pass
except
Exception
as
e
:
self
.
error_loading
=
True
errors
.
display
(
e
,
"loading settings"
)
...
...
modules/util.py
View file @
d9034b48
...
...
@@ -21,10 +21,10 @@ def html_path(filename):
def
html
(
filename
):
path
=
html_path
(
filename
)
if
os
.
path
.
exists
(
path
)
:
try
:
with
open
(
path
,
encoding
=
"utf8"
)
as
file
:
return
file
.
read
()
except
OSError
:
return
""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment