-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesktop_background.py
executable file
·51 lines (37 loc) · 1.28 KB
/
desktop_background.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
#!/usr/bin/env python
import logging
import importlib
from managers import bgmanager
logging.basicConfig()
logger = logging.getLogger('desktop_background:main')
logger.setLevel(logging.INFO)
__version__ = '1-flikr'
def get_plugin(name='earth'):
return importlib.import_module('plugins.%s' % name)
plugin = get_plugin()
def _parse_arguments():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source',
nargs='?', default='earth',
type=str, help='flikr earth')
parser.add_argument('-v', '--verbose', action='count', default=0)
args = parser.parse_args()
log_level = logging.WARN - 10*args.verbose
if log_level < 0:
log_level = logging.DEBUG
logger.setLevel(log_level)
return args.source
def set_background():
bgmanager.set_background(plugin.get_image())
if __name__ == '__main__':
plugin_name = _parse_arguments() or 'earth'
try:
logger.info(
"changing desktop background using '%s' plugin" % plugin_name)
plugin = get_plugin(plugin_name)
logger.debug("test debug")
except ImportError as ex:
logger.warning(
"No '%s' plugin found, fallback to default: 'earth'" % plugin_name)
set_background()