diff options
| author | Fulgen301 <tokmajigeorge@gmail.com> | 2017-08-18 17:59:35 +0200 |
|---|---|---|
| committer | Fulgen301 <tokmajigeorge@gmail.com> | 2017-08-18 17:59:35 +0200 |
| commit | c7fe28d5586c0a14ad680e9f062b917bf3a6b404 (patch) | |
| tree | 5654a172463f7ebba54f7ff03d8723c6f7a02280 /pycrctrl.py | |
| parent | 222d96a9bfcd8002c6e3b76efdba731dbbcdedda (diff) | |
| download | pycrctrl-c7fe28d5586c0a14ad680e9f062b917bf3a6b404.tar.gz pycrctrl-c7fe28d5586c0a14ad680e9f062b917bf3a6b404.zip | |
* Updater now uses absolute addresses
* Change log behavior
Diffstat (limited to 'pycrctrl.py')
| -rw-r--r-- | pycrctrl.py | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/pycrctrl.py b/pycrctrl.py index 9361d61..2f5d381 100644 --- a/pycrctrl.py +++ b/pycrctrl.py @@ -104,33 +104,33 @@ class Updater(object): def checkForUpdates(self): while True: try: - site = urllib.request.urlopen(self.parent.config["Addresses"]["snapshotList"]).read().decode("utf-8").split(self.parent.config["Updater"]["SplitString"]) + site = urllib.request.urlopen("http://openclonk.org/nightly-builds").read().decode("utf-8").split("<a href='/builds/nightly/snapshots/") site.remove(site[0]) site = [i.split("' title")[0] for i in site] x = None for i in site: - x = re.match(self.parent.config["RegExps"]["Snapshot"].format(sys.platform, self.lookuptable[architecture()[0]]), i) + x = re.match(r"openclonk-snapshot-(.*)-(.*)-{}-{}-.*".format(sys.platform, self.lookuptable[architecture()[0]]), i) if x: rev = x.group(2) if self.current_revision != rev: self.current_revision = rev - self.loadNewSnapshot(x) + self.loadNewSnapshot(i) break if not x: - self.parent.log.error("Updater: Update regular expression doesn't match!") + self.parent.log.error("Updater.checkForUpdates: Regular expression doesn't match!") except Exception as e: - cerr << str(e) << endl + self.parent.log.error(str(e.args[0])) finally: sleep(10) - def loadNewSnapshot(self, reg): + def loadNewSnapshot(self, f): self.parent.log.info("Downloading snapshot with id {}".format(self.current_revision)) with open(os.path.join(self.parent.path, "snapshot"), "wb") as fobj: - fobj.write(urllib.request.urlopen(self.parent.config["Addresses"]["snapshotDownload"].format(reg.group(0).split("' title")[0])).read()) + fobj.write(urllib.request.urlopen("http://openclonk.org/builds/nightly/snapshots/{}".format(f))) #extract the snapshot tar = tarfile.open(os.path.join(self.parent.path, "snapshot"), mode="r:bz2") @@ -138,26 +138,26 @@ class Updater(object): self.parent.log.info("New snapshot has been extracted.") #get the openclonk-server autobuild - site = json.loads(urllib.request.urlopen(self.parent.config["Addresses"]["autobuildList"]).read().decode("utf-8")) + site = json.loads(urllib.request.urlopen("https://autobuild.openclonk.org/api/v1/jobs").read().decode("utf-8")) for commit in site: for build in commit["builds"]: if re.match(r"{}-{}-.*".format(sys.platform, self.lookuptable[architecture()[0]]), build["platform"]["triplet"]): for b in build["components"]: - reg = re.match(self.parent.config["RegExps"]["Autobuild"], str(b["path"])) #skip the engine check as the only useful one is openclonk-server + reg = re.match(r".*/openclonk-server-(.*)-(.*)-(.*)-.*", str(b["path"])) #skip the engine check as the only useful one is openclonk-server if reg and (reg.group(1), reg.group(2), reg.group(3)) == (self.current_revision[:-3], sys.platform, self.lookuptable[architecture()[0]]): self.parent.log.info("Downloading autobuild with id {}".format(self.current_revision)) buffer = BytesIO() - buffer.write(urllib.request.urlopen(self.parent.config["Addresses"]["autobuildDownload"].format(b["path"])).read()) + buffer.write(urllib.request.urlopen("https://autobuild.openclonk.org/static/binaries/{}".format(b["path"])).read()) buffer.seek(0) - with open(os.path.join(self.parent.path, self.parent.config["Updater"]["BinaryName"]), "wb") as fobj: + with open(os.path.join(self.parent.path, self.parent.config["Clonk"]["Engine"]), "wb") as fobj: fobj.write(GzipFile(fileobj=buffer).read()) self.parent.log.info("New openclonk-server build has been extracted.") - os.chmod(os.path.join(self.parent.path, self.parent.config["Updater"]["BinaryName"]), os.stat(os.path.join(self.parent.path, self.parent.config["Updater"]["BinaryName"])).st_mode | 64) + os.chmod( + os.path.join(self.parent.path, self.parent.config["Clonk"]["Engine"]), + os.stat(os.path.join(self.parent.path, self.parent.config["Clonk"]["Engine"])).st_mode | 64) return True - - class PyCRCtrl(object): """Server control""" @@ -182,6 +182,7 @@ class PyCRCtrl(object): updater = None log = None + logfile = None shutdowned = False @property @@ -209,7 +210,7 @@ class PyCRCtrl(object): self.path = path self.loadConfigFile(config) self.setupLog() - self.ingamechat = "aktiviert" if self.config["Clonk"].getboolean("Autohost") else "deaktiviert" + self.__ingamechat = "aktiviert" if self.config["Clonk"].getboolean("Autohost") else "deaktiviert" # important because there is no scenario hostet yet self.loadScenarioList() self.queue = queue.Queue(5) @@ -229,16 +230,20 @@ class PyCRCtrl(object): self.log.debug("Scenario lists loaded.") def setupLog(self) -> None: + if self.log: + return + self.log = logging.getLogger(type(self).__name__) self.log.setLevel(getattr(logging, self.config["Logging"]["Level"], logging.INFO)) - ch = logging.FileHandler( - os.path.join(self.path, self.config["Logging"]["File"]) - ) - ch.setLevel(getattr(logging, self.config["Logging"]["Level"], logging.INFO)) - ch.setFormatter(logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s")) - - self.log.addHandler(ch) + if not hasattr(self.log, "handler_set"): + ch = logging.FileHandler( + os.path.join(self.path, self.config["Logging"]["File"]) + ) + ch.setLevel(getattr(logging, self.config["Logging"]["Level"], logging.INFO)) + ch.setFormatter(logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s")) + + self.log.addHandler(ch) self.log.info("PyCRCtrl started.") def loadConfigFile(self, config) -> None: @@ -314,6 +319,7 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-.""" encoding=self.config["Clonk"]["Encoding"] ) self.state = "Lobby" + self.log.info("Scenario: {}".format(self.scenario)) self.readServerOutput() if self.config["Clonk"].getboolean("Autohost") == False: self.thread_started = False @@ -354,22 +360,24 @@ Snapshot=openclonk-snapshot-(.*)-(.*)-{}-{}-.""" cmd = part.group(3).split(" ", 1) found = False x = None - if len(cmd) > 0: - for key in self.commands.keys(): - if key == cmd[0].splitlines()[0]: - found = True - try: - x = self.commands[key](cmd[1].split(" "), user=part.group(1)) - except IndexError: - x = self.commands[key](user=part.group(1)) + try: + if len(cmd) > 0: + key = cmd[0].splitlines()[0] + if not hasattr(self, key): + raise RuntimeError + try: + x = getattr(self, key)(cmd[1].split(" "), user=part.group(1)) + except IndexError: + x = getattr(self, key)(user=part.group(1)) break - if not found: + except RuntimeError: self.writeToServer('Unbekannter Befehl: "' + part.group(2) + '"!') if x: if type(x) == tuple and x[1] != "": self.writeToServer(x[1]) del x + if re.match(self.config["RegExps"]["LobbyStart"], output): self.state = "Lädt" |
