-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (58 loc) · 2.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
from argparse import ArgumentParser
import logging
import pathlib
import os
import random
import sys
if sys.platform == 'darwin':
from wallpaper.desktop.osx_desktop import OSX_Desktop as Desktop
else:
from wallpaper.desktop.windows_desktop import WindowsDesktop as Desktop
from wallpaper.config import WallpaperConfig
class Wallpaper:
"""
The master wallpaper object
"""
def __init__(self):
self.config = None
random.seed()
def get_config_file_options(self, options):
config_file = 'pywallpaper.json'
if options.config_file:
config_file = options.config_file
self.config = WallpaperConfig()
self.config.load(open(config_file, 'rt', encoding='utf-8'))
@staticmethod
def get_command_line_options():
parser = ArgumentParser()
parser.add_argument('--image', '-i', dest='single_image', default=None,
help='Set wallpaper to this image and exit (overrides -d)')
parser.add_argument('--directory', '-d', dest='directories', default=[], action='append',
type=str, help='Add an image directory')
parser.add_argument('--config', '-c', dest='config_file', default=None,
help='path to alternate config file (default <working dir>/pywallpaper.conf)')
parser.add_argument('--working-dir', '-w', dest='cwd', default='.', help='Working Directory (default .)')
parser.add_argument('--single_image', help='single image to set as wallpaper', default=None)
return parser.parse_args()
def go(self):
options = self.get_command_line_options()
if options.cwd and options.cwd != '.':
os.chdir(options.cwd)
elif sys.platform == 'darwin':
if os.getcwd() == '/':
os.chdir(pathlib.Path(sys.argv[0]).parent)
logging.info('Starting: %s', os.getcwd())
self.get_config_file_options(options)
desktop = Desktop(self.config)
if options.single_image:
desktop.set_wallpaper_from_image(options.single_image)
else:
desktop.generate_wallpaper()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, filename='/tmp/wallpaper.log')
pil_logger = logging.getLogger('PIL')
pil_logger.setLevel(logging.ERROR)
logging.info('Starting: %s', os.getcwd())
d = Wallpaper()
d.go()