File size: 1,565 Bytes
8dfb7db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from modules.shared import cmd_opts
import os, inspect, re #, sys, shlex

script_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
batchlinks_dir = os.path.join(script_dir, "batchlinks-downloader.py")

# remove the progress bar if queue off
with open(batchlinks_dir, 'r', encoding='utf-8') as f:
    contents = f.read()

gradio_queue_on = False

try:
  if cmd_opts.gradio_queue: #automatic1111
    gradio_queue_on = True
except AttributeError:
  if not cmd_opts.disable_queue: #vladmandic
    gradio_queue_on = True

if gradio_queue_on:
    #os.system(f"sed -i 's/def run(command, choosedowner):/def run(command, choosedowner, progress=gr.Progress()):/g' {batchlinks_dir}")
    # os.system(f"sed -i '/^#progress/s/^#//' {batchlinks_dir}")
    new_contents = re.sub(r'^(\s*)#progress\(', r'\1progress(', contents, flags=re.MULTILINE)
    contents = re.sub(r'civitvae\):', 'civitvae, progress=gr.Progress()):', new_contents, flags=re.MULTILINE)

    with open(batchlinks_dir, 'w', encoding='utf-8') as f:
        f.write(contents)

else:
    # os.system(f"sed -i 's/def run(command, choosedowner, progress=gr.Progress()):/def run(command, choosedowner):/g' {batchlinks_dir}")
    # os.system(f"sed -i '/^progress(/ s/^/#/' {batchlinks_dir}")
    new_contents = re.sub(r'^(\s*)progress\(', r'\1#progress(', contents, flags=re.MULTILINE)
    contents = re.sub(r'civitvae,\s*progress=gr\.Progress\(\)\):$', 'civitvae):', new_contents, flags=re.MULTILINE)

    with open(batchlinks_dir, 'w', encoding='utf-8') as f:
        f.write(contents)