Ejemplo n.º 1
0
async def main(dest):
    """Download vaccine images."""
    async with AsyncClient() as client, open_nursery() as nursery:
        nursery.start_soon(tuoitre, Path(dest), client, nursery)
        nursery.start_soon(vnexpress, Path(dest), client, nursery)
        nursery.start_soon(thanhnien, Path(dest), client, nursery)
        nursery.start_soon(dantri, Path(dest), client, nursery)
Ejemplo n.º 2
0
async def remove_first_str():
    folder, recursive = GUI.getFolderRecursiveWindow(title_text="Remove first occurrence",
                                                 initial_folder=str(await Path.home()))
    folder = Path(folder)
    str_to_remove = GUI.getTextInputWindow("Remove first occurrence" , "What do you want to remove from the filenames?")
    async with trio.open_nursery() as nursery:
        for item in await folder.iterdir():
            nursery.start_soon(maybe_rename, item, str_to_remove)
async def get_server_socket():
    name = Path() / tempfile.gettempdir() / "test.sock"
    try:
        await name.unlink()
    except OSError:
        pass

    serv_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    serv_sock.bind(fspath(name))  # bpo-32562
    serv_sock.listen(1)

    return name, serv_sock
Ejemplo n.º 4
0
async def replace_str():
    event, values = GUI.getFolderInputWindow(initial_folder=str(await Path.home()))
    if event == "OK":
        folder = values[0]
        try:
            fromstr, tostr = GUI.getDualTextInputWindow("Replace String",
                                                        "What do you want to replace?",
                                                        "With what do you want to replace that?")
        except AttributeError:
            logger.error("Prompt was cancelled by the User.")
            exit(1)

        folder = Path(folder)
        async with trio.open_nursery() as nursery:
            for item in await folder.iterdir():
                nursery.start_soon(replace_substr, item, fromstr, tostr)
Ejemplo n.º 5
0
 def stat_async(path):
     return Path(path).stat()
Ejemplo n.º 6
0
import json
import uuid
import pickle
from trio import Semaphore, Path

locks = {"kv": {}, "log": {}}

STORE_PATH = Path("store")
LOGS_PATH = Path("logs")
BLOB_PATH = Path("blobs")


class Store:
    def __init__(self, key):
        self.key = key
        if key not in locks["kv"]:
            locks["kv"][key] = Semaphore(1)
        self.lock = locks["kv"][key]
        self.path = STORE_PATH / key
        self.data = None

    async def __aenter__(self):
        await self.lock.acquire()
        if await self.path.exists():
            async with await self.path.open() as f:
                self.data = json.loads(await f.read())
        else:
            self.data = {}
        return self.data

    async def __aexit__(self, exc_type, exc, tb):