Skip to content

Commit

Permalink
implement wcmatch.glob in Input
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptofine committed Oct 9, 2023
1 parent 10c12d8 commit ebf1393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
10 changes: 7 additions & 3 deletions imdataset_creator/datarules/base_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from types import MappingProxyType
from typing import Any, ClassVar, Set

import wcmatch.glob as wglob
from polars import DataFrame, DataType, Expr, PolarsDataType

from ..configs.configtypes import InputData, OutputData
from ..file_list import get_file_list
from ..configs import FilterData, Keyworded
from ..configs.configtypes import InputData, OutputData
from ..file import File

PartialDataFrame = DataFrame
Expand Down Expand Up @@ -131,6 +131,9 @@ def run(self, *args, **kwargs):
raise NotImplementedError


flags = wglob.BRACE | wglob.SPLIT | wglob.EXTMATCH | wglob.IGNORECASE | wglob.GLOBSTAR


@dataclass
class Input(Keyworded):
folder: Path
Expand All @@ -141,7 +144,8 @@ def from_cfg(cls, cfg: InputData):
return cls(Path(cfg["folder"]), cfg["expressions"])

def run(self):
return get_file_list(self.folder, *self.expressions)
for file in wglob.iglob(self.expressions, flags=flags, root_dir=self.folder):
yield self.folder / file


class InvalidFormatException(Exception):
Expand Down
15 changes: 5 additions & 10 deletions imdataset_creator/gui/input_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,27 @@ class FilterList(FlowList):


class GathererThread(QThread):
source: Path
expressions: list[str]
flags: int
input: Input

count = Signal(int)
total = Signal(int)
files = Signal(list)

def run(self):
print(f"Starting search in: '{self.source}' with expressions: {self.expressions}")
print(f"Starting search in: '{self.input.folder}' with expressions: {self.input.expressions}")
filelist = []

count = 0
self.count.emit(0)
emit_timer = time.time()
for file in wglob.iglob(self.expressions, flags=self.flags, root_dir=self.source):
for file in self.input.run():
count += 1
if (newtime := time.time()) > emit_timer + 0.2:
self.count.emit(count)
emit_timer = newtime
filelist.append(file)

print(f"Gathered {count} files from '{self.source}'")
print(f"Gathered {count} files from '{self.input.folder}'")
self.count.emit(count)
self.files.emit(filelist)

Expand Down Expand Up @@ -121,8 +119,6 @@ def configure_settings_group(self):
self.gatherer.finished.connect(self.on_finished)
self.gatherer.finished.connect(self.increment.emit)

self.gatherer.flags = self.flags

self.gather_button.setText("gather")
self.gather_button.clicked.connect(self.get)

Expand Down Expand Up @@ -157,8 +153,7 @@ def get(self):
if not self.text.text():
raise NotADirectoryError(self.text.text())

self.gatherer.source = Path(self.text.text())
self.gatherer.expressions = self.globexprs.toPlainText().splitlines()
self.gatherer.input = Input(Path(self.text.text()), self.globexprs.toPlainText().splitlines())
self.gatherer.start()

@Slot(dict)
Expand Down

0 comments on commit ebf1393

Please sign in to comment.