Skip to content

Commit

Permalink
feat: add version arg, improve settings
Browse files Browse the repository at this point in the history
  • Loading branch information
png261 committed Jun 18, 2023
1 parent 33e4886 commit 171825a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
2 changes: 2 additions & 0 deletions pywalc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from .settings import __version__
from . import server
from . import colors
from . import theme
from . import wallpaper
from . import theme

__all__ = [
"__version__",
"server",
"colors",
"theme",
Expand Down
40 changes: 33 additions & 7 deletions pywalc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
import os

from . import util
from .settings import WAL_FILE, BACKUP_FILE, WALLPAPER_DIR, CACHE_DIR, PYWALL_CACHE
import argparse

from .settings import (
__version__,
PYWAL_FILE_PATH,
BACKUP_FILE,
WALLPAPER_DIR,
CACHE_DIR,
PYWAL_CURRENT_WALLPAPER,
)
from .server import Server
from . import util


def get_args():
"""Get the script arguments."""
description = "pywalc - Pywal client"
arg = argparse.ArgumentParser(description=description)

arg.add_argument("-v", action="store_true", help='Print "pywalc" version.')

return arg


def parse_args_exit(parser):
"""Process args that exit."""
args = parser.parse_args()

if args.v:
parser.exit(0, "wal %s\n" % __version__)


def main():
"""Main script function."""
util.setup_logging()

util.create_dir(CACHE_DIR)
util.create_dir(WALLPAPER_DIR)
util.copy_dir(WAL_FILE, BACKUP_FILE)
util.copy_dir(PYWAL_FILE_PATH, BACKUP_FILE)
util.copy_dir(PYWAL_CURRENT_WALLPAPER, os.path.join(WALLPAPER_DIR, "current"))

current_wallpaper = util.read_file(os.path.join(PYWALL_CACHE, "wal"))[0]
util.copy_dir(current_wallpaper, os.path.join(WALLPAPER_DIR, "current"))
parser = get_args()
parse_args_exit(parser)

server = Server(2601)
server.run()
Expand Down
4 changes: 2 additions & 2 deletions pywalc/colors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pywal
from fastapi import Request

from .settings import BACKUP_FILE, WAL
from .settings import BACKUP_FILE, PYWAL_DATA
from . import util


class Color:
def __init__(self):
self.data = WAL["colors"]
self.data = PYWAL_DATA["colors"]

def get(self):
return self.data
Expand Down
15 changes: 8 additions & 7 deletions pywalc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from uvicorn import run
from pycloudflared import try_cloudflare

from .settings import CACHE_DIR, OS
from .settings import CACHE_DIR, MODULE_DIR, OS
from .colors import Color
from .theme import Theme
from .wallpaper import Wallpaper
Expand Down Expand Up @@ -57,14 +57,15 @@ def __init__(self, port):
)

self.server.mount("/cache", StaticFiles(directory=CACHE_DIR), name="cache")
self.server.mount(
"/static",
StaticFiles(directory=os.path.join(MODULE_DIR, "static")),
name="static",
)

static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
self.server.mount("/static", StaticFiles(directory=static_dir), name="static")

templates_dir = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "templates"
self.templates = Jinja2Templates(
directory=os.path.join(MODULE_DIR, "templates")
)
self.templates = Jinja2Templates(directory=templates_dir)

self._setup_routes()

Expand Down
17 changes: 11 additions & 6 deletions pywalc/settings.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import pywal
import os
from . import util

__version__ = "0.1.0"

HOME = pywal.settings.HOME
OS = pywal.settings.OS
XDG_CACHE_DIR = os.getenv("XDG_CACHE_HOME", os.path.join(HOME, ".cache"))

PYWALL_CACHE = pywal.settings.CACHE_DIR
MODULE_DIR = pywal.settings.MODULE_DIR
PYWAL_FILE_PATH = os.path.join(PYWALL_CACHE, "colors.json")
PYWAL_DATA = pywal.colors.file(PYWAL_FILE_PATH)
PYWAL_CURRENT_WALLPAPER = util.read_file(os.path.join(PYWALL_CACHE, "wal"))[0]

CACHE_DIR = os.path.join(HOME, ".cache", "pywalc")
MODULE_DIR = os.path.dirname(__file__)
CACHE_DIR = os.path.join(XDG_CACHE_DIR, "pywalc")
WALLPAPER_DIR = os.path.join(CACHE_DIR, "wallpapers")

BACKUP_FILE = os.path.join(CACHE_DIR, "backup.json")
WAL_FILE = os.path.join(PYWALL_CACHE, "colors.json")

WAL = pywal.colors.file(WAL_FILE)
OS = pywal.settings.OS
5 changes: 3 additions & 2 deletions pywalc/wallpaper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import uuid
from typing import List
import pywal
from fastapi import File, UploadFile
from typing import List

from .settings import WALLPAPER_DIR
from . import util
from fastapi import File, UploadFile


class Wallpaper:
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools

LONG_DESC = open("README.md").read()
VERSION = "1.0.4"
VERSION = '0.1.0'
DOWNLOAD = "https://github.com/png261/pywalc/archive/%s.tar.gz" % VERSION

setuptools.setup(
Expand All @@ -25,6 +25,7 @@
],
packages=["pywalc"],
entry_points={"console_scripts": ["pywalc=pywalc.__main__:main"]},
python_requires=">=3.5",
install_requires=[
"pywal>=3.3.0",
"fastapi>=0.97.0",
Expand All @@ -33,6 +34,7 @@
"Jinja2>=3.1.2",
"python-multipart>=0.0.6",
"qrcode>=7.4.2",
"argparse>=1.4.0 ",
],
include_package_data=True,
zip_safe=False,
Expand Down

0 comments on commit 171825a

Please sign in to comment.