def screenshot_by_name(name, fname='temp.png'): if utility.is_windows(): toplist, winlist = [], [] def enum_cb(hwnd, results): winlist.append((hwnd, win32gui.GetWindowText(hwnd))) win32gui.EnumWindows(enum_cb, toplist) for _, title in winlist: if title != '': print(title) proc = [(hwnd, title) for hwnd, title in winlist if name in title.lower()] if len(proc) > 0: # just grab the hwnd for first window matching the name proc = proc[0] hwnd = proc[0] win32gui.SetForegroundWindow(hwnd) bbox = win32gui.GetWindowRect(hwnd) print(bbox) img = ImageGrab.grab(bbox) img.save(fname) return img else: raise Exception('No window with that title.') else: raise Exception('screenshot_by_name only available on windows.')
def _load_bin_info(self, xmlroot): """ Method: _load_bin_info Description: 加载其他可以直接运行的可执行程序的信息 Parameter: xmlroot: xml根节点 Return: Others: """ # 配置文件中,区分了win和linux # 其中windows下,没有lib_path参数 #if platform.system().lower() == "windows": if utility.is_windows(): xpath = "bins/bins/win" lib_path = "" else: xpath = "bins/bins/linux" lib_path = None for app_ele in xmlroot.iterfind(xpath): if lib_path is None: lib_path = app_ele.get("lib_path") bin = BinInfo(app_ele.get("program") , app_ele.get("arg") , app_ele.get("work_dir") , lib_path) self._bins.append(bin)
def prepare_qt(env, **args): """ prepare_qt() perform the environment of qt building. **args contain: console = True/False, whether build a console application or gui application. moc_debug = True/False, whether to show verbose info of scons_qt or not. """ qtdir = os.environ.get('QTDIR', '') debug = args.get('moc_debug', 0) console = args.get('console', 0) try: if utility.is_windows(): if qtdir == '': qtdir = r'C:/Qt/Qt5.12.7/5.12.7/mingw73_32' prepare_qt_win(env, qtdir, moc_debug=debug, console=console) else: if qtdir == '': qtdir = r'/usr/local/Qt/Qt5.12.7/5.12.7/gcc_32' prepare_qt_linux(env, qtdir, moc_debug=debug, console=console) # qrc scanner qrcscan = Scanner(name='qrcfile', function=qrc_scan, argument=None, skeys=['.qrc']) env.Append(SCANNERS=qrcscan) except Exception as e: print('prepare_qt() failed! No qt config performed!') print(' Qt dir configs as:', qtdir) traceback.print_exc()
def get_tools(): """get_tools() will detemine which compiler would use. """ keys = ARGUMENTS.keys() msvc_ver = ARGUMENTS.get('msvc', '') if utility.is_windows(): if msvc_ver and 'rtos' in keys: print('Rtos cannot build with msvc compiler!') Exit(1) if not msvc_ver: return (['mingw'], msvc_ver) return (['default'], msvc_ver)
def press_key(key, t=0.1): if utility.is_osx(): if key == '<return>': cmd = """ osascript -e 'tell application "System Events" to keystroke return' """ else: cmd = """ osascript -e 'tell application "System Events" to keystroke "{}"' """.format(key) os.system(cmd) elif utility.is_windows(): for c in winutil.process_key_windows(key): winutil.key_event(c) else: raise Exception( 'Keyboard presses not supported on operating systems other than Windows and OS X.' )
def __check_acp_sn(self): # 校验SN是否合法,避免软件被复制到其他设备上后可以运行 # TODO, 后续开发安装盘的时候,再去掉下面的语句 return 0 if utility.is_windows(): return 0 # windows暂时不校验 inter_nic = self._device_info.get_device_internal_NIC() try: mac = utility.get_hw_address(inter_nic) except: tracelog.exception("get hardware address of %s failed." % inter_nic) return -1 m = md5.new() m.update("acp software") m.update(mac) actual_sn = m.hexdigest() # 读取文件中的sn sn_file_path = os.path.join(self.get_app_top_path(), "data/sn/sn.dat") try: sn_file = open(sn_file_path, "r") expect_sn = sn_file.read() sn_file.close() except: tracelog.exception("read %s failed." % sn_file_path) return -1 if expect_sn != actual_sn: tracelog.error("the serial number does not match!") return -1 return 0
def prepare_opts(env): """prepare_opts() will process command line options and add to env. Option 'rtos': Add option rtos=yes/no to command line to generate rtos binary or not. Option 'rtos_os': Add option rtos_os=rt-thread/freertos to command line to specify rtos type. This option only works while rtos=1. Option 'debug': Add option debug=yes/no to command line to build debug/release version. Option 'define': Add macros to build, same to gcc option -D, this option can be multi-set. Option 'incdir': Add additional include path of depends, this option can be multi-set. Option 'libdir': Add additional library path of depends, this option can be multi-set. """ custom_opt = os.path.join(env['ROOT_DIR'], env['OPT_FILE']) vars = Variables(custom_opt, ARGUMENTS) if utility.is_windows(): vc_versions = { '': '', 'VS2017': '14.1', 'VS2015': '14.0', 'VS2010': '10.0', 'VS2010Express': '10.0Exp', 'VS2005': '8.0', 'VS2005Express': '8.0Exp', } vars.Add( EnumVariable('msvc', ('Set use msvc version and specifies vs version.'), '', allowed_values=tuple(vc_versions.values()), ignorecase=2)) else: env['msvc'] = '' vars.Add(BoolVariable('rtos', 'Set to build rtos binaries', 0)) vars.Add(BoolVariable('debug', 'Set to build debug version', 0)) vars.Add( PathVariable('depends', 'Path to depends folder', os.path.join('$ROOT_DIR', 'depends'), PathVariable.PathIsDirCreate)) vars.Add( PathVariable('essentials', 'Path to essentials folder', os.path.join('$ROOT_DIR', 'essentials'), PathVariable.PathIsDirCreate)) vars.Add( PathVariable('build_path', 'Path to build folder', os.path.join('$ROOT_DIR', 'build'), PathVariable.PathIsDirCreate)) vars.Add( PathVariable('export_path', 'Path to export folder', os.path.join('$ROOT_DIR', 'export'), PathVariable.PathIsDirCreate)) vars.Update(env) cpp_defines = [] for key, value in ARGLIST: if key == 'define': cpp_defines.append(value) incdirs = [] for key, value in ARGLIST: if key == 'incdir': if os.path.isdir(value): incdirs.append(value) else: print("WARNING: incdir {0} does NOT exist!".format(value)) libdirs = [] for key, value in ARGLIST: if key == 'libdir': if os.path.isdir(value): libdirs.append(value) else: print("WARNING: libdir {0} does NOT exist!".format(value)) if env['debug']: cpp_defines.extend(['DBG', 'DEBUG']) else: cpp_defines.append('NDEBUG') if utility.is_windows(): cpp_defines.append('WIN32') if env['rtos']: cpp_defines.append('RTOS') os_types = { 'rt-thread': 'RTOS_RTT', 'freertos': 'RTOS_FREERTOS', } keys = os_types.keys() vars.Add( EnumVariable('rtos_os', 'Set rtos type.\n', keys[1], allowed_values=tuple(keys), ignorecase=2)) vars.Update(env) cpp_defines.append(os_types[env['rtos_os']]) print( "Default use rt-thread as rtos. Use 'rtos_os=' variable to change!" ) try: # Call rtos specified scripts. rtos_module = importlib.import_module(env['rtos_os']) rtos_module.rtos_config(env) except Exception as e: print('Fail to do rtos specified config in {0}.py'.format( env['rtos_os'])) print(e) sys.exit(1) env.AppendUnique(CPPDEFINES=cpp_defines) env.Replace(DEPENDS='$depends') env.Replace(ESSENTIALS='$essentials') env.Replace(EXPORT_PATH='$export_path') # if integrate solution project, use build/ as variant dir # else use build/project_name as variant dir build_conf = 'debug' if env['debug'] else 'release' if File('SolutionMagicFile', '#').exists(): env.Replace(BUILD_PATH=os.path.join('$build_path', build_conf)) else: solo_sln_name = os.path.basename(Dir('#').abspath) env.Replace( BUILD_PATH=os.path.join('$build_path', build_conf, solo_sln_name)) env.Append(CPPPATH=[ os.path.join(env['DEPENDS'], 'include'), os.path.join(env['ESSENTIALS'], 'include') ]) env.Append(CPPPATH=incdirs) env.Append(LIBPATH=[ os.path.join(env['DEPENDS'], 'lib'), os.path.join(env['ESSENTIALS'], 'lib') ]) env.Append(LIBPATH=libdirs) env.PrependENVPath('PATH', [ os.path.join(env['DEPENDS'], 'bin'), os.path.join(env['ESSENTIALS'], 'bin') ]) Help(vars.GenerateHelpText(env)) env['TEST'] = 'test' in COMMAND_LINE_TARGETS
""" #raise Exception("No implementation") return 0, "" def _win_unbind_virtual_ip(vip, mask, NIC): """ Function: _win_unbind_virtual_ip Description: Parameter: vip: ����ip mask: ���� NIC: �������� Return: Others: �ݲ�֧�� """ #raise Exception("No implementation") return 0, "" if utility.is_windows(): bind_virtual_ip = _win_bind_virtual_ip unbind_virtual_ip = _win_unbind_virtual_ip else: bind_virtual_ip = _linux_bind_virtual_ip unbind_virtual_ip = _linux_unbind_virtual_ip