Esempio n. 1
0
 def test_create_dir(self):
     """> Create a directory."""
     tmp_dir = pathlib.Path("/tmp/test_dir")
     util.create_dir(tmp_dir)
     result = tmp_dir.is_dir()
     self.assertTrue(result)
     os.rmdir(tmp_dir)
Esempio n. 2
0
def process_args(args):
    """Process args."""
    # If no args were passed.
    if not len(sys.argv) > 1:
        print("error: wal needs to be given arguments to run.\n"
              "       Refer to \"wal -h\" for more info.")
        exit(1)

    if args.i and args.f:
        print("error: Conflicting arguments -i and -f.\n"
              "       Refer to \"wal -h\" for more info.")
        exit(1)

    # -q
    if args.q:
        sys.stdout = sys.stderr = open(os.devnull, "w")

    # -c
    if args.c:
        shutil.rmtree(CACHE_DIR / "schemes")
        util.create_dir(CACHE_DIR / "schemes")

    # -r
    if args.r:
        sequences.reload_colors(args.t)

    # -v
    if args.v:
        print(f"wal {__version__}")
        exit(0)

    # -i
    if args.i:
        image_file = image.get_image(args.i)

        # Create a list of hex colors.
        colors_plain = magic.get_colors(image_file, args.q)

        if not args.n:
            wallpaper.set_wallpaper(image_file)

    # -f
    elif args.f:
        colors_plain = util.read_file_json(args.f)

    # -i or -f
    if args.i or args.f:
        sequences.send_sequences(colors_plain, args.t)
        export.export_all_templates(colors_plain)
        reload.reload_env()

    # -o
    if args.o:
        util.disown(args.o)
Esempio n. 3
0
def process_args(args):
    """Process args."""
    # If no args were passed.
    if not len(sys.argv) > 1:
        print("error: wal needs to be given arguments to run.\n"
              "       Refer to \"wal -h\" for more info.")
        exit(1)

    # -q
    if args.q:
        sys.stdout = sys.stderr = open(os.devnull, "w")

    # -c
    if args.c:
        shutil.rmtree(CACHE_DIR / "schemes")
        util.create_dir(CACHE_DIR / "schemes")

    # -r
    if args.r:
        set_colors.reload_colors(args.t)

    # -v
    if args.v:
        print(f"wal {__version__}")
        exit(0)

    # -i
    if args.i:
        image = gen_colors.get_image(args.i)

        # Create a list of hex colors.
        colors_plain = gen_colors.get_colors(image, args.q)
        colors_plain[8] = set_colors.set_grey(colors_plain)

        if not args.n:
            wallpaper.set_wallpaper(image)

        # Set the colors.
        set_colors.send_sequences(colors_plain, args.t)
        export_colors.export_colors(colors_plain)

    # -o
    if args.o:
        util.disown(args.o)
Esempio n. 4
0
"""Test export functions."""
import unittest
import unittest.mock
import io
import pathlib

from pywal import export
from pywal import util

# Import colors.
COLORS = util.read_file_json("tests/test_files/test_file.json")
COLORS["colors"].update(COLORS["special"])
OUTPUT_DIR = pathlib.Path("/tmp/wal")

util.create_dir("/tmp/wal")


class TestExportColors(unittest.TestCase):
    """Test the export functions."""
    def test_all_templates(self):
        """> Test substitutions in template file."""
        export.every(COLORS, OUTPUT_DIR)

        result = pathlib.Path("/tmp/wal/colors.sh").is_file()
        self.assertTrue(result)

        content = pathlib.Path("/tmp/wal/colors.sh").read_text()
        content = content.split("\n")[6]
        self.assertEqual(content, "foreground='#F5F1F4'")

    def test_css_template(self):
Esempio n. 5
0
def main():
    """Main script function."""
    util.create_dir(CACHE_DIR / "schemes")
    args = get_args()
    process_args(args)
Esempio n. 6
0
 def setUp(self):
     """> Setup export tests."""
     util.create_dir(TMP_DIR)
Esempio n. 7
0
 def test_create_dir(self):
     """> Create a directory."""
     tmp_dir = "/tmp/test_dir"
     util.create_dir(tmp_dir)
     self.assertTrue(os.path.isdir(tmp_dir))
     os.rmdir(tmp_dir)