def sendfile(self, src=None, filename="", data=None): """ upload file args: data content for fine to upload src file to load upload content ( if data is None ) filename name for remote file """ if self.debug & 0x01: print("sendfile : ", self.__class__.__name__) if filename[0] != '/': filename = "/USER/WEB/" + filename elif not str(filename).upper().startswith("/USER/WEB/"): raise IsyE.IsyValueError( "sendfile: invalid dst filename : {!s}".format(filename)) # not len(data) if not data: if not src: src = filename if self.debug & 0x20: print("using file {!s} as data src".format(src)) with open(src, 'r') as content_file: data = content_file.read() else: if self.debug & 0x20: print("using provided data as data src") return self._sendfile(filename=filename, data=data, load="n")
def net_resource_get_src(self, rrid): rid = self._net_resource_get_id(rrid) if rid is None: raise IsyE.IsyValueError( "net_resource_get_src: bad network resources ID : " + rrid) r = self.soapcomm("GetSysConf", name="/CONF/NET/" + rrid + ".RES") return r
def __init__(self, isy, objdict): """ INIT """ self.error_str = "" if isinstance(objdict, dict): self._mydict = objdict else: raise IsyE.IsyValueError("{!s}: called without objdict".format( self.__class__.__name__)) if isinstance(isy, IsyUtil): self.isy = isy self.debug = isy.debug else: # print("error : class " + self.__class__.__name__ + " called without Isy") raise TypeError("IsySubClass: isy arg is not a ISY family class") if self.debug & 0x04: print("IsySubClass: ", end='') self._printdict(self._mydict)
def net_resource_run(self, rrid): """ Calls and executes net resource args: rrid : network resource ID calls : /rest/networking/resources/<rrid> """ rid = self._net_resource_get_id(rrid) if rid is None: raise IsyE.IsyValueError( "net_resource_run : bad network resources ID : " + rrid) xurl = "/rest/networking/resources/{!s}".format(rid) if self.debug & 0x02: print("wol : xurl = " + xurl) resp = self._getXMLetree(xurl) # self._printXML(resp) if resp is None or resp.attrib["succeeded"] != 'true': raise IsyE.IsyResponseError("ISY network resources error : rid=" + str(rid))
def net_wol(self, wid): """ Send Wake On LAN to registared wol ID args: wid : WOL resource ID calls : /rest/networking/wol/<wol_id> """ wol_id = self._net_wol_get_id(wid) # wol_id = str(wid).upper() if wol_id is None: raise IsyE.IsyValueError("bad wol ID : " + wid) xurl = "/rest/networking/wol/" + wol_id if self.debug & 0x02: print("wol : xurl = " + xurl) resp = self._getXMLetree(xurl) # self._printXML(resp) if resp.attrib["succeeded"] != 'true': raise IsyE.IsyResponseError("ISY command error : cmd=wol wol_id=" \ + str(wol_id))
def format_node_addr(naddr): if not isinstance(naddr, str): raise IsyE.IsyValueError("{0} arg not string".format(__name__)) addr_el = naddr.upper().split() a = "{0:0>2}' '{1:0>2}' '{2:0>2}' ".format(*addr_el) return a
def soapcomm(self, cmd, **kwargs): """ takes a command name and a list of keyword arguments. each keyword is converted into a xml element """ if not isinstance(cmd, str) or not cmd: raise IsyE.IsyValueError("SOAP Method name missing") # if self.debug & 0x02: # print("sendcomm : ", cmd) soap_cmd = self._gensoap(cmd, **kwargs) xurl = self.baseurl + "/services" if self.debug & 0x02: # print("xurl = ", xurl) print("soap_cmd = ", soap_cmd) # req_headers = {'content-type': 'application/soap+xml'} # req_headers = {'content-type': 'text/xml'} req_headers = {'Content-Type': 'application/xml; charset="utf-8"'} # req = URL.Request(xurl, soap_cmd, {'Content-Type': 'application/xml; charset="utf-8"'}) data = "" try: res = self._req_session.post(xurl, data=soap_cmd, headers=req_headers) data = res.text # res.content if self.debug & 0x200: print("res.status_code ", res.status_code, len(data)) print("data ", data) res.close() # except URL.HTTPError as e: except requests.exceptions.RequestException as rex: status_code = rex.response.status_code self.error_str = str("Reponse Code : {0} : {1} {2}").format( status_code, xurl, cmd) if ((cmd == "DiscoverNodes" and rex.response.status_code == 803) or (cmd == "CancelNodesDiscovery" and status_code == 501) # or (cmd == "RemoveNode" and status_code == 501) ): if self.debug & 0x02: print("spacial case : {0} : {1}".format(cmd, status_code)) print("status_code = ", status_code) print("response.reason = ", rex.response.reason) print("response.headers = ", rex.response.headers) # print("e.filename = ", e.filename) print("\n") return rex.response.text if self.debug & 0x202: print("status_code = ", status_code) # print("e.read = ", e.read()) print("RequestException = ", rex) print("data = ", data) mess = "{!s} : {!s} : {!s}".format(cmd, kwargs, status_code) # This a messy and should change raise IsyE.IsySoapError(mess, httperr=rex) else: if self.error_str: # len self.error_str = "" if self.debug & 0x200: print(data) return data