def __init__(self, parent, release, gridrow): "Initialise the ``News``." padx, pady = 10, 5 # formatting sticky = tk.EW + tk.N # full width, stuck to the top anchor = tk.NW Frame.__init__(self, parent) self.installed = False self.auto = tk.IntVar(value=config.getint("AutoUpdate")) self.novoices = tk.IntVar(value=config.getint("NoVoices")) self.rmbackup = tk.IntVar(value=config.getint("RemoveBackup")) self.columnconfigure(1, weight=1) self.grid(row=gridrow, column=0, sticky="NSEW", columnspan=2) self.label = tk.Label(self, text="Release:") self.label.grid(row=0, column=0, sticky=sticky) self.hyperlink = ReleaseLink(self) self.hyperlink.grid(row=0, column=1, sticky="NSEW") self.button = tk.Button(self, text="Click here to upgrade", command=self.click_installer) self.button.grid(row=1, column=0, columnspan=2, sticky="NSEW") self.button.grid_remove() self.release = release self.news_count = 0 self.news_pos = 0 self.minutes = 0 self.latest = {} # self.hyperlink.bind('<Configure>', self.hyperlink.configure_event) self.bind('<<ReleaseUpdate>>', self.release_update) debug(config.get('Canonn:RemoveBackup')) self.update(None) if self.rmbackup.get( ) == 1 and config.get('Canonn:RemoveBackup') != "None": delete_dir = config.get('Canonn:RemoveBackup') debug('Canonn:RemoveBackup {}'.format(delete_dir)) try: shutil.rmtree(delete_dir) except: error("Cant delete {}".format(delete_dir)) # lets not keep trying config.set('Canonn:RemoveBackup', "None")
def get_excludes(cls): # hard coded may as well get the exclude from live url = "https://api.canonn.tech" tempexcludes = {} r = requests.get("{}/excludeevents?_limit=1000".format(url)) if r.status_code == requests.codes.ok: # populate a local variable so other threads dont see incomplete results for exc in r.json(): tempexcludes[exc["eventName"]] = True CanonnJournal.exclusions = tempexcludes debug("Jouurnal excludes got") else: error("{}/excludeevents".format(url))
def run(self): url = "https://us-central1-canonn-api-236217.cloudfunctions.net/submitRaw?" url = url + "&cmdrName={}".format(self.cmdr) url = url + "&systemName={}".format(self.system) url = url + "&bodyName={}".format(self.body) url = url + "&station={}".format(self.station) url = url + "&event={}".format(self.entry.get("event")) url = url + "&x={}".format(self.x) url = url + "&y={}".format(self.y) url = url + "&z={}".format(self.z) url = url + "&lat={}".format(self.lat) url = url + "&lon={}".format(self.lon) url = url + "&is_beta={}".format(self.is_beta) url = url + "&raw_event={}".format( quote_plus( json.dumps(self.entry, ensure_ascii=False).encode('utf8'))) url = url + "&clientVersion={}".format(self.client) r = requests.get(url) if not r.status_code == requests.codes.ok: error("whiteListSetter {} ".format(url)) error(r.status_code) error(r.json()) results = [] else: results = r.json()
def installer(self): # need to add some defensive code around this tag_name = self.latest.get("tag_name") debug("Installing {}".format(tag_name)) new_plugin_dir = os.path.join(os.path.dirname(Release.plugin_dir), "EDMC-Canonn-{}".format(tag_name)) debug("Checking for pre-existence") if os.path.isdir(new_plugin_dir): error("Download already exists: {}".format(new_plugin_dir)) plug.show_error("Canonn upgrade failed") return False try: debug("Downloading new version") download = requests.get( "https://github.com/canonn-science/EDMC-Canonn/archive/{}.zip". format(tag_name), stream=True) try: z = zipfile.ZipFile(BytesIO(download.content)) z.extractall(os.path.dirname(Release.plugin_dir)) except: z = zipfile.ZipFile(StringIO.StringIO(download.content)) z.extractall(os.path.dirname(Release.plugin_dir)) except: error("Download failed: {}".format(new_plugin_dir)) plug.show_error("Canonn upgrade failed") return False # If we got this far then we have a new plugin so any failures and we will need to delete it debug("disable the current plugin") try: os.rename(Release.plugin_dir, "{}.disabled".format(Release.plugin_dir)) debug("Renamed {} to {}".format( Release.plugin_dir, "{}.disabled".format(Release.plugin_dir))) except: error("Upgrade failed reverting: {}".format(new_plugin_dir)) plug.show_error("Canonn upgrade failed") shutil.rmtree(new_plugin_dir) return False if self.rmbackup.get() == 1: config.set('Canonn:RemoveBackup', "{}.disabled".format(Release.plugin_dir)) debug("Upgrade complete") Release.plugin_dir = new_plugin_dir self.installed = True return True
def edsmGetSystem(cls, system): if not system: error("system is null") return if not system in cls.systemCache and not cls.scanned: #journalGetSystem() cls.scanned = True if system in cls.systemCache: return cls.systemCache[system] else: url = 'https://www.edsm.net/api-v1/system?systemName=' + quote_plus( system) + '&showCoordinates=1' r = requests.get(url) s = r.json() cls.systemCache[system] = (s["coords"]["x"], s["coords"]["y"], s["coords"]["z"]) return s["coords"]["x"], s["coords"]["y"], s["coords"]["z"]
def gSubmitAXCZ(self, payload): p = payload.copy() p["x"], p["y"], p["z"] = Systems.edsmGetSystem( payload.get("systemName")) if p.get("isBeta"): p["isBeta"] = 'Y' else: p["isBeta"] = 'N' p["rawJson"] = json.dumps(payload.get( "rawJson"), ensure_ascii=False).encode('utf8') url = "https://us-central1-canonn-api-236217.cloudfunctions.net/submitAXCZ" debug("gSubmitAXCZ {}".format(p.get("systemName"))) getstr = "{}?{}".format(url, urlencode(p)) debug("gsubmit {}".format(getstr)) r = requests.get(getstr) if not r.status_code == requests.codes.ok: error(getstr) error(r.status_code)
def run(self): debug("emitter.post") r = requests.post(self.url, data=json.dumps(self.payload, ensure_ascii=False).encode('utf8'), headers={"content-type": "application/json"}) if not r.status_code == requests.codes.ok: error(json.dumps(self.payload)) headers = r.headers contentType = str(headers['content-type']) if 'json' in contentType: error(json.dumps(r.content)) else: error(r.content) error(r.status_code) else: debug("emitter.post success") debug(json.dumps(r.json(), indent=4))
def run(self): debug("getting whiteList") url = "https://us-central1-canonn-api-236217.cloudfunctions.net/whitelist" r = requests.get(url) if not r.status_code == requests.codes.ok: error("whiteListGetter {} ".format(url)) error(r.status_code) error(r.json()) results = [] else: results = r.json() self.callback(results)
def run(self): # don't bother sending beta if self.is_beta == 'N': debug("sending gSubmitKill") url = "https://us-central1-canonn-api-236217.cloudfunctions.net/submitKills?cmdrName={}&systemName={}&isBeta={}&reward={}&victimFaction={}".format( self.cmdr, self.system, self.is_beta, self.reward, self.victimFaction) r = requests.get(url) if not r.status_code == requests.codes.ok: error("gSubmitKills {} ".format(url)) error(r.status_code) error(r.json())
def postFSS(cls, payload): url = "https://us-central1-canonn-api-236217.cloudfunctions.net/postEvent" debug("posting FSS") debug(payload) r = requests.post(url, data=json.dumps( payload, ensure_ascii=False).encode('utf8')) if not r.status_code == requests.codes.ok: headers = r.headers contentType = str(headers['content-type']) if 'json' in contentType: error(json.dumps(r.json())) else: error(r.content) error(r.status_code)
def run(self): debug("sending gSubmitCodex") url = "https://us-central1-canonn-api-236217.cloudfunctions.net/submitHD?cmdrName={}".format( self.cmdr) url = url + "&systemName={}".format(self.system) url = url + "&x={}".format(self.x) url = url + "&y={}".format(self.y) url = url + "&z={}".format(self.z) url = url + "&z={}".format(self.eddatetime) r = requests.get(url) if not r.status_code == requests.codes.ok: error("gSubmitHD {} ".format(url)) error(r.status_code) error(r.json())
def release_pull(self): self.latest = {} r = requests.get( "https://api.github.com/repos/canonn-science/EDMC-Canonn/releases/latest" ) latest = r.json() # debug(latest) if not r.status_code == requests.codes.ok: error("Error fetching release from github") error(r.status_code) error(r.json()) else: self.latest = latest debug("latest release downloaded") if not config.shutting_down: self.event_generate('<<ReleaseUpdate>>', when='tail')
def send(self, payload, url): fullurl = "{}/{}".format(url, self.modelreport) r = requests.post(fullurl, data=json.dumps(payload, ensure_ascii=False).encode('utf8'), headers={"content-type": "application/json"}) if not r.status_code == requests.codes.ok: error("{}/{}".format(url, self.modelreport)) error(r.status_code) headers = r.headers contentType = str(headers['content-type']) error(contentType) if 'json' in contentType: error(json.dumps(r.json())) else: if "Offline for Maintenance" in str(r.content): error("Canonn API Offline") else: error(r.content) error(json.dumps(payload)) else: debug("{}?id={}".format(fullurl, r.json().get("id")))