Optimization: Remove glob import

This commit is contained in:
Dylan Araps 2017-06-20 19:57:24 +10:00
parent 0840d57d02
commit 0adcd37dd3

13
wal
View File

@ -4,7 +4,6 @@ wal - Generate and change colorschemes on the fly.
Created by Dylan Araps Created by Dylan Araps
""" """
import argparse import argparse
import glob
import os import os
import pathlib import pathlib
import random import random
@ -117,13 +116,12 @@ def get_image(img):
# Pick a random image from the directory. # Pick a random image from the directory.
elif image.is_dir(): elif image.is_dir():
images = [] file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
file_types = ("*.png", "*.jpg", "*.jpeg", "*.jpe", "*.gif") images = [img for img in os.listdir(image)
for files in file_types: if img.endswith(file_types)]
images.extend(glob.glob(str(image) + "/" + files))
rand_img = random.choice(images) rand_img = random.choice(images)
rand_img = pathlib.Path(rand_img) rand_img = pathlib.Path(image / rand_img)
if rand_img.is_file(): if rand_img.is_file():
wal_img = rand_img wal_img = rand_img
@ -289,7 +287,8 @@ def send_sequences(colors, vte):
sequences = bytes(sequences, "utf-8").decode("unicode_escape") sequences = bytes(sequences, "utf-8").decode("unicode_escape")
# Send the sequences to all open terminals. # Send the sequences to all open terminals.
terminals = glob.glob("/dev/pts/[0-9]*") terminals = ["%s%s" % ("/dev/pts/", term)
for term in os.listdir("/dev/pts/") if len(term) < 4]
terminals.append(CACHE_DIR / "sequences") terminals.append(CACHE_DIR / "sequences")
for term in terminals: for term in terminals: