15 Commits
Author SHA1 Message Date
lilly 7bd85c9544 Update __init__.py 2023-04-05 20:21:21 +09:00
Filipe 1e7442625b Add suport for WAS text utils nodes 2023-04-04 19:26:02 -03:00
Filipe f8863c5cb2 Add TextWildcards 2023-04-04 19:06:33 -03:00
lilly 222c0b2c65 Update README.md 2023-04-02 17:22:27 +09:00
lilly 9c8ecab6fc Update README.md 2023-04-02 17:21:58 +09:00
lilly a5e946261e SimpleSamplerVAE add 2023-04-02 17:16:26 +09:00
lilly 37851ff4ce Update mypath.py 2023-03-30 17:11:11 +09:00
lilly 3472043e28 CLIPTextEncodeWildcards3 2023-03-30 15:22:18 +09:00
lilly f7d40d0b2d filenameget 2023-03-30 13:57:08 +09:00
lilly 98ae062bc0 clean 2023-03-28 21:21:32 +09:00
lilly f4d889bc74 Update ConsoleColor.py 2023-03-27 23:28:38 +09:00
lilly 61c0536251 Update wildcards.py 2023-03-27 22:31:55 +09:00
lilly fabcf37fb3 seperator support
{9$$ {and|or} $$a|b|c}
2023-03-27 21:56:58 +09:00
lilly 67dce2659e Update README.md 2023-03-25 03:03:17 +09:00
lilly 4596db540c seed wildcards 2023-03-25 02:53:15 +09:00
11 changed files with 330 additions and 96 deletions
+60 -2
View File
@@ -18,13 +18,71 @@ else:
class CLIPTextEncodeWildcards: class CLIPTextEncodeWildcards:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": {"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )}} return {
"required": {
"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )
}
}
RETURN_TYPES = ("CONDITIONING",) RETURN_TYPES = ("CONDITIONING",)
FUNCTION = "encode" FUNCTION = "encode"
CATEGORY = "conditioning" CATEGORY = "conditioning"
def encode(self, clip, text): def encode(self, clip, text):
print(f"[green]text : [/green]",text)
r=wildcards.run(text) r=wildcards.run(text)
print(f"[green]encode : [/green]",r) print(f"[green]result : [/green]",r)
return ([[clip.encode(r), {}]], ) return ([[clip.encode(r), {}]], )
class CLIPTextEncodeWildcards2:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("CONDITIONING",)
FUNCTION = "encode"
CATEGORY = "conditioning"
def encode(self, seed, clip, text):
random.seed(seed)
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]result : [/green]",r)
return ([[clip.encode(r), {}]], )
class CLIPTextEncodeWildcards3:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"clip": ("CLIP", ),
"positive": ("STRING", {"multiline": True}),
"negative": ("STRING", {"multiline": True}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("CONDITIONING","CONDITIONING")
FUNCTION = "encode"
CATEGORY = "conditioning"
def encode(self, seed, clip, positive, negative):
random.seed(seed)
print(f"[green]positive : [/green]",positive)
positive=wildcards.run(positive)
print(f"[green]result : [/green]",positive)
print(f"[green]negative : [/green]",negative)
negative=wildcards.run(negative)
print(f"[green]result : [/green]",negative)
return ([[clip.encode(positive), {}]], [[clip.encode(negative), {}]], )
+15 -5
View File
@@ -1,14 +1,15 @@
import os import os
import comfy.sd import comfy.sd
from nodes import * from nodes import *
import folder_paths from folder_paths import *
import random import random
from .check_name import *
import os import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] : if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console from ConsoleColor import print, console
from mypath import *
else: else:
from .ConsoleColor import print, console from .ConsoleColor import print, console
from .mypath import *
#print(__file__) #print(__file__)
#print(os.path.basename(__file__)) #print(os.path.basename(__file__))
@@ -34,10 +35,19 @@ class CheckpointLoaderSimpleText:
CATEGORY = "loaders" CATEGORY = "loaders"
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True): def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
ckpt_path =check_name_ckpt(name_split_choice(ckpt_name)) #ckpt_path =check_name_ckpt(name_split_choice(ckpt_name))
print(f"ckpt_name",ckpt_name)
ns=name_split_choice(ckpt_name)
print(f"ns",ns)
ckpt_path =get_full_path("checkpoints",ns)
print(f"ckpt_path",ckpt_path)
if ckpt_path is None: if ckpt_path is None:
print(f"{ckpt_name} is none") print(f"{ckpt_name} is none")
return (name,fullpath)=filenameget(os.path.join(models_dir, "checkpoints")+"/**/"+ckpt_name+"*.safetensors")
if fullpath is None:
print(f"{name} is none")
return
ckpt_path=fullpath
try: try:
out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
return out return out
+9 -1
View File
@@ -12,7 +12,15 @@ if missing:
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL) subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
from rich.console import Console from rich.console import Console
console=Console() from rich.theme import Theme
#console=Console(style="reset")
custom_theme = Theme({
"repr.path": "bright_blue",
"progress.percentage": "bright_blue",
"markdown.block_quote": "bright_blue",
"iso8601.time": "bright_blue"
})
console = Console(theme=custom_theme)
print=console.log print=console.log
""" """
print("test", style="bold white on blue") print("test", style="bold white on blue")
+6 -1
View File
@@ -3,7 +3,12 @@ import comfy.sd
from nodes import * from nodes import *
import folder_paths import folder_paths
import random import random
from .check_name import * if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
from mypath import *
else:
from .ConsoleColor import print, console
from .mypath import *
class LoraLoaderTextRandom: class LoraLoaderTextRandom:
@classmethod @classmethod
+25 -2
View File
@@ -72,18 +72,41 @@ __anotherfile__
## for ComfyUI ## for ComfyUI
### CLIPTextEncodeWildcards
- CLIPTextEncodeWildcards : no seed
- CLIPTextEncodeWildcards : seed
![2023-03-20 02 13 50](https://user-images.githubusercontent.com/20321215/226194627-b560c9e1-5dfa-49d9-8503-939693a8b119.png) ![2023-03-20 02 13 50](https://user-images.githubusercontent.com/20321215/226194627-b560c9e1-5dfa-49d9-8503-939693a8b119.png)
### SimpleSampler+modelVAE
- include wildcards
![SimpleSampler+modelVAE](https://user-images.githubusercontent.com/20321215/229340970-19c5c0f7-6281-430d-87ce-c2e512ead277.png)
### SimpleSampler
- include wildcards
![SimpleSampler](https://user-images.githubusercontent.com/20321215/229341019-0cea9dd8-0b03-4f4a-8f49-aff068b58faf.png)
### SimpleSamplerVAE
## random_sampler_node.py - include wildcards
![SimpleSamplerVAE](https://user-images.githubusercontent.com/20321215/229341040-72d422d5-7904-41c3-a0e7-ac256ea40d0e.png)
### random_sampler_node.py
![2023-03-18 20 53 37](https://user-images.githubusercontent.com/20321215/226104447-eadd1d15-437f-4a41-b989-511390236d13.png) ![2023-03-18 20 53 37](https://user-images.githubusercontent.com/20321215/226104447-eadd1d15-437f-4a41-b989-511390236d13.png)
## VAELoaderDecode.py ### VAELoaderDecode.py
![2023-03-18 20 52 27](https://user-images.githubusercontent.com/20321215/226104441-a13f49c6-c5be-4c70-b93e-f4ad984e9ff1.png) ![2023-03-18 20 52 27](https://user-images.githubusercontent.com/20321215/226104441-a13f49c6-c5be-4c70-b93e-f4ad984e9ff1.png)
+114 -21
View File
@@ -17,7 +17,9 @@ import hashlib
import copy import copy
import traceback import traceback
from PIL import Image from PIL import Image
from nodes import common_ksampler
from PIL.PngImagePlugin import PngInfo from PIL.PngImagePlugin import PngInfo
import numpy as np import numpy as np
@@ -25,10 +27,12 @@ import numpy as np
#print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}") #print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}")
import os import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] : if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console from ConsoleColor import print, console
from wildcards import wildcards
else: else:
from .ConsoleColor import print, console from .ConsoleColor import print, console
from .wildcards import wildcards
#print(__file__) #print(__file__)
#print(os.path.basename(__file__)) #print(os.path.basename(__file__))
@@ -46,6 +50,46 @@ except:
err_msg = traceback.format_exc() err_msg = traceback.format_exc()
print(err_msg) print(err_msg)
def encode(clip, text):
if wildcardsOn:
text=wildcards.run(text)
return [[clip.encode(text), {}]]
def generate(width, height, batch_size=1):
latent = torch.zeros([batch_size, 4, height // 8, width // 8])
return {"samples":latent}
# RETURN_TYPES = ("LATENT",)
def decode(vae, samples):
return vae.decode(samples["samples"])
# RETURN_TYPES = ("IMAGE",)
def sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae,
positive, negative,
#latent_image,
width, height, denoise=1.0, batch_size=1
):
samples=common_ksampler(
model, seed, steps, cfg, sampler_name, scheduler,
#positive,
encode(clip, positive),
#negative,
encode(clip, negative),
#latent_image,
generate( width, height, batch_size=1),
denoise=denoise)[0]
return (decode(vae,samples),)
def load_vae(vae_name):
vae_path = folder_paths.get_full_path("vae", vae_name)
vae = comfy.sd.VAE(ckpt_path=vae_path)
return vae
#---------------------------- #----------------------------
class SimpleSampler: class SimpleSampler:
@classmethod @classmethod
@@ -54,39 +98,88 @@ class SimpleSampler:
{ {
"model": ("MODEL",), "model": ("MODEL",),
#"positive": ("CONDITIONING", ), #"positive": ("CONDITIONING", ),
"positive": ("STRING", {"multiline": True}), "clip": ("CLIP", ), "clip": ("CLIP", ),
"vae": ("VAE", ),
"positive": ("STRING", {"multiline": True}),
#"negative": ("CONDITIONING", ), #"negative": ("CONDITIONING", ),
"negative": ("STRING", {"multiline": True}), "clip": ("CLIP", ), "negative": ("STRING", {"multiline": True}),
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}), "width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"height": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}), "height": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 64}), "batch_size": ("INT", {"default": 1, "min": 1, "max": 64}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}), "cfg": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ), #"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}), "denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}} }}
RETURN_TYPES = ("IMAGE",)
RETURN_TYPES = ("LATENT",) #RETURN_TYPES = ("LATENT",)
FUNCTION = "sample" FUNCTION = "simple"
CATEGORY = "sampling" CATEGORY = "sampling"
def encode(self, clip, text): def simple(self,
if wildcardsOn: model, seed, steps, cfg, sampler_name, scheduler,
text=wildcards.run(text) clip,
return ([[clip.encode(text), {}]], ) vae,
positive, negative,
def generate(self, width, height, batch_size=1):
latent = torch.zeros([batch_size, 4, height // 8, width // 8])
return ({"samples":latent}, )
def sample(self,
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
width, height, denoise=1.0, batch_size=1 width, height, denoise=1.0, batch_size=1
): ):
return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, self.encode(clip, positive), elf.encode(clip, negative), self.generate( width, height, batch_size=1), denoise=denoise) return sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae,
positive, negative,
width, height, denoise, batch_size
)
#----------------------------
class SimpleSamplerVAE:
@classmethod
def INPUT_TYPES(s):
return {"required":
{
"model": ("MODEL",),
#"positive": ("CONDITIONING", ),
"clip": ("CLIP", ),
#"vae": ("VAE", ),
"vae_name": (folder_paths.get_filename_list("vae"), ),
"positive": ("STRING", {"multiline": True}),
#"negative": ("CONDITIONING", ),
"negative": ("STRING", {"multiline": True}),
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"height": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 64}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
#"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}}
RETURN_TYPES = ("IMAGE",)
#RETURN_TYPES = ("LATENT",)
FUNCTION = "simple"
CATEGORY = "sampling"
def simple(self,
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae_name,
positive, negative,
width, height, denoise=1.0, batch_size=1
):
return sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
load_vae(vae_name),
positive, negative,
width, height, denoise, batch_size
)
+33
View File
@@ -0,0 +1,33 @@
import os, glob, sys
import random
import re
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console
from wildcards import wildcards
else:
from .ConsoleColor import print, console
from .wildcards import wildcards
class TextWildcards:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("STRING","ASCII")
FUNCTION = "encode"
CATEGORY = "utils"
def encode(self, seed, text):
random.seed(seed)
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]result : [/green]",r)
return ([r, r], )
+17 -6
View File
@@ -1,6 +1,10 @@
import sys import sys
import os import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
print(f"__file__ : {__file__}")
print(f"__name__ : {__name__}")
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console from ConsoleColor import print, console
else: else:
from .ConsoleColor import print, console from .ConsoleColor import print, console
@@ -44,11 +48,17 @@ if not md.startswith("custom_nodes."):
NODE_CLASS_MAPPINGS = { NODE_CLASS_MAPPINGS = {
} }
def add(name): def add(name,clist=None):
#print(f"Load : {name}") #print(f"Load : {name}")
try: try:
pkg = importlib.import_module(f"{md}.{name}") pkg = importlib.import_module(f"{md}.{name}")
NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}") if clist is None:
NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}")
elif type(clist) is str:
NODE_CLASS_MAPPINGS[clist]=eval(f"pkg.{clist}")
elif type(clist) is list:
for c in clist:
NODE_CLASS_MAPPINGS[c]=eval(f"pkg.{c}")
print(f"Load ok : {name}", style="bold green") print(f"Load ok : {name}", style="bold green")
except Exception: except Exception:
console.print_exception() console.print_exception()
@@ -57,13 +67,14 @@ if not md.startswith("custom_nodes."):
add("CheckpointLoaderRandom") add("CheckpointLoaderRandom")
add("CheckpointLoaderSimpleText") add("CheckpointLoaderSimpleText")
add("CLIPTextEncodeWildcards") add("CLIPTextEncodeWildcards",["CLIPTextEncodeWildcards","CLIPTextEncodeWildcards2","CLIPTextEncodeWildcards3"])
add("LoraLoaderText") add("LoraLoaderText")
add("LoraLoaderTextRandom") add("LoraLoaderTextRandom")
add("Random_Sampler") add("Random_Sampler")
add("VAELoaderDecode") add("VAELoaderDecode")
add("SimpleSampler") add("SimpleSampler",["SimpleSampler","SimpleSamplerVAE"])
add("SaveImageSimple") add("SaveImageSimple")
add("TextWildcards")
#add("test") #add("test")
console.rule(" finit end ", style="bold green") console.rule(" init end ", style="bold green")
-25
View File
@@ -1,25 +0,0 @@
import os
from folder_paths import supported_ckpt_extensions,supported_pt_extensions
import folder_paths
import random
def check_name(kind,name,supported_extensions):
for ext in supported_extensions:
if name.lower().endswith(ext):
path = folder_paths.get_full_path(kind, name)
if path is not None:
return path
for ext in supported_extensions:
path = folder_paths.get_full_path(kind, name+ext)
if path is not None:
return path
def check_name_ckpt(name):
return check_name("checkpoints",name,supported_ckpt_extensions)
def check_name_pt(kind,name):
return check_name(kind,name,supported_pt_extensions)
def name_split_choice(name):
return random.choice(name.split('|'))
+34 -22
View File
@@ -1,13 +1,12 @@
import sys import sys
import json import json
import os import ast
import os, glob
import random
if __name__ == os.path.splitext(os.path.basename(__file__))[0] : if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console from ConsoleColor import print, console
else: else:
from .ConsoleColor import print, console from .ConsoleColor import print, console
#print(__file__)
#print(os.path.basename(__file__))
""" """
import psutil import psutil
@@ -48,22 +47,35 @@ print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style=
mainfolder = os.path.dirname(mainFile) mainfolder = os.path.dirname(mainFile)
print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN") print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN")
def jsondic(full,dic,update=False): def check_name(kind,name,supported_extensions):
for ext in supported_extensions:
if name.lower().endswith(ext):
path = folder_paths.get_full_path(kind, name)
if path is not None:
return path
for ext in supported_extensions:
path = folder_paths.get_full_path(kind, name+ext)
if path is not None:
return path
def check_name_ckpt(name):
return check_name("checkpoints",name,supported_ckpt_extensions)
path=os.path.split(full)[0] def check_name_pt(kind,name):
if not os.path.exists(path): return check_name(kind,name,supported_pt_extensions)
os.makedirs(path)
#with open(f"./RandomLoop/chars-{time.strftime('_%Y%m%d_%H%M%S')}.json", 'w', encoding='utf-8') as file: def name_split_choice(name):
if os.path.exists(full): return random.choice(name.split('|'))
with open(full, 'r', encoding='utf-8') as file:
tmp=json.load(file) #----------------------
if update:
dic.update(tmp) def filenameget(v_path):
else: t_path=os.path.join(os.path.dirname(__file__),v_path)
dic=(tmp) print(t_path)
else: fullpaths=glob.glob(t_path, recursive=True)
with open(full, 'w', encoding='utf-8') as file: print(fullpaths)
json.dump(dic, file, sort_keys=False, indent=4) fullpath=random.choice(fullpaths)
name=os.path.basename(fullpath)
return path #r_path=[os.path.basename(fullpath) for fullpath in fullpaths]
return (name,fullpath)
+17 -11
View File
@@ -2,7 +2,7 @@ import glob, sys
import random import random
import re import re
import os import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] : if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console from ConsoleColor import print, console
else: else:
from .ConsoleColor import print, console from .ConsoleColor import print, console
@@ -20,7 +20,8 @@ class wildcards:
# 정규식 # 정규식
#resub = re.compile(r"(\{)([^\{\}]*)(\})") #resub = re.compile(r"(\{)([^\{\}]*)(\})")
resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$)?([^\{\}]*)(\})") #resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$((.*)?\$\$)?)?([^\{\}]*)(\})")
resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$(([^\{\}]*?)\$\$)?)?([^\{\}]*)(\})")
recard = re.compile(r"(__)(.*?)(__)") recard = re.compile(r"(__)(.*?)(__)")
# 카드 목록 # 카드 목록
@@ -33,17 +34,20 @@ class wildcards:
#print(f"sub : {(match.groups())}") #print(f"sub : {(match.groups())}")
try: try:
#m=match.group(2) #m=match.group(2)
seperator=wildcards.seperator
s=match.group(3) s=match.group(3)
m=match.group(7).split("|") m=match.group(9).split("|")
p=match.group(8)
#print(f"m : {m}") if p:
seperator=p
if s is None: if s is None:
return random.choice(m) return random.choice(m)
c=len(m) c=len(m)
n=int(match.group(4)) if match.group(4) else None n=int(match.group(4)) if match.group(4) else None
if n: if n:
r=wildcards.seperator.join(random.sample(m,min(n,c))) r=seperator.join(random.sample(m,min(n,c)))
#print(f"n : {n} ; {r}") #print(f"n : {n} ; {r}")
return r return r
@@ -54,7 +58,7 @@ class wildcards:
a=min(int(n1 if n1 else c), int(n2 if n2 else c),c) a=min(int(n1 if n1 else c), int(n2 if n2 else c),c)
b=min(max(int(n1 if n1 else 0), int(n2 if n2 else 0)),c) b=min(max(int(n1 if n1 else 0), int(n2 if n2 else 0)),c)
#print(f"ab : {a} ; {b}") #print(f"ab : {a} ; {b}")
r=wildcards.seperator.join( r=seperator.join(
random.sample( random.sample(
m, m,
random.randint( random.randint(
@@ -65,7 +69,7 @@ class wildcards:
#n1=int(match.group(5)) if not match.group(5) is None #n1=int(match.group(5)) if not match.group(5) is None
#n2=int(match.group(6)) if not match.group(6) is None #n2=int(match.group(6)) if not match.group(6) is None
else: else:
r=wildcards.seperator.join( r=seperator.join(
random.sample( random.sample(
m, m,
random.randint( random.randint(
@@ -166,7 +170,9 @@ class wildcards:
#print(__name__) #print(__name__)
#if __name__ == '__main__' : #if __name__ == '__main__' :
# 테스트용 # 테스트용
test="{3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}" test="{3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}/{9$$-$$a|b|c}/{9$$ {and|or} $$a|b|c}"
print("[green]wildcards test : [/green]",wildcards.run(test)) print("[green]wildcards test : [/green]",wildcards.run(test),style="reset")
#print("wildcards test : "+wildcards.run("{9$$a|b}")) #print("wildcards test : "+wildcards.run("{9$$a|b}"))
print("[green]wildcards test : [/green]",wildcards.run("__my__")) #print("[green]wildcards test : [/green]",wildcards.run("__my__"))
print("wildcards test : "+wildcards.run("{9$$-$$a|b|c}"))
print("wildcards test : "+wildcards.run("{9$$ {and|or} $$a|b|c}"))