def _compile(self, md, ars): mcp = md.Compile() smsg = mcp.get_name() try: cflgs = self._cpp_compiler_flags if cflgs is not None: if utils.is_windows(): mcp.set_cpp_compiler_flags("windows", cflgs) elif utils.is_linux(): mcp.set_cpp_compiler_flags("linux", cflgs) elif utils.is_mac(): mcp.set_cpp_compiler_flags("mac", cflgs) lflgs = self._linker_flags if lflgs is not None: if utils.is_windows(): mcp.set_linker_flags("windows", lflgs) elif utils.is_linux(): mcp.set_linker_flags("linux", lflgs) elif utils.is_mac(): mcp.set_linker_flags("mac", lflgs) mcp.run() smsg += " - OK!" ars.append(smsg) except Exception as e: smsg += " - ERROR: " + utils.exception_to_string(e) ars.append(smsg) raise e
def test_matching(self): self.assertTrue(utils.is_mac("00:C0:B7:7E:55:50")) self.assertTrue(utils.is_mac("00:c0:b7:7E:55:50")) self.assertFalse(utils.is_mac("00.D0.B7.7E.55.50")) self.assertFalse(utils.is_mac("testsystem0")) self.assertTrue(utils.is_ip("127.0.0.1")) self.assertTrue(utils.is_ip("192.168.1.1")) self.assertFalse(utils.is_ip("00:C0:B7:7E:55:50")) self.assertFalse(utils.is_ip("testsystem0"))
def run(self): utils.info("BEGIN " + self.get_name()) utils.make_tmppath() tarname=CONF["name"] + "-" + CONF["version"] + ".tar.gz" utils.remove_from_native(CONF) if os.path.exists(CONF["pathdst"]): utils.remove_path(CONF["pathdst"]) if os.path.exists(utils.PATHTMP + os.sep + tarname): utils.remove_path(utils.PATHTMP + os.sep + tarname) if os.path.exists(utils.PATHTMP + os.sep + CONF["name"] + "-" + CONF["version"]): utils.remove_path(utils.PATHTMP + os.sep + CONF["name"] + "-" + CONF["version"]) utils.download_file(CONF["urlsrc"], utils.PATHTMP + os.sep + tarname) utils.untar_file(utils.PATHTMP + os.sep + tarname, utils.PATHTMP) utils.remove_file(utils.PATHTMP + os.sep + tarname) os.rename(utils.PATHTMP + os.sep + CONF["name"] + "-" + CONF["version"], CONF["pathdst"]) if utils.is_mac(): #CORREGGE configure apppth=CONF["pathdst"] + os.sep + "configure" f = codecs.open(apppth, encoding='utf-8') appdata = f.read() f.close() appdata=appdata.replace('.dylib','.so').replace("-dynamiclib","-shared") os.remove(apppth) f = codecs.open(apppth, encoding='utf-8', mode='w+') f.write(appdata) f.close() os.chmod(apppth, stat.S_IRWXU) if utils.is_windows(): utils.system_exec(["mingw32-make.exe", "-fwin32/Makefile.gcc"],CONF["pathdst"]) else: utils.system_exec(["./configure"],CONF["pathdst"]) utils.system_exec(["make"],CONF["pathdst"]) if utils.is_mac(): #CORREGGE zutil.h apppth=CONF["pathdst"] + os.sep + "zutil.h" f = codecs.open(apppth, encoding='utf-8') appdata = f.read() f.close() appdata=appdata.replace('# define local static','//# define local static') os.remove(apppth) f = codecs.open(apppth, encoding='utf-8', mode='w+') f.write(appdata) f.close() utils.copy_to_native(CONF) utils.info("END " + self.get_name())
def __init__(self, reference_folder=None, screenshot_folder=None, keyword_on_failure='ImageHorizonLibrary.Take A Screenshot'): '''ImageHorizonLibrary can be imported with several options. ``reference_folder`` is path to the folder where all reference images are stored. It must be a _valid absolute path_. As the library is suite-specific (ie. new instance is created for every suite), different suites can have different folders for it's reference images. ``screenshot_folder`` is path to the folder where screenshots are saved. If not given, screenshots are saved to the current working directory. ``keyword_on_failure`` is the keyword to be run, when location-related keywords fail. If you wish to not take screenshots, use for example `BuiltIn.No Operation`. Keyword must however be a valid keyword. ''' self.reference_folder = reference_folder self.screenshot_folder = screenshot_folder self.keyword_on_failure = keyword_on_failure self.open_applications = OrderedDict() self.screenshot_counter = 1 self.is_windows = utils.is_windows() self.is_mac = utils.is_mac() self.is_linux = utils.is_linux()
def set_name(self,name): """ Set the name. If the name is a MAC or IP, and the first MAC and/or IP is not defined, go ahead and fill that value in. """ if self.name not in ["",None] and self.parent not in ["",None] and self.name == self.parent: raise CX(_("self parentage is weird")) if not isinstance(name, basestring): raise CX(_("name must be a string")) for x in name: if not x.isalnum() and not x in [ "_", "-", ".", ":", "+" ] : raise CX(_("invalid characters in name: %s") % x) # Stuff here defaults to eth0. Yes, it's ugly and hardcoded, but so was # the default interface behaviour that's now removed. ;) # --Jasper Capel if utils.is_mac(name): intf = self.__get_interface("eth0") if intf["mac_address"] == "": intf["mac_address"] = name elif utils.is_ip(name): intf = self.__get_interface("eth0") if intf["ip_address"] == "": intf["ip_address"] = name self.name = name return True
def set_name(self, name): """ Set the name. If the name is a MAC or IP, and the first MAC and/or IP is not defined, go ahead and fill that value in. """ if self.name not in ["", None] and self.parent not in [ "", None ] and self.name == self.parent: raise CX(_("self parentage is weird")) if not isinstance(name, basestring): raise CX(_("name must be a string")) for x in name: if not x.isalnum() and not x in ["_", "-", ".", ":", "+"]: raise CX(_("invalid characters in name: %s") % x) # Stuff here defaults to eth0. Yes, it's ugly and hardcoded, but so was # the default interface behaviour that's now removed. ;) # --Jasper Capel if utils.is_mac(name): intf = self.__get_interface("eth0") if intf["mac_address"] == "": intf["mac_address"] = name elif utils.is_ip(name): intf = self.__get_interface("eth0") if intf["ip_address"] == "": intf["ip_address"] = name self.name = name return True
def fmain(args): if utils.is_mac(): if len(args) > 1: a1 = args[1] if a1 is not None and a1.lower() == "guilnc": main = Mac() main.start_guilnc() sys.exit(0)
def get_suffix(): if utils.is_windows(): return "win" elif utils.is_linux(): return "linux" elif utils.is_mac(): return "mac" return None
def __init__(self, agent_main): self._agent_main=agent_main if utils.is_windows(): self._osnative = Windows(self._agent_main) elif utils.is_linux(): self._osnative = Linux() elif utils.is_mac(): self._osnative = Mac()
def before_copy_to_native(self, osn): if utils.is_mac(): confos = self._conf[osn] utils.system_exec([ "install_name_tool -change \"/usr/local/lib/librtaudio.6.dylib\" \"@loader_path/librtaudio.dylib\" " + confos["outname"] ], self._conf["pathdst"]) utils.system_exec([ "install_name_tool -change \"/usr/local/lib/libopus.0.dylib\" \"@loader_path/libopus.dylib\" " + confos["outname"] ], self._conf["pathdst"])
def before_copy_to_native(self, osn): if utils.is_mac(): confos = self._conf[osn] utils.system_exec([ "install_name_tool -change \"/usr/local/lib/libz.1.dylib\" \"@loader_path/libz.dylib\" " + confos["outname"] ], self._conf["pathdst"]) utils.system_exec([ "install_name_tool -change \"/opt/libjpeg-turbo/lib/libturbojpeg.0.2.0.dylib\" \"@loader_path/libturbojpeg.dylib\" " + confos["outname"] ], self._conf["pathdst"])
def _unload_lib_obj(olib): if utils.is_windows(): import _ctypes _ctypes.FreeLibrary(olib._handle) del olib elif utils.is_linux(): import _ctypes _ctypes.dlclose(olib._handle) del olib elif utils.is_mac(): import _ctypes _ctypes.dlclose(olib._handle) del olib
def run(self): utils.info("BEGIN " + self.get_name()) utils.make_tmppath() utils.remove_from_native(CONF) confos = utils.compile_lib(CONF) if confos is not None: if utils.is_mac(): utils.system_exec([ "install_name_tool -change \"/usr/local/lib/libz.1.so\" \"@loader_path/libz.so\" " + confos["outname"] ], CONF["pathdst"]) utils.copy_to_native(CONF) utils.info("END " + self.get_name())
def _dependency_post_fix(self, snm, sver): spth = self.get_path_tmp() + os.sep + snm if snm == "lib_z": if utils.is_mac(): #CORREGGE zutil.h apppth = spth + os.sep + "zutil.h" f = codecs.open(apppth, encoding='utf-8') appdata = f.read() f.close() appdata = appdata.replace('# define local static', '//# define local static') os.remove(apppth) f = codecs.open(apppth, encoding='utf-8', mode='w+') f.write(appdata) f.close()
def get(self, key): try: self._semaphore.acquire() try: if self._lang_current is None: applng = None try: if utils.is_windows(): import ctypes windll = ctypes.windll.kernel32 windll.GetUserDefaultUILanguage() wl = locale.windows_locale[ windll.GetUserDefaultUILanguage()] applng = wl.split("_")[0] elif utils.is_mac(): p = subprocess.Popen( ['defaults', 'read', '-g', 'AppleLocale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) sout, serr = p.communicate() if sout is not None: applng = sout.replace("\n", "").replace(" ", "_")[:10] except: None try: if applng is None: l = locale.getdefaultlocale() if l is not None: applng = l[0] except: None self._set_locale(applng) finally: self._semaphore.release() if key in self._data_current: return self._data_current[key] elif key in self._data_default: return self._data_default[key] else: return "RES_MISSING#" + key except: return "RES_ERROR#" + key
def set_mac_address(self,address,interface): if address == "random": address = utils.get_random_mac(self.config.api) # FIXME: move duplicate supression code to the object validation # functions to take a harder line on supression? if address != "" and not str(self.config._settings.allow_duplicate_macs).lower() in [ "1", "y", "yes"]: matched = self.config.api.find_items("system", {"mac_address" : address}) for x in matched: if x.name != self.name: raise CX("MAC address duplicated: %s" % address) intf = self.__get_interface(interface) if address == "" or utils.is_mac(address): intf["mac_address"] = address.strip() return True raise CX(_("invalid format for MAC address (%s)" % address))
def get_instance(): oret = None _nativemap["semaphore"].acquire() try: if "instance" in _nativemap: oret = _nativemap["instance"] else: if utils.is_windows(): oret = Windows() elif utils.is_linux(): oret = Linux() elif utils.is_mac(): oret = Mac() oret.load_library() _nativemap["instance"] = oret finally: _nativemap["semaphore"].release() return oret
def run(self): utils.info("BEGIN " + self.get_name()) #PREPARE CONF self._conf["pathsrc"]=".." + os.sep + self._name + os.sep + "src" self._conf["pathdst"]=self.get_path_tmp() + os.sep + self._name osn=None if utils.is_windows(): osn="windows" elif utils.is_linux(): osn="linux" elif utils.is_mac(): osn="mac" if osn is not None: appcnf=self.get_os_config(osn) if appcnf is not None: self._conf[osn]=appcnf if self._b32bit and osn in self._conf: if "linker_flags" not in self._conf[osn]: self._conf[osn]["linker_flags"]="-m32" else: self._conf[osn]["linker_flags"]="-m32 " + self._conf[osn]["linker_flags"] if "cpp_compiler_flags" not in self._conf[osn]: self._conf[osn]["cpp_compiler_flags"]="-m32" else: self._conf[osn]["cpp_compiler_flags"]="-m32 " + self._conf[osn]["cpp_compiler_flags"] #START COMPILE CONF utils.make_tmppath(self.get_path_tmp()) utils.remove_from_native(self.get_path_native(), self._conf) confos=utils.compile_lib(self._conf) if confos is not None: self.before_copy_to_native(osn) utils.copy_to_native(self.get_path_native(),self._conf) utils.info("END " + self.get_name())
def get(self, key): try: self._semaphore.acquire() try: if self._lang_current is None: applng = None try: l = locale.getdefaultlocale() if l is None or l[0] is None: if utils.is_mac(): p = subprocess.Popen( ['defaults', 'read', '-g', 'AppleLocale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) sout, serr = p.communicate() if sout is not None: applng = sout.replace("\n", "").replace( " ", "_")[:10] else: applng = l[0] except: None self._set_locale(applng) finally: self._semaphore.release() if key in self._data_current: return self._data_current[key] elif key in self._data_default: return self._data_default[key] else: return "RES_MISSING#" + key except: return "RES_ERROR#" + key
def _load_lib_obj(name): retlib = None if utils.is_windows(): if not utils.path_exists(".srcmode"): retlib = ctypes.CDLL("native\\" + name) else: retlib = ctypes.CDLL("..\\make\\native\\" + name) if retlib is None: raise Exception("Missing library " + name + ".") elif utils.is_linux(): if not utils.path_exists(".srcmode"): retlib = ctypes.CDLL("native/" + name, ctypes.RTLD_GLOBAL) else: retlib = ctypes.CDLL("../make/native/" + name, ctypes.RTLD_GLOBAL) if retlib is None: raise Exception("Missing library " + name + ".") elif utils.is_mac(): if not utils.path_exists(".srcmode"): retlib = ctypes.CDLL("native/" + name, ctypes.RTLD_GLOBAL) else: retlib = ctypes.CDLL("../make/native/" + name, ctypes.RTLD_GLOBAL) if retlib is None: raise Exception("Missing library " + name + ".") return retlib
def set_name(self, name): """ Set the name. If the name is a MAC or IP, and the first MAC and/or IP is not defined, go ahead and fill that value in. """ if self.name not in ["", None] and self.parent not in ["", None] and self.name == self.parent: raise CX(_("self parentage is weird")) self.validate_name(name) # Stuff here defaults to eth0. Yes, it's ugly and hardcoded, but so was # the default interface behaviour that's now removed. ;) # --Jasper Capel if utils.is_mac(name): intf = self.__get_interface("eth0") if intf["mac_address"] == "": intf["mac_address"] = name elif utils.is_ip(name): intf = self.__get_interface("eth0") if intf["ip_address"] == "": intf["ip_address"] = name self.name = name return True
def set_mac_address(self,address,interface): intf = self.__get_interface(interface) if address == "" or utils.is_mac(address): intf["mac_address"] = address.strip() return True raise CX(_("invalid format for MAC address (%s)" % address))
def is_mac(): return utils.is_mac()