From 70b936e279154bc802ae05f4eb265ef1f4e22528 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Tue, 7 Mar 2017 21:00:19 +0100 Subject: Rights and Updater class --- pycrctrl.py | 181 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 130 insertions(+), 51 deletions(-) diff --git a/pycrctrl.py b/pycrctrl.py index e53a722..6935512 100644 --- a/pycrctrl.py +++ b/pycrctrl.py @@ -15,29 +15,30 @@ import sys -if sys.version_info < (3,6): - class ModuleNotFoundError(ImportError): - pass - -import socket +#import socket import subprocess import urllib.request import urllib.error import urllib.parse from _thread import start_new_thread -import inspect +#import inspect import queue -import traceback import os import re -import signal +#import signal import json import base64 +import supybot.log import supybot.ircmsgs as ircmsgs from pickle import Pickler, Unpickler from PyQt5.QtCore import * +from time import sleep +from platform import architecture +from io import BytesIO +#iostream import + try: from iostream import * except ModuleNotFoundError: @@ -47,6 +48,8 @@ except ModuleNotFoundError: from iostream import * import random +import tarfile +from gzip import GzipFile from time import sleep from enum import IntEnum @@ -57,38 +60,44 @@ from enum import IntEnum class QString(str): pass -class QStringList(QObject): +class QList(QObject): """ QStringList """ - typeclass = str - strlist = list() + list = list() + typeclass = None def __init__(self, *args): QObject.__init__(self) - self.strlist = list(args) + self.list = list(args) def __getitem__(self, name): if type(name) != int: raise ValueError("Wrong datatype for name!") else: - return self.strlist[name] + return self.list[name] def __lshift__(self, other): - if type(other) != self.typeclass: + if self.typeclass and not isinstance(other, self.typeclass): raise ValueError("Wrong datatype") else: - self.strlist.append(other) + self.list.append(other) def __call__(self): - return self.strlist + return self.list def __len__(self): - return len(self.strlist) + return len(self.list) + + def __repr__(self): + return "{}({})".format(self.__name__, self.list) # Methods def isEmpty(self): - return len(self.strlist) == 0 + return len(self.list) == 0 + +class QStringList(QList): + typeclass = str class CmdResult(IntEnum): UnknownCommand = -1 @@ -103,6 +112,96 @@ class Capability(IntEnum): Admin = 1 Moderator = 2 +class Updater(object): + parent = None + __current_revision = "" + lookuptable = {"64bit" : "amd64", "32bit" : "i386"} + + def __init__(self, parent): + self.parent = parent + with open(os.path.join(self.parent.path, "snapshot.id"), "rb") as fobj: + self.__current_revision = fobj.read().decode("utf-8") + start_new_thread(self.checkForUpdates, ()) + + @property + def current_revision(self): + return self.__current_revision + + @current_revision.setter + def current_revision(self, other): + self.__current_revision = other + if type(other) in [QString, str]: + try: + other = other.encode("utf-8") + except Exception: + raise TypeError("Wrong datatype!") from None + + with open(os.path.join(self.parent.path, "snapshot.id"), "wb") as fobj: + fobj.write(other) + + def checkForUpdates(self): + while True: + try: + site = urllib.request.urlopen("http://openclonk.org/nightly-builds").read().decode("utf-8").split("