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
Branch feature/fetchlibrary (0a4b7d)
by David
01:16
created

SyncProgress.push()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
#!/usr/bin/python
2
# -*- coding: UTF-8 -*-
3
import time
4
import threading
5
import xbmc, xbmcgui, xbmcaddon
6
__addon__ = xbmcaddon.Addon("script.simkl")
7
from simklapi import api as API
8
tmp = time.time()
9
10
__icon__ = __addon__.getAddonInfo("icon")
11
def getstr(strid): return __addon__.getLocalizedString(strid)
12
13
xbmc.log("Simkl: Icon: "+str(__icon__))
14
15
not_dialog = xbmcgui.Dialog()
16
def notify(txt="Test", title="Simkl", icon=__icon__):
17
    not_dialog.notification(title, txt, icon)
18
19
PIN_LABEL      = 201
20
INSTRUCTION_ID = 202
21
CANCEL_BUTTON  = 203
22
ACTION_PREVIOUS_MENU = 10
23
ACTION_BACK = 92
24
25
#xmlfile = ""
26
#script  = __addon__.getAddonInfo("path").decode("utf-8")
27
def login(logged):
28
    """Change the things that need to be changed. E.g: The settings dialog"""
29
    __addon__.setSetting("loginbool", str(bool(1)).lower())
30
31
class loginDialog(xbmcgui.WindowXMLDialog):
32
    """ The login dialog popped when you click on LogIn """
33
    def __init__(self, xmlFilename, scriptPath, pin, url, check_login, log,
34
        exp=900, inter=5, api=None):
35
        self.pin = pin
36
        self.url = url
37
        self.check_login = check_login
38
        self.log = log
39
        self.exp = exp
40
        self.inter = inter
41
        self.api = api
42
        self.waiting = True
43
        self.canceled = False
44
45
    def threaded(self):
46
        """ A loop threaded function, so you can do another things meanwhile """
47
        xbmc.log("Simkl: threaded: {0}".format(self))
48
        cnt = 0
49
        while self.waiting:
50
            if cnt % (self.inter+1) == 0 and cnt>1:
51
                xbmc.log("Simkl: Still waiting... {0}".format(cnt))
52
                if self.check_login(self.pin, self.log):
53
54
                    xbmc.log(str(self.api.USERSETTINGS))
55
                    notify(getstr(32030).format(self.api.USERSETTINGS["user"]["name"]))
56
                    self.waiting = False
57
                    #Now check that the user has done what it has to be done
58
59
            cnt += 1
60
            time.sleep(1)
61
            if self.canceled or cnt >= self.exp:
62
                self.waiting = False
63
                notify(getstr(32031))
64
65
        xbmc.log("Simkl: Stop waiting")
66
        self.close()
67
68
    def onInit(self):
69
        """The function that is loaded on Window init"""
70
        instruction = self.getControl(INSTRUCTION_ID)
71
        instruction.setLabel(
72
            getstr(32022).format("[COLOR ffffbf00]" + self.url + "[/COLOR]"))
73
        self.getControl(PIN_LABEL).setLabel(self.pin)
74
        xbmc.log("Simkl: Visible: {0}".format(self.getProperty("visible")))
75
76
        t = threading.Thread(target=self.threaded)
77
        t.start()
78
79
        if API.is_user_logged(): #If user is alredy logged in
80
            dialog = xbmcgui.Dialog()
81
            username = API.USERSETTINGS["user"]["name"]
82
            ret = dialog.yesno("Simkl LogIn Warning", getstr(32032).format(username),
83
                nolabel=getstr(32034), yeslabel=getstr(32033), autoclose=30000)
84
            #xbmc.log("Ret: {0}".format(ret))
85
            xbmc.log("Simkl:ret: {0}".format(ret))
86
            if ret == 1: pass
87
            elif ret == 0:
88
                self.onClick(CANCEL_BUTTON)
89
            return
90
91
    def onControl(self, controlID):
92
        pass
93
    def onFocus(self, controlID):
94
        pass
95
96
    def onAction(self, action):
97
        if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
98
            self.canceled = True
99
            self.close()
100
101
    def onClick(self, controlID):
102
        xbmc.log("Simkl: onclick {0}, {1}".format(controlID, self))
103
        if controlID == CANCEL_BUTTON:
104
            self.canceled = True
105
106
class SyncProgress(xbmcgui.DialogProgressBG):
107
    def __init__(self, media="None", mode="None"):
108
        self.cnt = 0
109
        self.msg = "Simkl: Syncing {0} library, {1} mode".format(media, mode)
110
        self.create(self.msg, "Starting")
111
112
    def push(self, i, message=None):
113
        self.cnt += i
114
        self.update(int(self.cnt), message=message)
115
116