GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 2c61a7...12a538 )
by Benjamin
01:11
created

Helper   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 14
c 2
b 0
f 1
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A clean_up() 0 8 3
A send_notifaction() 0 12 1
B check_config() 0 25 6
A get_config() 0 19 3
A set_wallpaper() 0 4 1
1
import os
2
from configparser import ConfigParser
3
from os import listdir
4
from gi.repository import Notify, GdkPixbuf
5
6
7
class Helper(object):
8
    def get_config(self):
9
        config_file_path = os.path.dirname(os.path.realpath(__file__)) + '/config.ini'
10
        if not os.path.exists(config_file_path):
11
            return self.check_config(None)
12
13
        config_reader = ConfigParser()
14
        config_reader.read(config_file_path)
15
16
        config = {}
17
        config['wallpapers_directory'] = config_reader.get('settings', 'wallpapers_directory')
18
        config['refresh_rate'] = config_reader.get('settings', 'refresh_rate')
19
        config['subs'] = config_reader.get('settings', 'subs')
20
        config['only_local'] = config_reader.get('settings', 'only_local')
21
        config['over_18'] = config_reader.get('settings', 'allow_nsfw')
22
23
        if not config['subs'] == "":
24
            config['subs'] = config['subs'].split(',')
25
26
        return self.check_config(config)
27
28
    def check_config(self, config):
29
        if config is None:
30
            config = {}
31
            config['wallpapers_directory'] = '~/Pictures/RedditWallpapers/'
32
            config['refresh_rate'] = 120
33
            config['subs'] = ['wallpapers']
34
            config['only_local'] = False
35
            config['over_18'] = False
36
37
        config['wallpapers_directory'] = config['wallpapers_directory'].replace('~', os.path.expanduser("~"))
38
        os.system("mkdir -p " + config['wallpapers_directory'])
39
40
        if len(config['subs']) <= 0:
41
            config['subs'] = ['wallpapers']
42
43
        if not str(config['refresh_rate']).isdigit():
44
            config['refresh_rate'] = 120
45
46
        if config['only_local'] == '':
47
            config['only_local'] = False
48
49
        if config['over_18'] == '':
50
            config['over_18'] = False
51
52
        return config
53
54
    def set_wallpaper(self, image):
55
        print('loading new wallpaper' + image)
56
        os.system("gsettings set org.gnome.desktop.background picture-uri file://" + image)
57
        self.send_notifaction()
58
59
    def send_notifaction(self):
60
        Notify.init("Wallpaper Changer")
61
        notification = Notify.Notification.new(
62
            'New wallpaper has been set!',
63
            #'this is the body',
64
        )
65
66
        image = GdkPixbuf.Pixbuf.new_from_file(os.path.dirname(os.path.realpath(__file__)) + '/alien.png')
67
        notification.set_icon_from_pixbuf(image)
68
        notification.set_image_from_pixbuf(image)
69
70
        notification.show()
71
72
    def clean_up(self, config):
73
        all_files = listdir(config['wallpapers_directory'])
74
75
        for image in all_files:
76
            file = config['wallpapers_directory'] + image
77
78
            if os.stat(file).st_size == 0:
79
                os.remove(file)
80